102 lines
1.8 KiB
C++
102 lines
1.8 KiB
C++
/**
|
|
* @file route.cpp
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief Implements the class Route and Point
|
|
* @version 0.1
|
|
* @date 2022-01-31
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
|
|
#include "route.h"
|
|
|
|
void Route::addPointToRoute(Point point)
|
|
{
|
|
this->points.push_back(point);
|
|
}
|
|
|
|
void Route::clear()
|
|
{
|
|
this->points.clear();
|
|
this->currentPoint = 0;
|
|
this->started = false;
|
|
}
|
|
|
|
Point Route::startRoute()
|
|
{
|
|
if (this->points.empty())
|
|
{
|
|
this->started = false;
|
|
return Point();
|
|
}
|
|
|
|
this->it = this->points.begin();
|
|
this->currentPoint = 1;
|
|
this->started = true;
|
|
return *this->it;
|
|
}
|
|
|
|
Point Route::endRoute()
|
|
{
|
|
if (this->points.empty())
|
|
{
|
|
this->started = false;
|
|
return Point();
|
|
}
|
|
|
|
this->it = this->points.end();
|
|
// TODO: Understand why i have to decrement the iterator first to get realy the last element.
|
|
this->it--;
|
|
this->currentPoint = this->points.size();
|
|
this->started = true;
|
|
return *this->it;
|
|
}
|
|
|
|
Point Route::getNextPoint()
|
|
{
|
|
Point point;
|
|
if (!this->started)
|
|
{
|
|
return point;
|
|
}
|
|
|
|
if (this->it != --this->points.end())
|
|
{
|
|
this->it++;
|
|
this->currentPoint++;
|
|
return *this->it;
|
|
// } else if (this->it == this->points.end() && this->currentPoint != this->points.size()) {
|
|
// this->currentPoint++;
|
|
// return *this->it;
|
|
}
|
|
|
|
return point;
|
|
}
|
|
|
|
Point Route::getPreviousPoint()
|
|
{
|
|
Point point;
|
|
if (!this->started)
|
|
{
|
|
return point;
|
|
}
|
|
|
|
if (this->it != this->points.begin())
|
|
{
|
|
this->it--;
|
|
this->currentPoint--;
|
|
return *this->it;
|
|
}
|
|
|
|
return point;
|
|
}
|
|
|
|
RouteInfo Route::getRouteInfo()
|
|
{
|
|
RouteInfo info{0, 0};
|
|
info.totalPoints = this->points.size();
|
|
info.currentPoint = this->currentPoint;
|
|
return info;
|
|
}
|