pi2-view.cpp 2.03 KB
Newer Older
1
#include "pi2-view.h"
Martin Kröning's avatar
Martin Kröning committed
2 3
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-tags"
Martin Kröning's avatar
Martin Kröning committed
4
#include "MapApp.hpp"
Martin Kröning's avatar
Martin Kröning committed
5
#pragma clang diagnostic pop
Martin Kröning's avatar
Martin Kröning committed
6 7 8 9 10 11 12 13
#include <algorithm>
#include <chrono>
#include <gsl/pointers>
#include <gsl/span>
#include <gsl/string_span>
#include <valarray>
#include <vector>

14 15 16
gsl::owner<MapApp *> mapAppCreate(gsl::czstring<> windowTitle) {
  return new MapApp(windowTitle);
}
Martin Kröning's avatar
Martin Kröning committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

void mapAppDestroy(gsl::owner<MapApp *> mapApp) { delete mapApp; }

void mapAppAddJunction(MapApp *mapApp, const double x, const double y) {
  mapApp->addJunction(x, y);
}

void mapAppAddRoad(MapApp *mapApp, gsl::czstring<> laneThereName,
                   gsl::czstring<> laneBackName, const double coordinates[],
                   const size_t coordinateCount) {
  const gsl::span<const double> coordinatesSpan(coordinates, coordinateCount);
  std::vector<std::valarray<double>> coordinateVector(coordinateCount / 2);
  std::generate(coordinateVector.begin(), coordinateVector.end(),
                [&coordinatesSpan, i = 0]() mutable {
                  return std::valarray<double>(
                      {coordinatesSpan.at(i++), coordinatesSpan(i++)});
                });
  mapApp->addRoad(laneThereName, laneBackName, coordinateVector);
}

37
void mapAppAddOrReplaceBicycle(MapApp *mapApp, gsl::czstring<> vehicleName,
Martin Kröning's avatar
Martin Kröning committed
38
                               gsl::czstring<> roadName,
39 40 41 42 43 44 45 46 47 48 49
                               const double positionOnLane,
                               const double speed) {
  mapApp->addOrReplaceBicycle(vehicleName, roadName, positionOnLane, speed);
}

void mapAppAddOrReplaceCar(MapApp *mapApp, gsl::czstring<> vehicleName,
                           gsl::czstring<> roadName,
                           const double positionOnLane, const double speed,
                           const double remainingFuel) {
  mapApp->addOrReplaceCar(vehicleName, roadName, positionOnLane, speed,
                          remainingFuel);
Martin Kröning's avatar
Martin Kröning committed
50 51
}

52 53
void mapAppSetTimeLabel(MapApp *mapApp, int64_t minutes) {
  mapApp->setTimeLabel(std::chrono::minutes(minutes));
Martin Kröning's avatar
Martin Kröning committed
54
}