ad_map_access
ENUCoordinate.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_ENUCOORDINATE_THROWS_EXCEPTION 1
46 
47 #if SAFE_DATATYPES_EXPLICIT_CONVERSION
48 
51 #define _AD_MAP_POINT_ENUCOORDINATE_EXPLICIT_CONVERSION_ explicit
52 #else
53 
56 #define _AD_MAP_POINT_ENUCOORDINATE_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  : mENUCoordinate(std::numeric_limits<double>::quiet_NaN())
92  {
93  }
94 
101  : mENUCoordinate(iENUCoordinate)
102  {
103  }
104 
108  ENUCoordinate(const ENUCoordinate &other) = default;
109 
113  ENUCoordinate(ENUCoordinate &&other) = default;
114 
122  ENUCoordinate &operator=(const ENUCoordinate &other) = default;
123 
131  ENUCoordinate &operator=(ENUCoordinate &&other) = default;
132 
140  bool operator==(const ENUCoordinate &other) const
141  {
142  ensureValid();
143  other.ensureValid();
144  return std::fabs(mENUCoordinate - other.mENUCoordinate) < cPrecisionValue;
145  }
146 
154  bool operator!=(const ENUCoordinate &other) const
155  {
156  return !operator==(other);
157  }
158 
168  bool operator>(const ENUCoordinate &other) const
169  {
170  ensureValid();
171  other.ensureValid();
172  return (mENUCoordinate > other.mENUCoordinate) && operator!=(other);
173  }
174 
184  bool operator<(const ENUCoordinate &other) const
185  {
186  ensureValid();
187  other.ensureValid();
188  return (mENUCoordinate < other.mENUCoordinate) && operator!=(other);
189  }
190 
200  bool operator>=(const ENUCoordinate &other) const
201  {
202  ensureValid();
203  other.ensureValid();
204  return ((mENUCoordinate > other.mENUCoordinate) || operator==(other));
205  }
206 
216  bool operator<=(const ENUCoordinate &other) const
217  {
218  ensureValid();
219  other.ensureValid();
220  return ((mENUCoordinate < other.mENUCoordinate) || operator==(other));
221  }
222 
234  {
235  ensureValid();
236  other.ensureValid();
237  ENUCoordinate const result(mENUCoordinate + other.mENUCoordinate);
238  result.ensureValid();
239  return result;
240  }
241 
253  {
254  ensureValid();
255  other.ensureValid();
256  mENUCoordinate += other.mENUCoordinate;
257  ensureValid();
258  return *this;
259  }
260 
272  {
273  ensureValid();
274  other.ensureValid();
275  ENUCoordinate const result(mENUCoordinate - other.mENUCoordinate);
276  result.ensureValid();
277  return result;
278  }
279 
291  {
292  ensureValid();
293  other.ensureValid();
294  mENUCoordinate -= other.mENUCoordinate;
295  ensureValid();
296  return *this;
297  }
298 
309  ENUCoordinate operator*(const double &scalar) const
310  {
311  ensureValid();
312  ENUCoordinate const result(mENUCoordinate * scalar);
313  result.ensureValid();
314  return result;
315  }
316 
327  ENUCoordinate operator/(const double &scalar) const
328  {
329  ENUCoordinate const scalarENUCoordinate(scalar);
330  ENUCoordinate const result(operator/(scalarENUCoordinate));
331  result.ensureValid();
332  return result;
333  }
334 
346  double operator/(const ENUCoordinate &other) const
347  {
348  ensureValid();
349  other.ensureValidNonZero();
350  double const result = mENUCoordinate / other.mENUCoordinate;
351  return result;
352  }
353 
363  {
364  ensureValid();
365  ENUCoordinate const result(-mENUCoordinate);
366  result.ensureValid(); // LCOV_EXCL_BR_LINE Some types do not throw an exception
367  return result;
368  }
369 
377  {
378  return mENUCoordinate;
379  }
380 
388  bool isValid() const
389  {
390  auto const valueClass = std::fpclassify(mENUCoordinate);
391  return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mENUCoordinate)
392  && (mENUCoordinate <= cMaxValue);
393  }
394 
401  void ensureValid() const
402  {
403  if (!isValid())
404  {
405  spdlog::info("ensureValid(::ad::map::point::ENUCoordinate)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE
406 #if (AD_MAP_POINT_ENUCOORDINATE_THROWS_EXCEPTION == 1)
407  throw std::out_of_range("ENUCoordinate value out of range"); // LCOV_EXCL_BR_LINE
408 #endif
409  }
410  }
411 
418  void ensureValidNonZero() const
419  {
420  ensureValid();
421  if (operator==(ENUCoordinate(0.))) // LCOV_EXCL_BR_LINE
422  {
423  spdlog::info("ensureValid(::ad::map::point::ENUCoordinate)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE
424 #if (AD_MAP_POINT_ENUCOORDINATE_THROWS_EXCEPTION == 1)
425  throw std::out_of_range("ENUCoordinate value is zero"); // LCOV_EXCL_BR_LINE
426 #endif
427  }
428  }
429 
434  {
435  return ENUCoordinate(cMinValue);
436  }
437 
442  {
443  return ENUCoordinate(cMaxValue);
444  }
445 
450  {
452  }
453 
454 private:
458  double mENUCoordinate;
459 };
460 
461 } // namespace point
462 } // namespace map
463 } // namespace ad
475 inline ::ad::map::point::ENUCoordinate operator*(const double &other, ::ad::map::point::ENUCoordinate const &value)
476 {
477  return value.operator*(other);
478 }
479 
483 namespace std {
484 
488 inline ::ad::map::point::ENUCoordinate fabs(const ::ad::map::point::ENUCoordinate other)
489 {
490  ::ad::map::point::ENUCoordinate const result(std::fabs(static_cast<double>(other)));
491  return result;
492 }
493 
502 template <> class numeric_limits<::ad::map::point::ENUCoordinate> : public numeric_limits<double>
503 {
504 public:
508  static inline ::ad::map::point::ENUCoordinate lowest()
509  {
510  return ::ad::map::point::ENUCoordinate::getMin();
511  }
515  static inline ::ad::map::point::ENUCoordinate max()
516  {
517  return ::ad::map::point::ENUCoordinate::getMax();
518  }
519 
523  static inline ::ad::map::point::ENUCoordinate epsilon()
524  {
525  return ::ad::map::point::ENUCoordinate::getPrecision();
526  }
527 };
528 
529 } // namespace std
530 
534 #ifndef GEN_GUARD_AD_MAP_POINT_ENUCOORDINATE
535 #define GEN_GUARD_AD_MAP_POINT_ENUCOORDINATE
536 
539 namespace ad {
543 namespace map {
549 namespace point {
550 
560 inline std::ostream &operator<<(std::ostream &os, ENUCoordinate 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::ENUCoordinate const &value)
574 {
575  return to_string(static_cast<double>(value));
576 }
577 } // namespace std
578 #endif // GEN_GUARD_AD_MAP_POINT_ENUCOORDINATE
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
ad::map::point::ENUCoordinate::getMax
static ENUCoordinate getMax()
get maximum valid ENUCoordinate (i.e. cMaxValue)
Definition: ENUCoordinate.hpp:441
ad::map::point::ENUCoordinate::operator<=
bool operator<=(const ENUCoordinate &other) const
standard comparison operator
Definition: ENUCoordinate.hpp:216
ad::map::point::operator<<
std::ostream & operator<<(std::ostream &os, Altitude const &_value)
standard ostream operator
Definition: Altitude.hpp:562
ad::map::point::ENUCoordinate::operator==
bool operator==(const ENUCoordinate &other) const
standard comparison operator
Definition: ENUCoordinate.hpp:140
ad::map::point::ENUCoordinate::operator/
ENUCoordinate operator/(const double &scalar) const
standard arithmetic operator
Definition: ENUCoordinate.hpp:327
ad::map::point::ENUCoordinate::operator-=
ENUCoordinate operator-=(const ENUCoordinate &other)
standard arithmetic operator
Definition: ENUCoordinate.hpp:290
ad::map::point::ENUCoordinate::operator-
ENUCoordinate operator-() const
standard arithmetic operator
Definition: ENUCoordinate.hpp:362
ad::map::point::ENUCoordinate::operator-
ENUCoordinate operator-(const ENUCoordinate &other) const
standard arithmetic operator
Definition: ENUCoordinate.hpp:271
ad::map::point::ENUCoordinate::cMaxValue
static const double cMaxValue
constant defining the maximum valid ENUCoordinate value (used in isValid())
Definition: ENUCoordinate.hpp:76
ad::map::point::ENUCoordinate::getPrecision
static ENUCoordinate getPrecision()
get assumed accuracy of ENUCoordinate (i.e. cPrecisionValue)
Definition: ENUCoordinate.hpp:449
ad::map::point::ENUCoordinate::operator+
ENUCoordinate operator+(const ENUCoordinate &other) const
standard arithmetic operator
Definition: ENUCoordinate.hpp:233
ad::map::point::ENUCoordinate::ensureValidNonZero
void ensureValidNonZero() const
ensure that the ENUCoordinate is valid and non zero
Definition: ENUCoordinate.hpp:418
ad::map::point::ENUCoordinate::cMinValue
static const double cMinValue
constant defining the minimum valid ENUCoordinate value (used in isValid())
Definition: ENUCoordinate.hpp:71
_AD_MAP_POINT_ENUCOORDINATE_EXPLICIT_CONVERSION_
#define _AD_MAP_POINT_ENUCOORDINATE_EXPLICIT_CONVERSION_
Enable/Disable explicit conversion. Currently set to "implicit conversion allowed".
Definition: ENUCoordinate.hpp:56
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
ad::map::point::ENUCoordinate::operator/
double operator/(const ENUCoordinate &other) const
standard arithmetic operator
Definition: ENUCoordinate.hpp:346
std::numeric_limits<::ad::map::point::ENUCoordinate >::max
static inline ::ad::map::point::ENUCoordinate max()
Definition: ENUCoordinate.hpp:515
operator*
inline ::ad::map::point::ENUCoordinate operator*(const double &other, ::ad::map::point::ENUCoordinate const &value)
standard arithmetic operator
Definition: ENUCoordinate.hpp:475
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::ENUCoordinate::ENUCoordinate
ENUCoordinate()
default constructor
Definition: ENUCoordinate.hpp:90
ad::map::point::ENUCoordinate::operator=
ENUCoordinate & operator=(const ENUCoordinate &other)=default
standard assignment operator
ad::map::point::ENUCoordinate::ENUCoordinate
_AD_MAP_POINT_ENUCOORDINATE_EXPLICIT_CONVERSION_ ENUCoordinate(double const iENUCoordinate)
standard constructor
Definition: ENUCoordinate.hpp:100
std::numeric_limits<::ad::map::point::ENUCoordinate >::lowest
static inline ::ad::map::point::ENUCoordinate lowest()
Definition: ENUCoordinate.hpp:508
ad::map::point::ENUCoordinate::ensureValid
void ensureValid() const
ensure that the ENUCoordinate is valid
Definition: ENUCoordinate.hpp:401
ad::map::point::ENUCoordinate::operator!=
bool operator!=(const ENUCoordinate &other) const
standard comparison operator
Definition: ENUCoordinate.hpp:154
ad::map::point::ENUCoordinate::cPrecisionValue
static const double cPrecisionValue
constant defining the assumed ENUCoordinate value accuracy (used in comparison operator==(),...
Definition: ENUCoordinate.hpp:82
ad::map::point::ENUCoordinate::getMin
static ENUCoordinate getMin()
get minimum valid ENUCoordinate (i.e. cMinValue)
Definition: ENUCoordinate.hpp:433
ad::map::point::ENUCoordinate::operator<
bool operator<(const ENUCoordinate &other) const
standard comparison operator
Definition: ENUCoordinate.hpp:184
ad::map::point::ENUCoordinate::isValid
bool isValid() const
Definition: ENUCoordinate.hpp:388
std::numeric_limits<::ad::map::point::ENUCoordinate >::epsilon
static inline ::ad::map::point::ENUCoordinate epsilon()
Definition: ENUCoordinate.hpp:523
ad::map::point::ENUCoordinate::operator>
bool operator>(const ENUCoordinate &other) const
standard comparison operator
Definition: ENUCoordinate.hpp:168
ad::map::point::ENUCoordinate::operator*
ENUCoordinate operator*(const double &scalar) const
standard arithmetic operator
Definition: ENUCoordinate.hpp:309
ad::map::point::ENUCoordinate::operator+=
ENUCoordinate & operator+=(const ENUCoordinate &other)
standard arithmetic operator
Definition: ENUCoordinate.hpp:252
ad::map::point::ENUCoordinate::operator>=
bool operator>=(const ENUCoordinate &other) const
standard comparison operator
Definition: ENUCoordinate.hpp:200
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::ENUCoordinate
DataType ENUCoordinate.
Definition: ENUCoordinate.hpp:65