26 #ifndef SIMDRIVER_STOPHORIZON_H 27 #define SIMDRIVER_STOPHORIZON_H 38 #define EPS_DISTANCE 1e-9 52 double sStart = INFINITY;
53 double timeStartStanding = INFINITY;
54 double standingTime = INFINITY;
58 double _sActual = 0.0;
59 std::map<unsigned long, _StopPoint> _elements{};
79 if (_elements.size() > 0) _elements.clear();
91 bool addStopPoint(
unsigned long id,
double sStop,
double standingTime) {
93 if(_elements.find(
id) != _elements.end() && standingTime == 0) {
94 _elements[id].passed =
true;
98 if(_elements.find(
id) != _elements.end())
99 if (fabs(_elements[
id].s - sStop) < 0.5)
103 if(_sActual - sStop >= DELETE_AFTER_DISTANCE - EPS_DISTANCE)
107 _elements[id] = {sStop, _sActual, INFINITY, standingTime,
false};
121 bool stopped(
unsigned long id,
double actualTime) {
124 if(std::isinf(_elements.at(
id).timeStartStanding)) {
127 _elements.at(
id).timeStartStanding = actualTime;
145 void update(
double actualPosition,
double actualTime) {
147 _sActual = actualPosition;
150 for(
auto &ke : _elements) {
160 if(actualTime - e.timeStartStanding >= e.standingTime - EPS_TIME)
166 auto it = _elements.cbegin();
167 while(it != _elements.cend()) {
170 if(it->second.passed && _sActual - it->second.s >= DELETE_AFTER_DISTANCE - EPS_DISTANCE)
171 it = _elements.erase(it);
188 double dsMin = INFINITY;
189 double interval = INFINITY;
190 unsigned long id = (std::numeric_limits<unsigned long>::max)();
193 for(
auto &ke : _elements) {
199 double ds = e.s - _sActual;
202 if(e.passed || ds > dsMin)
208 interval = e.s - e.sStart;
223 #endif // SIMDRIVER_STOPHORIZON_H StopPoint getNextStop()
Definition: StopHorizon.h:185
Definition: StopHorizon.h:44
bool stopped(unsigned long id, double actualTime)
Definition: StopHorizon.h:121
Definition: DistanceTimeInterval.h:33
static constexpr const double DELETE_AFTER_DISTANCE
Distance after which the stop point is deleted from the list.
Definition: StopHorizon.h:48
void init(double s)
Definition: StopHorizon.h:76
Definition: StopHorizon.h:50
bool addStopPoint(unsigned long id, double sStop, double standingTime)
Definition: StopHorizon.h:91
void update(double actualPosition, double actualTime)
Definition: StopHorizon.h:145
a struct to store a stop point
Definition: StopHorizon.h:65