ad_physics
RangeOperation.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2018-2021 Intel Corporation
4 //
5 // SPDX-License-Identifier: MIT
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
8 
13 #pragma once
14 
19 
20 namespace ad {
21 namespace physics {
26 template <typename RangeType> bool isRangeValid(RangeType const &range)
27 {
28  return withinValidInputRange(range);
29 }
30 
35 template <typename RangeType> bool isRangeEmpty(RangeType const &range)
36 {
37  return isRangeValid(range) && (range.minimum == range.maximum);
38 }
39 
46 template <typename RangeType, typename RangeBaseType>
47 bool isWithinRange(RangeType const &range, RangeBaseType const &value)
48 {
49  return (range.minimum <= value) && (value <= range.maximum);
50 }
51 
58 template <typename RangeType> bool isRangeContained(RangeType const &left, RangeType const &right)
59 {
60  return (left.minimum <= right.minimum) && (right.maximum <= left.maximum);
61 }
62 
69 template <typename RangeType> bool doRangesOverlap(RangeType const &left, RangeType const &right)
70 {
71  return isWithinRange(left, right.minimum) || isWithinRange(left, right.maximum) || isWithinRange(right, left.minimum)
72  || isWithinRange(right, left.maximum) || isRangeContained(left, right) || isRangeContained(right, left);
73 }
74 
81 template <typename RangeType> bool areRangesDisjunct(RangeType const &left, RangeType const &right)
82 {
83  return !doRangesOverlaps(left, right);
84 }
85 
92 template <typename RangeType> bool doesRangePredate(RangeType const &left, RangeType const &right)
93 {
94  return left.maximum == right.minimum;
95 }
96 
103 template <typename RangeType> bool doesRangeSucceed(RangeType const &left, RangeType const &right)
104 {
105  return left.minimum == right.maximum;
106 }
107 
116 template <typename RangeType> bool extendRangeWith(RangeType &left, RangeType const &right)
117 {
118  if (doesRangePredate(left, right))
119  {
120  left.maximum = right.maximum;
121  return true;
122  }
123  else if (doesRangeSucceed(left, right))
124  {
125  left.minimum = right.minimum;
126  return true;
127  }
128  else
129  {
130  return false;
131  }
132 }
133 
140 template <typename RangeType> RangeType getUnionRange(RangeType const &left, RangeType const &right)
141 {
142  RangeType result;
143  result.minimum = std::min(left.minimum, right.minimum);
144  result.maximum = std::max(left.maximum, right.maximum);
145  return result;
146 }
147 
154 template <typename RangeType, typename RangeBaseType>
155 RangeType getUnionRange(RangeType const &left, RangeBaseType const &value)
156 {
157  RangeType result;
158  result.minimum = std::min(left.minimum, value);
159  result.maximum = std::max(left.maximum, value);
160  return result;
161 }
162 
169 template <typename RangeType> bool unionRangeWith(RangeType &left, RangeType const &right)
170 {
171  left = getUnionRange(left, right);
172  return isRangeValid(left);
173 }
174 
181 template <typename RangeType, typename RangeBaseType> bool unionRangeWith(RangeType &left, RangeBaseType const &value)
182 {
183  left = getUnionRange(left, value);
184  return isRangeValid(left);
185 }
186 
194 template <typename RangeType> RangeType getIntersectionRange(RangeType const &left, RangeType const &right)
195 {
196  RangeType result;
197  if (doRangesOverlap(left, right))
198  {
199  result.minimum = std::max(left.minimum, right.minimum);
200  result.maximum = std::min(left.maximum, right.maximum);
201  }
202  return result;
203 }
204 
212 template <typename RangeType> bool intersectRangeWith(RangeType &left, RangeType const &right)
213 {
214  left = getIntersectionRange(left, right);
215  return isRangeValid(left);
216 }
217 
218 } // namespace physics
219 } // namespace ad
220 
228 {
229  return left.minimum > right.maximum;
230 }
231 
239 {
240  return left.minimum >= right.maximum;
241 }
242 
250 {
251  return left.maximum < right.minimum;
252 }
253 
261 {
262  return left.maximum <= right.minimum;
263 }
264 
271 inline bool operator>(ad::physics::MetricRange const &left, ad::physics::MetricRange const &right)
272 {
273  return left.minimum > right.maximum;
274 }
275 
282 inline bool operator>=(ad::physics::MetricRange const &left, ad::physics::MetricRange const &right)
283 {
284  return left.minimum >= right.maximum;
285 }
286 
293 inline bool operator<(ad::physics::MetricRange const &left, ad::physics::MetricRange const &right)
294 {
295  return left.maximum < right.minimum;
296 }
297 
304 inline bool operator<=(ad::physics::MetricRange const &left, ad::physics::MetricRange const &right)
305 {
306  return left.maximum <= right.minimum;
307 }
308 
316 {
317  return left.minimum > right.maximum;
318 }
319 
327 {
328  return left.minimum >= right.maximum;
329 }
330 
338 {
339  return left.maximum < right.minimum;
340 }
341 
349 {
350  return left.maximum <= right.minimum;
351 }
352 
359 inline bool operator>(ad::physics::SpeedRange const &left, ad::physics::SpeedRange const &right)
360 {
361  return left.minimum > right.maximum;
362 }
363 
370 inline bool operator>=(ad::physics::SpeedRange const &left, ad::physics::SpeedRange const &right)
371 {
372  return left.minimum >= right.maximum;
373 }
374 
381 inline bool operator<(ad::physics::SpeedRange const &left, ad::physics::SpeedRange const &right)
382 {
383  return left.maximum < right.minimum;
384 }
385 
392 inline bool operator<=(ad::physics::SpeedRange const &left, ad::physics::SpeedRange const &right)
393 {
394  return left.maximum <= right.minimum;
395 }
ad
namespace ad
Definition: Acceleration.hpp:30
ad::physics::isWithinRange
bool isWithinRange(RangeType const &range, RangeBaseType const &value)
Checks if value of RangeBaseType is within range.
Definition: RangeOperation.hpp:47
ad::physics::SpeedRange::maximum
::ad::physics::Speed maximum
Definition: SpeedRange.hpp:121
ad::physics::ParametricRange::maximum
::ad::physics::ParametricValue maximum
Definition: ParametricRange.hpp:121
ParametricRangeValidInputRange.hpp
ad::physics::doRangesOverlap
bool doRangesOverlap(RangeType const &left, RangeType const &right)
Checks left range overlaps right one.
Definition: RangeOperation.hpp:69
ad::physics::unionRangeWith
bool unionRangeWith(RangeType &left, RangeType const &right)
Definition: RangeOperation.hpp:169
operator<
bool operator<(ad::physics::ParametricRange const &left, ad::physics::ParametricRange const &right)
Comparison operator for range based types.
Definition: RangeOperation.hpp:249
ad::physics::isRangeContained
bool isRangeContained(RangeType const &left, RangeType const &right)
Checks if right range is contained in left one.
Definition: RangeOperation.hpp:58
ad::physics::getUnionRange
RangeType getUnionRange(RangeType const &left, RangeType const &right)
Calculate union of left and right range.
Definition: RangeOperation.hpp:140
ad::physics::SpeedRange::minimum
::ad::physics::Speed minimum
Definition: SpeedRange.hpp:116
operator>
bool operator>(ad::physics::ParametricRange const &left, ad::physics::ParametricRange const &right)
Comparison operator for range based types.
Definition: RangeOperation.hpp:227
ad::physics::areRangesDisjunct
bool areRangesDisjunct(RangeType const &left, RangeType const &right)
Checks left range is disjunct from right one.
Definition: RangeOperation.hpp:81
operator<=
bool operator<=(ad::physics::ParametricRange const &left, ad::physics::ParametricRange const &right)
Comparison operator for range based types.
Definition: RangeOperation.hpp:260
ad::physics::extendRangeWith
bool extendRangeWith(RangeType &left, RangeType const &right)
Extends left range with right one. Direction of extension depends of the relative position of ranges.
Definition: RangeOperation.hpp:116
ad::physics::doesRangeSucceed
bool doesRangeSucceed(RangeType const &left, RangeType const &right)
Checks if left range comes directly after right one.
Definition: RangeOperation.hpp:103
withinValidInputRange
bool withinValidInputRange(::ad::physics::Acceleration3DList const &input, bool const logErrors=true)
check if the given Acceleration3DList is within valid input range
Definition: Acceleration3DListValidInputRange.hpp:39
ad::physics::getIntersectionRange
RangeType getIntersectionRange(RangeType const &left, RangeType const &right)
Intersect this range with right one.
Definition: RangeOperation.hpp:194
ad::physics::SpeedRange
DataType SpeedRange.
Definition: SpeedRange.hpp:39
ad::physics::doesRangePredate
bool doesRangePredate(RangeType const &left, RangeType const &right)
Checks if left range comes directly before right one.
Definition: RangeOperation.hpp:92
ad::physics::intersectRangeWith
bool intersectRangeWith(RangeType &left, RangeType const &right)
Intersect left range with right one and store intersection in left.
Definition: RangeOperation.hpp:212
AccelerationRangeValidInputRange.hpp
operator>=
bool operator>=(ad::physics::ParametricRange const &left, ad::physics::ParametricRange const &right)
Comparison operator for range based types.
Definition: RangeOperation.hpp:238
ad::physics::MetricRange::minimum
::ad::physics::Distance minimum
Definition: MetricRange.hpp:116
ad::physics::isRangeValid
bool isRangeValid(RangeType const &range)
Definition: RangeOperation.hpp:26
ad::physics::ParametricRange::minimum
::ad::physics::ParametricValue minimum
Definition: ParametricRange.hpp:116
ad::physics::MetricRange
DataType MetricRange.
Definition: MetricRange.hpp:39
ad::physics::ParametricRange
DataType ParametricRange.
Definition: ParametricRange.hpp:39
MetricRangeValidInputRange.hpp
SpeedRangeValidInputRange.hpp
ad::physics::AccelerationRange::minimum
::ad::physics::Acceleration minimum
Definition: AccelerationRange.hpp:116
ad::physics::AccelerationRange
DataType AccelerationRange.
Definition: AccelerationRange.hpp:39
ad::physics::isRangeEmpty
bool isRangeEmpty(RangeType const &range)
Definition: RangeOperation.hpp:35
ad::physics::MetricRange::maximum
::ad::physics::Distance maximum
Definition: MetricRange.hpp:121
ad::physics::AccelerationRange::maximum
::ad::physics::Acceleration maximum
Definition: AccelerationRange.hpp:121