Bicycle.cpp 886 Bytes
Newer Older
Martin Kröning's avatar
Martin Kröning committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "Bicycle.hpp"
#include "MapAppABIWrapper.hpp"
#include <algorithm>
#include <cmath>
#include <utility>

Bicycle::Bicycle(std::string name, const double topSpeed,
                 const double timeOfStart, const double time)
    : Vehicle(std::move(name), topSpeed, timeOfStart, time) {}

void Bicycle::draw(MapAppABIWrapper &mapApp, const std::string &laneName,
                   const double laneLength, const double speedLimit) const {
  const auto positionOnLane = getDistanceOnLane() / laneLength;
  mapApp.addOrReplaceVehicle(getName(), laneName, positionOnLane,
                             getSpeed(speedLimit), 0, 0, 1, 0);
}

double Bicycle::getSpeed(const double speedLimit) const {
  auto const slowingSpeed =
      getTopSpeed() * std::pow(0.9, std::floor(getGesamtStrecke() / 20));
  return isParking() ? 0 : std::min(std::max(slowingSpeed, 12.0), speedLimit);
}