MIRA
Angle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
48 #include <type_traits>
49 
50 #include <error/Exceptions.h>
51 
52 #include <platform/Platform.h> // for MIRA_DEPRECATED
53 #include <math/Math.h>
54 
55 #include <serialization/Accessor.h>
56 
57 
58 #ifndef _MIRA_ANGLE_H_
59 #define _MIRA_ANGLE_H_
60 
61 namespace mira {
63 
65 namespace Private {
66 template <typename Param, typename Result>
67 inline Result deg2rad(Param value) {
68  return static_cast<Result>(value * pi_div_deg180<Result>());
69 }
70 template <typename Param, typename Result>
71 inline Result rad2deg(Param value) {
72  return static_cast<Result>(value * deg180_div_pi<Result>());
73 }
74 }
76 
78 template <typename T>
79 inline
80 typename std::enable_if<std::is_floating_point<T>::value, T>::type
81 deg2rad(T value) {
82  return Private::deg2rad<T, T>(value);
83 }
84 
86 template <typename T>
87 inline
88 typename std::enable_if<std::is_integral<T>::value, double>::type
89 deg2rad(T value) {
90  return Private::deg2rad<T, double>(value);
91 }
92 
93 // disable for non-arithmetic types, with clear compile-time error message
94 template <typename T>
95 typename std::enable_if<!std::is_arithmetic<T>::value>::type // = void if enabled
96 deg2rad(T value) {
97  static_assert(sizeof(T)==0,
98  "deg2rad must be used with arithmetic types");
99 }
100 
102 template <typename T>
103 inline
104 typename std::enable_if<std::is_floating_point<T>::value, T>::type
105 rad2deg(T value) {
106  return Private::rad2deg<T, T>(value);
107 }
108 
110 template <typename T>
111 inline
112 typename std::enable_if<std::is_integral<T>::value, double>::type
113 rad2deg(T value) {
114  return Private::rad2deg<T, double>(value);
115 }
116 
117 // disable for non-arithmetic types, with clear compile-time error message
118 template <typename T>
119 typename std::enable_if<!std::is_arithmetic<T>::value>::type // = void if enabled
120 rad2deg(T value) {
121  static_assert(sizeof(T)==0,
122  "rad2deg must be used with arithmetic types");
123 }
124 
126 
128 namespace Private {
130 struct DegreeUnitTag {
132  static const char* unit() { return "deg"; }
133 };
135 struct RadianUnitTag {
137  static const char* unit() { return "rad"; }
138 };
139 
140 // helper for converting angles from FromTag to ToTag, e.g. DegreeUnitTag to RadianUnitTag.
141 template <typename T, typename FromTag, typename ToTag>
142 struct AngleConverter {
143  static_assert(sizeof(FromTag)==0, "Angle conversion not specialized!");
144  static T convert(T value) { return static_cast<T>(0); }
145 };
146 
147 
148 // specializations for the actual conversions
149 template <typename T>
150 struct AngleConverter<T,DegreeUnitTag,RadianUnitTag> {
151  static T convert(T value) { return mira::deg2rad(value); }
152 };
153 
154 template <typename T>
155 struct AngleConverter<T,RadianUnitTag,DegreeUnitTag> {
156  static T convert(T value) { return mira::rad2deg(value); }
157 };
158 
159 template <typename T,typename SameTag>
160 struct AngleConverter<T,SameTag,SameTag> {
161  static T convert(T value) { return value; }
162 };
163 
168 template <typename A, typename B>
169 struct AnglePromoteHelper {
170  typedef decltype(A(0) + B(0)) type;
171 };
172 
173 }
175 
181 template <typename T, typename UnitTag, typename Derived>
183 {
184 protected:
185 
186  // direct fast initialization without normalization
187  AngleBase(T value, int) : mValue(value) {}
188 
190  explicit AngleBase(T value) { setValue(value); }
191  AngleBase(const AngleBase& other) : mValue(other.mValue) {}
192 
193  template <typename OtherT, typename OtherUnitTag, typename OtherDerived>
195  setValue(conv(other));
196  }
197 
198  // generated copy constructor is suitable
199 
200  // assignment operator implementations that are used by derived classes
201  template <typename OtherUnitTag, typename OtherDerived>
203  mValue = conv(other);
204  }
205 
206  void operator=(const T& other) {
207  setValue(other);
208  }
209 
210 public:
211 
212  template <typename Reflector>
213  void reflect(Reflector& r) {
214  r.delegate(mValue);
215  }
216 
217 public:
218 
224  static T upper() { return Derived::lower() + Derived::turn(); }
225 
226 
227 public:
228 
230  void setValue(const T& value)
231  {
232  mValue = value;
233  if(mValue < Derived::upper() && mValue >= Derived::lower())
234  return;
235  // for deviations of two times turn from the allowed interval the floor
236  // operation is faster than a while loop
237  // therefore, the explicit check for interval in the line above makes sense
238  // to make it faster if no clipping is necessary
239 #ifdef MIRA_LINUX
240  mValue -= Derived::turn() * floor((mValue - Derived::lower())/ Derived::turn());
241 #endif
242 #ifdef MIRA_WINDOWS
243  mValue -= Derived::turn() * floor((double)(mValue - Derived::lower())/ Derived::turn());
244 #endif
245  //for integer types the floor operation fails
246  if(mValue < Derived::lower())
247  mValue += Derived::turn();
248  }
249 
251  const T& value() const { return mValue; }
252 
264  explicit operator T() const { return mValue; }
265 
274  void setSerializedValue(const T& value) {
275  setValue(Derived::convertFromSerialized(value));
276  }
277 
286  T serializedValue() const { return Derived::convertToSerialized(mValue); }
287 
288 
289 public:
290 
292  T deg() const { return This()->toDeg(); }
293 
295  T rad() const { return This()->toRad();}
296 
297 public:
298  // operators
299 
300  // note the generic operators take Derived& as first argument, while
301  // the operators, where T& is a parameter take AngleBase& as argument.
302  // this is necessary to resolve the ISO C++ ambiguity with type conversation
303 
305  template <typename OtherUnitTag, typename OtherDerived>
306  friend Derived operator+(const Derived& a, const AngleBase<T,OtherUnitTag,OtherDerived>& b) {
307  return Derived( a.mValue + conv(b) );
308  }
310  friend Derived operator+(const AngleBase& a, const T& b) {
311  return Derived( a.mValue + b);
312  }
314  friend Derived operator+(const T& a, const AngleBase& b) {
315  return Derived( a + b.mValue);
316  }
317 
319  template <typename OtherUnitTag, typename OtherDerived>
320  friend Derived operator-(const Derived& a,const AngleBase<T,OtherUnitTag,OtherDerived>& b) {
321  return Derived( a.mValue - conv(b) );
322  }
324  friend Derived operator-(const AngleBase& a, const T& b) {
325  return Derived( a.mValue - b);
326  }
328  friend Derived operator-(const T& a, const AngleBase& b) {
329  return Derived( a - b.mValue);
330  }
331 
333  Derived operator-() const {
334  return Derived(-mValue);
335  }
336 
338  friend Derived operator*(const Derived& a, const T& b) {
339  return Derived( a.mValue * b);
340  }
342  friend Derived operator*(const T& a, const Derived& b) {
343  return Derived( a * b.mValue);
344  }
345 
347  friend Derived operator/(const Derived& a, const T& b) {
348  return Derived( a.mValue / b);
349  }
350 
351 
353  template <typename OtherUnitTag, typename OtherDerived>
355  setValue(mValue+conv(a));
356  return *This();
357  }
359  Derived& operator+=(const T& a) {
360  setValue(mValue+a);
361  return *This();
362  }
363 
365  template <typename OtherUnitTag, typename OtherDerived>
367  setValue(mValue-conv(a));
368  return *This();
369  }
371  Derived& operator-=(const T& a) {
372  setValue(mValue-a);
373  return *This();
374  }
375 
377  Derived& operator*=(const T& s) {
378  setValue(mValue*s);
379  return *This();
380  }
381 
383  Derived& operator/=(const T& s) {
384  setValue(mValue/s);
385  return *This();
386  }
387 
388 
389  friend bool operator<(const AngleBase& a, const AngleBase& b) { return a.mValue < b.mValue; }
390  friend bool operator<=(const AngleBase& a, const AngleBase& b) { return a.mValue <= b.mValue; }
391  friend bool operator>(const AngleBase& a, const AngleBase& b) { return a.mValue > b.mValue; }
392  friend bool operator>=(const AngleBase& a, const AngleBase& b) { return a.mValue >= b.mValue; }
393  friend bool operator==(const AngleBase& a, const AngleBase& b) { return a.mValue == b.mValue; }
394  friend bool operator!=(const AngleBase& a, const AngleBase& b) { return a.mValue != b.mValue; }
395 
396 
397 public:
398 
405  T smallestDifferenceValue(const Derived& other) const
406  {
407  T d = mValue - other.mValue;
408 
409  static const T halfTurn = Derived::turn() / 2;
410  if(d > halfTurn)
411  d -= Derived::turn();
412  else if(d <= -halfTurn)
413  d += Derived::turn();
414 
415  return d;
416  }
417 
422  bool isInInterval(const Derived& min, const Derived& max) const
423  {
424  if (min.mValue <= max.mValue)
425  return mValue >= min.mValue && mValue <= max.mValue;
426  return mValue >= min.mValue || mValue <= max.mValue;
427  }
428 
429 public:
430 
432  friend std::ostream& operator<<(std::ostream& o, const AngleBase& v ) {
433  o << v.value() << " " << UnitTag::unit();
434  return o;
435  }
436 
437 public:
438 
443  static const char* unit() {
444  return UnitTag::unit();
445  }
446 
447 private:
448 
450  template <typename OtherT, typename OtherUnitTag, typename OtherDerived>
451  static T conv(const AngleBase<OtherT,OtherUnitTag,OtherDerived>& other) {
453  return Private::AngleConverter<type,OtherUnitTag,UnitTag>::convert(other.value());
454  }
455 
456 
458  Derived* This() { return static_cast<Derived*>(this); }
459 
461  const Derived* This() const { return static_cast<const Derived*>(this); }
462 
463 protected:
464 
467 };
468 
469 
470 #define MIRA_ANGLE_CONSTRUCTORS_AND_ASSIGNOPS(Type) \
471 protected: \
472  Type(const T& value, int) : Base(value,1) {} \
473 public: \
474  Type() {} \
475  explicit Type(T value) : Base(value) {} \
476  template <typename OtherT, typename OtherUnitTag, typename OtherDerived> \
477  Type(const AngleBase<OtherT,OtherUnitTag,OtherDerived>& other) : Base(other) {} \
478  template <typename OtherUnitTag, typename OtherDerived> \
479  Type& operator=(const AngleBase<T,OtherUnitTag,OtherDerived>& other) { \
480  Base::operator=(other); \
481  return *this; } \
482  Type& operator=(const T& other) { \
483  Base::operator=(other); \
484  return *this; }
485 
486 
488 
492 template <typename T, typename Derived>
493 class DegreeBase : public AngleBase<T, Private::DegreeUnitTag, Derived>
494 {
495  friend class AngleBase<T, Private::DegreeUnitTag, Derived>;
496  typedef AngleBase<T, Private::DegreeUnitTag, Derived> Base;
497 public:
499 
500 public:
502  static T turn() { return (T)360; }
503 
505  static T convertToSerialized(T value) { return value; }
506 
508  static T convertFromSerialized(T value) { return value; }
509 
510 private:
512  T toDeg() const { return this->mValue; }
513 
515  T toRad() const { return deg2rad(this->mValue); }
516 };
517 
521 template <typename T, typename Derived>
522 class RadianBase : public AngleBase<T, Private::RadianUnitTag, Derived>
523 {
524  static_assert(std::is_floating_point<T>::value,
525  "Radians make sense with floating point types only. "
526  "Use Degree if you want to represent angles with integral types");
527 
528  friend class AngleBase<T, Private::RadianUnitTag, Derived>;
529  typedef AngleBase<T, Private::RadianUnitTag, Derived> Base;
530 
531 public:
533 
534 public:
536  static T turn() { return two_pi<T>(); }
537 
539  static T convertToSerialized(T value) { return value; }
540 
542  static T convertFromSerialized(T value) { return value; }
543 
544 private:
546  T toDeg() const { return rad2deg(this->mValue); }
547 
549  T toRad() const { return this->mValue; }
550 
551 };
552 
554 
555 // forward decl
556 template <typename T>
557 class Degree;
558 
569 template <typename T>
570 class SignedDegree : public DegreeBase<T, SignedDegree<T>>
571 {
573  friend class Degree<T>;
574 public:
576 
577 
582  static T lower() { return static_cast<T>(-180); }
583 
589  return SignedDegree<T>(this->smallestDifferenceValue(other), 1);
590  }
591 };
592 
593 template <typename T, typename SerializerTag>
594 class IsTransparentSerializable<SignedDegree<T>,SerializerTag> : public std::true_type {};
595 
596 
607 template <typename T>
608 class Degree : public DegreeBase<T, Degree<T>>
609 {
610  typedef DegreeBase<T, Degree<T>> Base;
611 public:
613 
614 
619  static T lower() { return static_cast<T>(0); }
620 
626  return SignedDegree<T>(this->smallestDifferenceValue(other), 1);
627  }
628 };
629 
630 template <typename T, typename SerializerTag>
631 class IsTransparentSerializable<Degree<T>,SerializerTag> : public std::true_type {};
632 
634 
635 // forward decl
636 template <typename T>
637 class Radian;
638 
649 template <typename T>
650 class SignedRadian : public RadianBase<T, SignedRadian<T>>
651 {
653  friend class Radian<T>;
654 public:
656 
657 
662  static T lower() { return -pi<T>(); }
663 
669  return SignedRadian<T>(this->smallestDifferenceValue(other), 1);
670  }
671 };
672 
673 template <typename T, typename SerializerTag>
674 class IsTransparentSerializable<SignedRadian<T>,SerializerTag> : public std::true_type {};
675 
686 template <typename T>
687 class Radian : public RadianBase<T, Radian<T>>
688 {
689  typedef RadianBase<T, Radian<T>> Base;
690 public:
692 
693 
698  static T lower() { return static_cast<T>(0); }
699 
705  return SignedRadian<T>(this->smallestDifferenceValue(other), 1);
706  }
707 };
708 
709 template <typename T, typename SerializerTag>
710 class IsTransparentSerializable<Radian<T>,SerializerTag> : public std::true_type {};
711 
713 
714 // forward decl
715 template <typename T>
716 class Angle;
717 
731 template <typename T>
732 class SignedAngle : public RadianBase<T, SignedAngle<T>>
733 {
735  friend class Angle<T>;
736 public:
738 
739  template <typename Reflector>
740  void reflect(Reflector& r) {
741  r.delegate(getter<T>(convertToSerialized, this->mValue),
742  setter<T>(convertFromSerialized, this->mValue));
743  }
744 
750  static T lower() { return -pi<T>(); }
751 
757  return SignedAngle<T>(this->smallestDifferenceValue(other), 1);
758  }
759 
760 
762  MIRA_DEPRECATED("use Radian<T>(value)", static SignedAngle fromRad(T value)) {
763  return SignedAngle(Radian<T>(value));
764  }
766  MIRA_DEPRECATED("use Degree<T>(value)", static SignedAngle fromDeg(T value)) {
767  return SignedAngle(Degree<T>(value));
768  }
769 
770 public:
771  // overwite convertXYZSerialized since Angle uses different internal and serialized representation.
773  static T convertToSerialized(T value) { return rad2deg<T>(value); }
774 
776  static T convertFromSerialized(T value) { return deg2rad<T>(value); }
777 };
778 
779 template <typename T, typename SerializerTag>
780 class IsTransparentSerializable<SignedAngle<T>,SerializerTag> : public std::true_type {};
781 
782 
796 template <typename T>
797 class Angle : public RadianBase<T, Angle<T>>
798 {
799  typedef RadianBase<T, Angle<T>> Base;
800 public:
802 
803  template <typename Reflector>
804  void reflect(Reflector& r) {
805  r.delegate(getter<T>(convertToSerialized, this->mValue),
806  setter<T>(convertFromSerialized, this->mValue));
807  }
808 
814  static T lower() { return static_cast<T>(0); }
815 
821  return SignedAngle<T>(this->smallestDifferenceValue(other), 1);
822  }
823 
825  MIRA_DEPRECATED("use Radian<T>(value)", static Angle fromRad(T value)) {
826  return Angle(Radian<T>(value));
827  }
829  MIRA_DEPRECATED("use Degree<T>(value)", static Angle fromDeg(T value)) {
830  return Angle(Degree<T>(value));
831  }
832 
833 public:
834  // overwite convertXYZSerialized since Angle uses different internal and serialized representation.
836  static T convertToSerialized(T value) { return rad2deg<T>(value); }
837 
839  static T convertFromSerialized(T value) { return deg2rad<T>(value); }
840 };
841 
842 template <typename T, typename SerializerTag>
843 class IsTransparentSerializable<Angle<T>,SerializerTag> : public std::true_type {};
844 
845 
847 
860 
869 
878 
880 
886 template<typename T>
887 inline T smallestAngleDifference(const T& a, const T& b)
888 {
889  return SignedAngle<T>(a).smallestDifference(SignedAngle<T>(b)).value();
890 }
891 
893 template<typename T>
894 inline bool inAngleInterval(T value, T min, T max)
895 {
896  return SignedAngle<T>(value).isInInterval(SignedAngle<T>(min),
897  SignedAngle<T>(max));
898 }
899 
901 template<typename T>
902 inline bool isInAngleInterval(T value, T min, T max)
903 {
904  return SignedAngle<T>(value).isInInterval(SignedAngle<T>(min),
905  SignedAngle<T>(max));
906 }
908 
923 template <typename T>
924 Getter<T> rad2degGetter(const T& cref)
925 {
926  return getter<T>([&]{return rad2deg<T>(cref);});
927 }
928 
933 struct Deg2RadNonNegativeType { explicit Deg2RadNonNegativeType() = default; };
934 
940 
942 template <typename T>
944 {
945  return setter<T>([&ref](const T& in){ ref = deg2rad<T>(in);});
946 }
947 
961 template <typename T>
963 {
964  // we should throw an exception in error case here as we cannot emit a
965  // message including the name of the member/property at this place
966  // --> exception allows to catch on a higher level to add/show more information
967  return setter<T>([&ref](const T& in){
968  if (in < 0) {
969  MIRA_THROW(XInvalidParameter,
970  "deg2radSetter: input value must be non-negative.");
971  }
972  ref = deg2rad<T>(in);
973  });
974 }
975 
986 template <typename T>
988  return makeAccessor(rad2degGetter(ref), deg2radSetter(ref));
989 }
990 
1002 template <typename T>
1005 }
1006 
1008 
1009 }
1010 
1012 
1013 // specialization of std::abs for all Angle types
1014 namespace std {
1015 template <typename T, typename UnitTag, typename Derived>
1016 inline Derived abs(const mira::AngleBase<T,UnitTag,Derived>& other) {
1017  return Derived(std::abs(other.value()));
1018 }
1019 }
1020 
1022 
1023 #endif
void operator=(const T &other)
Definition: Angle.h:206
MIRA_DEPRECATED("use Radian<T>(value)", static Angle fromRad(T value))
deprecated, use Radian<T>(value) instead
Definition: Angle.h:825
SignedAngle< double > SignedAngled
Double precision signed angle.
Definition: Angle.h:873
INTERNAL std::enable_if< std::is_floating_point< T >::value, T >::type deg2rad(T value)
Convert degree to radian, for floating point arguments (return type = argument type) ...
Definition: Angle.h:81
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:508
Base class for angle classes that represent angles using radians.
Definition: Angle.h:522
friend bool operator<=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:390
Type trait that indicates whether a type should be serialized "transparently", i.e.
Definition: IsTransparentSerializable.h:81
friend Derived operator-(const Derived &a, const AngleBase< T, OtherUnitTag, OtherDerived > &b)
Subtract two angles.
Definition: Angle.h:320
Radian< float > Radianf
Float precision angle.
Definition: Angle.h:866
Derived operator-=(const AngleBase< T, OtherUnitTag, OtherDerived > &a)
Subtract other angle from this angle.
Definition: Angle.h:366
Includes often needed math headers and methods and provides additional constants. ...
Degree< double > Degreed
Double precision angle.
Definition: Angle.h:859
SignedDegree< T > smallestDifference(const Degree &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:625
Derived & operator*=(const T &s)
Multiply this angle with scalar.
Definition: Angle.h:377
static const char * unit()
Returns the unit of this angle representation as string, e.g.
Definition: Angle.h:443
friend Derived operator/(const Derived &a, const T &b)
Divide by scalar.
Definition: Angle.h:347
void reflect(Reflector &r)
Definition: Angle.h:804
Getter< T > rad2degGetter(const T &cref)
Create a getter for serializing radians as degrees.
Definition: Angle.h:924
Derived & operator-=(const T &a)
Subtract float value from this angle.
Definition: Angle.h:371
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
MIRA_DEPRECATED("use Degree<T>(value)", static SignedAngle fromDeg(T value))
deprecated, use Degree<T>(value) instead
Definition: Angle.h:766
MIRA_DEPRECATED("use Degree<T>(value)", static Angle fromDeg(T value))
deprecated, use Degree<T>(value) instead
Definition: Angle.h:829
Degree< int > Degreei
Integer precision angle.
Definition: Angle.h:855
friend bool operator<(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:389
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:773
STL namespace.
Signed angle that is represented using degrees.
Definition: Angle.h:570
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
Base class for angle classes that represent angles using degrees.
Definition: Angle.h:493
A tag type used as parameter type in deg2radSetter, signalling that negative values are not permitted...
Definition: Angle.h:933
AngleBase()
Definition: Angle.h:189
SignedRadian< double > SignedRadiand
Double precision signed angle.
Definition: Angle.h:864
Contains internal accessor class that abstracts from the underlying getter and setter classes or dire...
static T lower()
Returns the lower limit of the defined angle interval.
Definition: Angle.h:814
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:539
const T & value() const
Returns the raw angle value given in the native unit of the angle class.
Definition: Angle.h:251
SignedAngle< T > smallestDifference(const SignedAngle &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:756
AngleBase(const AngleBase &other)
Definition: Angle.h:191
SignedRadian< T > smallestDifference(const SignedRadian &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:668
Setter< T > deg2radSetter(T &ref)
Create setter for deserializing radians from degrees. See rad2degGetter.
Definition: Angle.h:943
Derived & operator/=(const T &s)
Divide this angle by scalar.
Definition: Angle.h:383
Duration abs(const Duration &duration)
Get the absolute duration from a duration.
Definition: Time.h:399
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:776
Commonly used exception classes.
AngleBase(T value, int)
Definition: Angle.h:187
void setSerializedValue(const T &value)
Sets the value in the unit that is used for serialization.
Definition: Angle.h:274
SignedDegree< double > SignedDegreed
Double precision signed angle.
Definition: Angle.h:853
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:505
SignedAngle< float > SignedAnglef
Float precision signed angle.
Definition: Angle.h:871
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
T mValue
the actual value
Definition: Angle.h:466
Degree< float > Degreef
Float precision angle.
Definition: Angle.h:857
friend Derived operator-(const T &a, const AngleBase &b)
Subtract two angles.
Definition: Angle.h:328
Derived & operator+=(const T &a)
Add float value to this angle.
Definition: Angle.h:359
Unsigned angle that is represented using degrees.
Definition: Angle.h:557
constexpr Deg2RadNonNegativeType Deg2RadNonNegative
Use this constant as second parameter when calling deg2radSetter, in order to prohibit negative value...
Definition: Angle.h:939
Signed angle that is represented using radians.
Definition: Angle.h:650
AngleBase(const AngleBase< OtherT, OtherUnitTag, OtherDerived > &other)
Definition: Angle.h:194
SignedRadian< T > smallestDifference(const Radian &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:704
friend std::ostream & operator<<(std::ostream &o, const AngleBase &v)
stream operator
Definition: Angle.h:432
friend Derived operator+(const Derived &a, const AngleBase< T, OtherUnitTag, OtherDerived > &b)
Add two angles.
Definition: Angle.h:306
friend Derived operator+(const T &a, const AngleBase &b)
Add two angles.
Definition: Angle.h:314
bool inAngleInterval(T value, T min, T max)
Definition: Angle.h:894
Derived abs(const mira::AngleBase< T, UnitTag, Derived > &other)
Definition: Angle.h:1016
friend Derived operator*(const T &a, const Derived &b)
Multiply with scalar.
Definition: Angle.h:342
void operator=(const AngleBase< T, OtherUnitTag, OtherDerived > &other)
Definition: Angle.h:202
T deg() const
Returns the value of the angle in degrees.
Definition: Angle.h:292
Derived operator+=(const AngleBase< T, OtherUnitTag, OtherDerived > &a)
Add other angle to this angle.
Definition: Angle.h:354
The Accessor class is used as an adapter to reduce the code bloat within the reflection and serializa...
Definition: Accessor.h:244
T rad() const
Returns the value of the angle in radian.
Definition: Angle.h:295
Angle< double > Angled
Double precision angle.
Definition: Angle.h:877
T smallestAngleDifference(const T &a, const T &b)
Returns the signed difference angle between the specified angles (in radian) that has the smallest ab...
Definition: Angle.h:887
Unsigned angle that is represented using radians.
Definition: Angle.h:637
SignedDegree< int > SignedDegreei
Integer precision signed angle.
Definition: Angle.h:849
void reflect(Reflector &r)
Definition: Angle.h:213
friend bool operator>=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:392
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:836
T serializedValue() const
Returns the value in the unit that is used for serialization.
Definition: Angle.h:286
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
Accessor< Getter< T >, Setter< T > > radAsDegAccessor(T &ref)
Create an accessor consisting of getter + setter for serializing radians as degrees.
Definition: Angle.h:987
MIRA_DEPRECATED("use Radian<T>(value)", static SignedAngle fromRad(T value))
deprecated, use Radian<T>(value) instead
Definition: Angle.h:762
friend Derived operator*(const Derived &a, const T &b)
Multiply with scalar.
Definition: Angle.h:338
void reflect(Reflector &r)
Definition: Angle.h:740
void setValue(const T &value)
Set the angle value. The input value is mapped into the angle interval.
Definition: Angle.h:230
AngleBase(T value)
Definition: Angle.h:190
#define MIRA_ANGLE_CONSTRUCTORS_AND_ASSIGNOPS(Type)
Definition: Angle.h:470
Signed angle that is represented using radians.
Definition: Angle.h:732
static T upper()
Returns the upper limit of the defined angle interval.
Definition: Angle.h:224
bool isInInterval(const Derived &min, const Derived &max) const
Returns true, if the angle is in the given interval [min,max].
Definition: Angle.h:422
std::enable_if< std::is_floating_point< T >::value, T >::type rad2deg(T value)
Convert radian to degree, for floating point arguments (return type = argument type) ...
Definition: Angle.h:105
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:839
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:542
friend Derived operator-(const AngleBase &a, const T &b)
Subtract two angles.
Definition: Angle.h:324
Derived operator-() const
Unary minus operator.
Definition: Angle.h:333
SignedDegree< T > smallestDifference(const SignedDegree &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:588
SignedDegree< float > SignedDegreef
Float precision signed angle.
Definition: Angle.h:851
friend Derived operator+(const AngleBase &a, const T &b)
Add two angles.
Definition: Angle.h:310
friend bool operator==(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:393
Accessor< Getter, Setter > makeAccessor(const Getter &getter, const Setter &setter)
Helper method that creates an accessor from a different combination of either direct access to a vari...
Definition: Accessor.h:300
SignedAngle< T > smallestDifference(const Angle &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:820
T smallestDifferenceValue(const Derived &other) const
Returns the signed difference angle between this angle and the specified other angle that has the sma...
Definition: Angle.h:405
SignedRadian< float > SignedRadianf
Float precision signed angle.
Definition: Angle.h:862
static T lower()
Returns the lower limit of the defined angle interval.
Definition: Angle.h:750
Unsigned angle that is represented using radians.
Definition: Angle.h:716
Angle< float > Anglef
Float precision angle.
Definition: Angle.h:875
Base class template for derived Angle implementations.
Definition: Angle.h:182
bool isInAngleInterval(T value, T min, T max)
Returns true, if the given angle (in radian) is in the given interval [min,max].
Definition: Angle.h:902
friend bool operator>(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:391
Platform dependent defines and macros.
friend bool operator!=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:394
Radian< double > Radiand
Double precision angle.
Definition: Angle.h:868