Bicycle.cpp 872 Bytes
Newer Older
Martin Kröning's avatar
Martin Kröning committed
1
#include "Bicycle.hpp"
2
#include "MapAppAPIWrapper.hpp"
Martin Kröning's avatar
Martin Kröning committed
3
4
5
6
7
8
9
10
#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) {}

11
void Bicycle::draw(MapAppAPIWrapper &mapApp, std::string_view laneName,
Martin Kröning's avatar
Martin Kröning committed
12
13
                   const double laneLength, const double speedLimit) const {
  const auto positionOnLane = getDistanceOnLane() / laneLength;
14
15
  mapApp.addOrReplaceBicycle(getName(), laneName, positionOnLane,
                             getSpeed(speedLimit));
Martin Kröning's avatar
Martin Kröning committed
16
17
18
19
20
21
22
}

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);
}