SimDriver  0.1
DistanceTimeInterval.h
1 // Copyright (c) 2020 Institute for Automotive Engineering (ika), RWTH Aachen University. All rights reserved.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 //
21 // Created by Jens Klimke on 07.04.20.
22 // Contributors:
23 //
24 
25 
26 #ifndef SIMDRIVER_DISTANCETIMEINTERVAL_H
27 #define SIMDRIVER_DISTANCETIMEINTERVAL_H
28 
29 #include "model_collection.h"
30 #include <cmath>
31 
32 
33 namespace agent_model {
34 
36 
37  protected:
38 
39  double _actualPosition = 0.0;
40  double _actualTime = 0.0;
41 
42  double _startTime = INFINITY;
43  double _endTime = INFINITY;
44 
45  double _startPosition = INFINITY;
46  double _endPosition = INFINITY;
47 
48  double _scale = 1.0;
49  double _delta = 1.0;
50 
51 
52  public:
53 
54 
59  void setDelta(double delta) {
60 
61  _delta = delta;
62 
63  }
64 
65 
70  bool isSet() const {
71 
72  return !std::isinf(_startTime) || !std::isinf(_startPosition);
73 
74  }
75 
76 
81  void setScale(double scale) {
82 
83  _scale = scale;
84 
85  }
86 
87 
92  double getScale() const {
93 
94  return _scale;
95 
96  }
97 
98 
104  void update(double position, double time) {
105 
106  _actualPosition = position;
107  _actualTime = time;
108 
109  }
110 
111 
116  void setTimeInterval(double timeInterval) {
117 
118  if(std::isinf(timeInterval)) {
119 
120  // set start and end time to inf
121  _startTime = INFINITY;
122  _endTime = INFINITY;
123 
124  return;
125 
126  }
127 
128  _startTime = _actualTime;
129  _endTime = _actualTime + timeInterval;
130 
131  }
132 
133 
138  void setEndPosition(double endPosition) {
139 
140  if(std::isinf(endPosition)) {
141 
142  // set start and end time to inf
143  _startPosition = INFINITY;
144  _endPosition = INFINITY;
145 
146  return;
147 
148  }
149 
150  _startPosition = _actualPosition;
151  _endPosition = endPosition;
152 
153  }
154 
155 
160  void reset() {
161 
162  setTimeInterval(INFINITY);
163  setEndPosition(INFINITY);
164 
165  }
166 
167 
172  double getFactor() const {
173 
174  // if not set, return 0
175  if(!isSet())
176  return 0.0;
177 
178  // calculate factors
179 // double ft = std::isinf(_startTime) ? 0.0 : agent_model::scale(_actualTime, _endTime, _startTime, 0.5);
180 // double fs = std::isinf(_startPosition) ? 0.0 : agent_model::scale(_actualPosition, _endPosition, _startPosition, 0.5);
181 
182  double ft = std::isinf(_startTime) ? 0.0 : agent_model::scale(_actualTime, _endTime, _startTime, _delta);
183  double fs = std::isinf(_startPosition) ? 0.0 : agent_model::scale(_actualPosition, _endPosition, _startPosition, _delta);
184 
185  // maximum
186  return (std::max)(ft, fs);
187 
188  }
189 
190 
195  double getScaledFactor() const {
196 
197  return getFactor() * _scale;
198 
199  }
200 
201  };
202 
203 } // namespace
204 
205 #endif //SIMDRIVER_DISTANCETIMEINTERVAL_H
Definition: DistanceTimeInterval.h:35
void setScale(double scale)
Definition: DistanceTimeInterval.h:81
void update(double position, double time)
Definition: DistanceTimeInterval.h:104
double _actualPosition
The actual position.
Definition: DistanceTimeInterval.h:39
double _startTime
The start time.
Definition: DistanceTimeInterval.h:42
void setDelta(double delta)
Definition: DistanceTimeInterval.h:59
void setTimeInterval(double timeInterval)
Definition: DistanceTimeInterval.h:116
double getFactor() const
Definition: DistanceTimeInterval.h:172
double _scale
The factor to be scaled.
Definition: DistanceTimeInterval.h:48
double _endPosition
The end position.
Definition: DistanceTimeInterval.h:46
void setEndPosition(double endPosition)
Definition: DistanceTimeInterval.h:138
double _startPosition
The start position.
Definition: DistanceTimeInterval.h:45
Definition: DistanceTimeInterval.h:33
double _endTime
The end time.
Definition: DistanceTimeInterval.h:43
double getScale() const
Definition: DistanceTimeInterval.h:92
double getScaledFactor() const
Definition: DistanceTimeInterval.h:195
double _delta
The power to calculate the scale.
Definition: DistanceTimeInterval.h:49
bool isSet() const
Definition: DistanceTimeInterval.h:70
void reset()
Definition: DistanceTimeInterval.h:160
double _actualTime
The actual time.
Definition: DistanceTimeInterval.h:40