ad_map_access
ENUHeading.hpp
Go to the documentation of this file.
1 /*
2  * ----------------- BEGIN LICENSE BLOCK ---------------------------------
3  *
4  * Copyright (C) 2018-2020 Intel Corporation
5  *
6  * SPDX-License-Identifier: MIT
7  *
8  * ----------------- END LICENSE BLOCK -----------------------------------
9  */
10 
18 #pragma once
19 
20 #include <cmath>
21 #include <iostream>
22 #include <limits>
23 #include <sstream>
24 #include <stdexcept>
25 #include "spdlog/fmt/ostr.h"
26 #include "spdlog/spdlog.h"
30 namespace ad {
34 namespace map {
40 namespace point {
41 
45 #define AD_MAP_POINT_ENUHEADING_THROWS_EXCEPTION 1
46 
47 #if SAFE_DATATYPES_EXPLICIT_CONVERSION
48 
51 #define _AD_MAP_POINT_ENUHEADING_EXPLICIT_CONVERSION_ explicit
52 #else
53 
56 #define _AD_MAP_POINT_ENUHEADING_EXPLICIT_CONVERSION_
57 #endif
58 
66 {
67 public:
71  static const double cMinValue;
72 
76  static const double cMaxValue;
77 
82  static const double cPrecisionValue;
83 
91  : mENUHeading(std::numeric_limits<double>::quiet_NaN())
92  {
93  }
94 
101  : mENUHeading(iENUHeading)
102  {
103  }
104 
108  ENUHeading(const ENUHeading &other) = default;
109 
113  ENUHeading(ENUHeading &&other) = default;
114 
122  ENUHeading &operator=(const ENUHeading &other) = default;
123 
131  ENUHeading &operator=(ENUHeading &&other) = default;
132 
140  bool operator==(const ENUHeading &other) const
141  {
142  ensureValid();
143  other.ensureValid();
144  return std::fabs(mENUHeading - other.mENUHeading) < cPrecisionValue;
145  }
146 
154  bool operator!=(const ENUHeading &other) const
155  {
156  return !operator==(other);
157  }
158 
168  bool operator>(const ENUHeading &other) const
169  {
170  ensureValid();
171  other.ensureValid();
172  return (mENUHeading > other.mENUHeading) && operator!=(other);
173  }
174 
184  bool operator<(const ENUHeading &other) const
185  {
186  ensureValid();
187  other.ensureValid();
188  return (mENUHeading < other.mENUHeading) && operator!=(other);
189  }
190 
200  bool operator>=(const ENUHeading &other) const
201  {
202  ensureValid();
203  other.ensureValid();
204  return ((mENUHeading > other.mENUHeading) || operator==(other));
205  }
206 
216  bool operator<=(const ENUHeading &other) const
217  {
218  ensureValid();
219  other.ensureValid();
220  return ((mENUHeading < other.mENUHeading) || operator==(other));
221  }
222 
233  ENUHeading operator+(const ENUHeading &other) const
234  {
235  ensureValid();
236  other.ensureValid();
237  ENUHeading const result(mENUHeading + other.mENUHeading);
238  result.ensureValid();
239  return result;
240  }
241 
253  {
254  ensureValid();
255  other.ensureValid();
256  mENUHeading += other.mENUHeading;
257  ensureValid();
258  return *this;
259  }
260 
271  ENUHeading operator-(const ENUHeading &other) const
272  {
273  ensureValid();
274  other.ensureValid();
275  ENUHeading const result(mENUHeading - other.mENUHeading);
276  result.ensureValid();
277  return result;
278  }
279 
291  {
292  ensureValid();
293  other.ensureValid();
294  mENUHeading -= other.mENUHeading;
295  ensureValid();
296  return *this;
297  }
298 
309  ENUHeading operator*(const double &scalar) const
310  {
311  ensureValid();
312  ENUHeading const result(mENUHeading * scalar);
313  result.ensureValid();
314  return result;
315  }
316 
327  ENUHeading operator/(const double &scalar) const
328  {
329  ENUHeading const scalarENUHeading(scalar);
330  ENUHeading const result(operator/(scalarENUHeading));
331  result.ensureValid();
332  return result;
333  }
334 
346  double operator/(const ENUHeading &other) const
347  {
348  ensureValid();
349  other.ensureValidNonZero();
350  double const result = mENUHeading / other.mENUHeading;
351  return result;
352  }
353 
363  {
364  ensureValid();
365  ENUHeading const result(-mENUHeading);
366  result.ensureValid(); // LCOV_EXCL_BR_LINE Some types do not throw an exception
367  return result;
368  }
369 
377  {
378  return mENUHeading;
379  }
380 
388  bool isValid() const
389  {
390  auto const valueClass = std::fpclassify(mENUHeading);
391  return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mENUHeading)
392  && (mENUHeading <= cMaxValue);
393  }
394 
401  void ensureValid() const
402  {
403  if (!isValid())
404  {
405  spdlog::info("ensureValid(::ad::map::point::ENUHeading)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE
406 #if (AD_MAP_POINT_ENUHEADING_THROWS_EXCEPTION == 1)
407  throw std::out_of_range("ENUHeading value out of range"); // LCOV_EXCL_BR_LINE
408 #endif
409  }
410  }
411 
418  void ensureValidNonZero() const
419  {
420  ensureValid();
421  if (operator==(ENUHeading(0.))) // LCOV_EXCL_BR_LINE
422  {
423  spdlog::info("ensureValid(::ad::map::point::ENUHeading)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE
424 #if (AD_MAP_POINT_ENUHEADING_THROWS_EXCEPTION == 1)
425  throw std::out_of_range("ENUHeading value is zero"); // LCOV_EXCL_BR_LINE
426 #endif
427  }
428  }
429 
434  {
435  return ENUHeading(cMinValue);
436  }
437 
442  {
443  return ENUHeading(cMaxValue);
444  }
445 
450  {
451  return ENUHeading(cPrecisionValue);
452  }
453 
454 private:
458  double mENUHeading;
459 };
460 
461 } // namespace point
462 } // namespace map
463 } // namespace ad
475 inline ::ad::map::point::ENUHeading operator*(const double &other, ::ad::map::point::ENUHeading const &value)
476 {
477  return value.operator*(other);
478 }
479 
483 namespace std {
484 
488 inline ::ad::map::point::ENUHeading fabs(const ::ad::map::point::ENUHeading other)
489 {
490  ::ad::map::point::ENUHeading const result(std::fabs(static_cast<double>(other)));
491  return result;
492 }
493 
502 template <> class numeric_limits<::ad::map::point::ENUHeading> : public numeric_limits<double>
503 {
504 public:
508  static inline ::ad::map::point::ENUHeading lowest()
509  {
510  return ::ad::map::point::ENUHeading::getMin();
511  }
515  static inline ::ad::map::point::ENUHeading max()
516  {
517  return ::ad::map::point::ENUHeading::getMax();
518  }
519 
523  static inline ::ad::map::point::ENUHeading epsilon()
524  {
525  return ::ad::map::point::ENUHeading::getPrecision();
526  }
527 };
528 
529 } // namespace std
530 
534 #ifndef GEN_GUARD_AD_MAP_POINT_ENUHEADING
535 #define GEN_GUARD_AD_MAP_POINT_ENUHEADING
536 
539 namespace ad {
543 namespace map {
549 namespace point {
550 
560 inline std::ostream &operator<<(std::ostream &os, ENUHeading const &_value)
561 {
562  return os << double(_value);
563 }
564 
565 } // namespace point
566 } // namespace map
567 } // namespace ad
568 
569 namespace std {
573 inline std::string to_string(::ad::map::point::ENUHeading const &value)
574 {
575  return to_string(static_cast<double>(value));
576 }
577 } // namespace std
578 #endif // GEN_GUARD_AD_MAP_POINT_ENUHEADING
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
ad::map::point::ENUHeading::getMax
static ENUHeading getMax()
get maximum valid ENUHeading (i.e. cMaxValue)
Definition: ENUHeading.hpp:441
ad::map::point::ENUHeading::cMinValue
static const double cMinValue
constant defining the minimum valid ENUHeading value (used in isValid())
Definition: ENUHeading.hpp:71
ad::map::point::ENUHeading::getMin
static ENUHeading getMin()
get minimum valid ENUHeading (i.e. cMinValue)
Definition: ENUHeading.hpp:433
ad::map::point::operator<<
std::ostream & operator<<(std::ostream &os, Altitude const &_value)
standard ostream operator
Definition: Altitude.hpp:562
ad::map::point::ENUHeading::operator>
bool operator>(const ENUHeading &other) const
standard comparison operator
Definition: ENUHeading.hpp:168
operator*
inline ::ad::map::point::ENUHeading operator*(const double &other, ::ad::map::point::ENUHeading const &value)
standard arithmetic operator
Definition: ENUHeading.hpp:475
std::numeric_limits<::ad::map::point::ENUHeading >::epsilon
static inline ::ad::map::point::ENUHeading epsilon()
Definition: ENUHeading.hpp:523
ad::map::point::ENUHeading::operator/
double operator/(const ENUHeading &other) const
standard arithmetic operator
Definition: ENUHeading.hpp:346
ad::map::point::ENUHeading::operator+=
ENUHeading & operator+=(const ENUHeading &other)
standard arithmetic operator
Definition: ENUHeading.hpp:252
ad::map::point::ENUHeading::cMaxValue
static const double cMaxValue
constant defining the maximum valid ENUHeading value (used in isValid())
Definition: ENUHeading.hpp:76
std::fabs
inline ::ad::map::point::Longitude fabs(const ::ad::map::point::Longitude other)
overload of the std::fabs for Longitude
Definition: Longitude.hpp:488
std::to_string
std::string to_string(::ad::map::access::GeometryStoreItem const &value)
overload of the std::to_string for GeometryStoreItem
Definition: GeometryStoreItem.hpp:183
ad::map::point::ENUHeading::operator=
ENUHeading & operator=(const ENUHeading &other)=default
standard assignment operator
ad::map::point::ENUHeading
DataType ENUHeading.
Definition: ENUHeading.hpp:65
ad::map::point::ENUHeading::ENUHeading
ENUHeading()
default constructor
Definition: ENUHeading.hpp:90
ad::map::point::ENUHeading::operator<=
bool operator<=(const ENUHeading &other) const
standard comparison operator
Definition: ENUHeading.hpp:216
ad::map::point::ENUHeading::operator/
ENUHeading operator/(const double &scalar) const
standard arithmetic operator
Definition: ENUHeading.hpp:327
std::numeric_limits<::ad::map::point::ENUHeading >::lowest
static inline ::ad::map::point::ENUHeading lowest()
Definition: ENUHeading.hpp:508
ad::map::point::ENUHeading::operator-=
ENUHeading operator-=(const ENUHeading &other)
standard arithmetic operator
Definition: ENUHeading.hpp:290
ad::map::point::ENUHeading::operator*
ENUHeading operator*(const double &scalar) const
standard arithmetic operator
Definition: ENUHeading.hpp:309
ad::map::point::ENUHeading::isValid
bool isValid() const
Definition: ENUHeading.hpp:388
_AD_MAP_POINT_ENUHEADING_EXPLICIT_CONVERSION_
#define _AD_MAP_POINT_ENUHEADING_EXPLICIT_CONVERSION_
Enable/Disable explicit conversion. Currently set to "implicit conversion allowed".
Definition: ENUHeading.hpp:56
ad::map::point::ENUHeading::operator-
ENUHeading operator-(const ENUHeading &other) const
standard arithmetic operator
Definition: ENUHeading.hpp:271
ad::map::point::ENUHeading::cPrecisionValue
static const double cPrecisionValue
constant defining the assumed ENUHeading value accuracy (used in comparison operator==(),...
Definition: ENUHeading.hpp:82
std::numeric_limits<::ad::map::point::ENUHeading >::max
static inline ::ad::map::point::ENUHeading max()
Definition: ENUHeading.hpp:515
ad::map::point::ENUHeading::operator>=
bool operator>=(const ENUHeading &other) const
standard comparison operator
Definition: ENUHeading.hpp:200
ad::map::point::ENUHeading::operator==
bool operator==(const ENUHeading &other) const
standard comparison operator
Definition: ENUHeading.hpp:140
ad::map::point::ENUHeading::operator+
ENUHeading operator+(const ENUHeading &other) const
standard arithmetic operator
Definition: ENUHeading.hpp:233
ad::map::point::ENUHeading::ensureValidNonZero
void ensureValidNonZero() const
ensure that the ENUHeading is valid and non zero
Definition: ENUHeading.hpp:418
ad::map::point::ENUHeading::getPrecision
static ENUHeading getPrecision()
get assumed accuracy of ENUHeading (i.e. cPrecisionValue)
Definition: ENUHeading.hpp:449
ad::map::point::ENUHeading::ensureValid
void ensureValid() const
ensure that the ENUHeading is valid
Definition: ENUHeading.hpp:401
ad::map::point::ENUHeading::operator<
bool operator<(const ENUHeading &other) const
standard comparison operator
Definition: ENUHeading.hpp:184
ad::map::point::ENUHeading::ENUHeading
_AD_MAP_POINT_ENUHEADING_EXPLICIT_CONVERSION_ ENUHeading(double const iENUHeading)
standard constructor
Definition: ENUHeading.hpp:100
ad::map::point::ENUHeading::operator-
ENUHeading operator-() const
standard arithmetic operator
Definition: ENUHeading.hpp:362
std::fabs
inline ::ad::map::point::Altitude fabs(const ::ad::map::point::Altitude other)
overload of the std::fabs for Altitude
Definition: Altitude.hpp:490
ad::map::point::ENUHeading::operator!=
bool operator!=(const ENUHeading &other) const
standard comparison operator
Definition: ENUHeading.hpp:154