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 #ifndef _MIRA_ANGLE_H_
49 #define _MIRA_ANGLE_H_
50 
51 #include <type_traits>
52 
53 #include <error/Exceptions.h>
54 
55 #include <platform/Platform.h> // for MIRA_DEPRECATED
56 #include <math/Math.h>
57 
58 #include <serialization/Accessor.h>
59 
60 #include <utils/IsCheapToCopy.h>
61 
62 namespace mira {
64 
66 namespace Private {
67 template <typename Param, typename Result>
68 inline Result deg2rad(Param value) {
69  return static_cast<Result>(value * pi_div_deg180<Result>());
70 }
71 template <typename Param, typename Result>
72 inline Result rad2deg(Param value) {
73  return static_cast<Result>(value * deg180_div_pi<Result>());
74 }
75 }
77 
79 template <typename T>
80 inline
81 typename std::enable_if<std::is_floating_point<T>::value, T>::type
82 deg2rad(T value) {
83  return Private::deg2rad<T, T>(value);
84 }
85 
87 template <typename T>
88 inline
89 typename std::enable_if<std::is_integral<T>::value, double>::type
90 deg2rad(T value) {
91  return Private::deg2rad<T, double>(value);
92 }
93 
94 // disable for non-arithmetic types, with clear compile-time error message
95 template <typename T>
96 typename std::enable_if<!std::is_arithmetic<T>::value>::type // = void if enabled
97 deg2rad(T value) {
98  static_assert(sizeof(T)==0,
99  "deg2rad must be used with arithmetic types");
100 }
101 
103 template <typename T>
104 inline
105 typename std::enable_if<std::is_floating_point<T>::value, T>::type
106 rad2deg(T value) {
107  return Private::rad2deg<T, T>(value);
108 }
109 
111 template <typename T>
112 inline
113 typename std::enable_if<std::is_integral<T>::value, double>::type
114 rad2deg(T value) {
115  return Private::rad2deg<T, double>(value);
116 }
117 
118 // disable for non-arithmetic types, with clear compile-time error message
119 template <typename T>
120 typename std::enable_if<!std::is_arithmetic<T>::value>::type // = void if enabled
121 rad2deg(T value) {
122  static_assert(sizeof(T)==0,
123  "rad2deg must be used with arithmetic types");
124 }
125 
127 
129 namespace Private {
131 struct DegreeUnitTag {
133  static const char* unit() { return "deg"; }
134 };
136 struct RadianUnitTag {
138  static const char* unit() { return "rad"; }
139 };
140 
141 // helper for converting angles from FromTag to ToTag, e.g. DegreeUnitTag to RadianUnitTag.
142 template <typename T, typename FromTag, typename ToTag>
143 struct AngleConverter {
144  static_assert(sizeof(FromTag)==0, "Angle conversion not specialized!");
145  static T convert(T value) { return static_cast<T>(0); }
146 };
147 
148 
149 // specializations for the actual conversions
150 template <typename T>
151 struct AngleConverter<T,DegreeUnitTag,RadianUnitTag> {
152  static T convert(T value) { return mira::deg2rad(value); }
153 };
154 
155 template <typename T>
156 struct AngleConverter<T,RadianUnitTag,DegreeUnitTag> {
157  static T convert(T value) { return mira::rad2deg(value); }
158 };
159 
160 template <typename T,typename SameTag>
161 struct AngleConverter<T,SameTag,SameTag> {
162  static T convert(T value) { return value; }
163 };
164 
169 template <typename A, typename B>
170 struct AnglePromoteHelper {
171  typedef decltype(A(0) + B(0)) type;
172 };
173 
174 }
176 
182 template <typename T, typename UnitTag, typename Derived>
184 {
185 protected:
186 
187  // direct fast initialization without normalization
188  AngleBase(T value, int) : mValue(value) {}
189 
191  explicit AngleBase(T value) { setValue(value); }
192  AngleBase(const AngleBase& other) : mValue(other.mValue) {}
193 
194  template <typename OtherT, typename OtherUnitTag, typename OtherDerived>
196  setValue(conv(other));
197  }
198 
199  // generated copy constructor is suitable
200 
201  // assignment operator implementations that are used by derived classes
202  template <typename OtherUnitTag, typename OtherDerived>
204  mValue = conv(other);
205  }
206 
207  void operator=(const T& other) {
208  setValue(other);
209  }
210 
211 public:
212 
213  template <typename Reflector>
214  void reflect(Reflector& r) {
215  r.delegate(mValue);
216  }
217 
218 public:
219 
225  static T upper() { return Derived::lower() + Derived::turn(); }
226 
227 
228 public:
229 
231  void setValue(const T& value)
232  {
233  mValue = value;
234  if(mValue < Derived::upper() && mValue >= Derived::lower())
235  return;
236  // for deviations of two times turn from the allowed interval the floor
237  // operation is faster than a while loop
238  // therefore, the explicit check for interval in the line above makes sense
239  // to make it faster if no clipping is necessary
240 #ifdef MIRA_LINUX
241  mValue -= Derived::turn() * floor((mValue - Derived::lower())/ Derived::turn());
242 #endif
243 #ifdef MIRA_WINDOWS
244  mValue -= Derived::turn() * floor((double)(mValue - Derived::lower())/ Derived::turn());
245 #endif
246  //for integer types the floor operation fails
247  if(mValue < Derived::lower())
248  mValue += Derived::turn();
249  }
250 
252  const T& value() const { return mValue; }
253 
265  explicit operator T() const { return mValue; }
266 
275  void setSerializedValue(const T& value) {
276  setValue(Derived::convertFromSerialized(value));
277  }
278 
287  T serializedValue() const { return Derived::convertToSerialized(mValue); }
288 
289 
290 public:
291 
293  T deg() const { return This()->toDeg(); }
294 
296  T rad() const { return This()->toRad();}
297 
298 public:
299  // operators
300 
301  // note the generic operators take Derived& as first argument, while
302  // the operators, where T& is a parameter take AngleBase& as argument.
303  // this is necessary to resolve the ISO C++ ambiguity with type conversation
304 
306  template <typename OtherUnitTag, typename OtherDerived>
307  friend Derived operator+(const Derived& a, const AngleBase<T,OtherUnitTag,OtherDerived>& b) {
308  return Derived( a.mValue + conv(b) );
309  }
311  friend Derived operator+(const AngleBase& a, const T& b) {
312  return Derived( a.mValue + b);
313  }
315  friend Derived operator+(const T& a, const AngleBase& b) {
316  return Derived( a + b.mValue);
317  }
318 
320  template <typename OtherUnitTag, typename OtherDerived>
321  friend Derived operator-(const Derived& a,const AngleBase<T,OtherUnitTag,OtherDerived>& b) {
322  return Derived( a.mValue - conv(b) );
323  }
325  friend Derived operator-(const AngleBase& a, const T& b) {
326  return Derived( a.mValue - b);
327  }
329  friend Derived operator-(const T& a, const AngleBase& b) {
330  return Derived( a - b.mValue);
331  }
332 
334  Derived operator-() const {
335  return Derived(-mValue);
336  }
337 
339  friend Derived operator*(const Derived& a, const T& b) {
340  return Derived( a.mValue * b);
341  }
343  friend Derived operator*(const T& a, const Derived& b) {
344  return Derived( a * b.mValue);
345  }
346 
348  friend Derived operator/(const Derived& a, const T& b) {
349  return Derived( a.mValue / b);
350  }
351 
352 
354  template <typename OtherUnitTag, typename OtherDerived>
356  setValue(mValue+conv(a));
357  return *This();
358  }
360  Derived& operator+=(const T& a) {
361  setValue(mValue+a);
362  return *This();
363  }
364 
366  template <typename OtherUnitTag, typename OtherDerived>
368  setValue(mValue-conv(a));
369  return *This();
370  }
372  Derived& operator-=(const T& a) {
373  setValue(mValue-a);
374  return *This();
375  }
376 
378  Derived& operator*=(const T& s) {
379  setValue(mValue*s);
380  return *This();
381  }
382 
384  Derived& operator/=(const T& s) {
385  setValue(mValue/s);
386  return *This();
387  }
388 
389 
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  friend bool operator!=(const AngleBase& a, const AngleBase& b) { return a.mValue != b.mValue; }
396 
397 
398 public:
399 
406  T smallestDifferenceValue(const Derived& other) const
407  {
408  T d = mValue - other.mValue;
409 
410  static const T halfTurn = Derived::turn() / 2;
411  if(d > halfTurn)
412  d -= Derived::turn();
413  else if(d <= -halfTurn)
414  d += Derived::turn();
415 
416  return d;
417  }
418 
423  bool isInInterval(const Derived& min, const Derived& max) const
424  {
425  if (min.mValue <= max.mValue)
426  return mValue >= min.mValue && mValue <= max.mValue;
427  return mValue >= min.mValue || mValue <= max.mValue;
428  }
429 
430 public:
431 
433  friend std::ostream& operator<<(std::ostream& o, const AngleBase& v ) {
434  o << v.value() << " " << UnitTag::unit();
435  return o;
436  }
437 
438 public:
439 
444  static const char* unit() {
445  return UnitTag::unit();
446  }
447 
448 private:
449 
451  template <typename OtherT, typename OtherUnitTag, typename OtherDerived>
452  static T conv(const AngleBase<OtherT,OtherUnitTag,OtherDerived>& other) {
454  return Private::AngleConverter<type,OtherUnitTag,UnitTag>::convert(other.value());
455  }
456 
457 
459  Derived* This() { return static_cast<Derived*>(this); }
460 
462  const Derived* This() const { return static_cast<const Derived*>(this); }
463 
464 protected:
465 
468 };
469 
470 
471 #define MIRA_ANGLE_CONSTRUCTORS_AND_ASSIGNOPS(Type) \
472 protected: \
473  Type(const T& value, int) : Base(value,1) {} \
474 public: \
475  Type() {} \
476  explicit Type(T value) : Base(value) {} \
477  template <typename OtherT, typename OtherUnitTag, typename OtherDerived> \
478  Type(const AngleBase<OtherT,OtherUnitTag,OtherDerived>& other) : Base(other) {} \
479  template <typename OtherUnitTag, typename OtherDerived> \
480  Type& operator=(const AngleBase<T,OtherUnitTag,OtherDerived>& other) { \
481  Base::operator=(other); \
482  return *this; } \
483  Type& operator=(const T& other) { \
484  Base::operator=(other); \
485  return *this; }
486 
487 
489 
493 template <typename T, typename Derived>
494 class DegreeBase : public AngleBase<T, Private::DegreeUnitTag, Derived>
495 {
496  friend class AngleBase<T, Private::DegreeUnitTag, Derived>;
497  typedef AngleBase<T, Private::DegreeUnitTag, Derived> Base;
498 public:
500 
501 public:
503  static T turn() { return (T)360; }
504 
506  static T convertToSerialized(T value) { return value; }
507 
509  static T convertFromSerialized(T value) { return value; }
510 
511 private:
513  T toDeg() const { return this->mValue; }
514 
516  T toRad() const { return deg2rad(this->mValue); }
517 };
518 
522 template <typename T, typename Derived>
523 class RadianBase : public AngleBase<T, Private::RadianUnitTag, Derived>
524 {
525  static_assert(std::is_floating_point<T>::value,
526  "Radians make sense with floating point types only. "
527  "Use Degree if you want to represent angles with integral types");
528 
529  friend class AngleBase<T, Private::RadianUnitTag, Derived>;
530  typedef AngleBase<T, Private::RadianUnitTag, Derived> Base;
531 
532 public:
534 
535 public:
537  static T turn() { return two_pi<T>(); }
538 
540  static T convertToSerialized(T value) { return value; }
541 
543  static T convertFromSerialized(T value) { return value; }
544 
545 private:
547  T toDeg() const { return rad2deg(this->mValue); }
548 
550  T toRad() const { return this->mValue; }
551 
552 };
553 
555 
556 // forward decl
557 template <typename T>
558 class Degree;
559 
570 template <typename T>
571 class SignedDegree : public DegreeBase<T, SignedDegree<T>>
572 {
574  friend class Degree<T>;
575 public:
577 
578 
583  static T lower() { return static_cast<T>(-180); }
584 
590  return SignedDegree<T>(this->smallestDifferenceValue(other), 1);
591  }
592 };
593 
594 template <typename T, typename SerializerTag>
595 class IsTransparentSerializable<SignedDegree<T>,SerializerTag> : public std::true_type {};
596 
597 
608 template <typename T>
609 class Degree : public DegreeBase<T, Degree<T>>
610 {
611  typedef DegreeBase<T, Degree<T>> Base;
612 public:
614 
615 
620  static T lower() { return static_cast<T>(0); }
621 
627  return SignedDegree<T>(this->smallestDifferenceValue(other), 1);
628  }
629 };
630 
631 template <typename T, typename SerializerTag>
632 class IsTransparentSerializable<Degree<T>,SerializerTag> : public std::true_type {};
633 
635 
636 // forward decl
637 template <typename T>
638 class Radian;
639 
650 template <typename T>
651 class SignedRadian : public RadianBase<T, SignedRadian<T>>
652 {
654  friend class Radian<T>;
655 public:
657 
658 
663  static T lower() { return -pi<T>(); }
664 
670  return SignedRadian<T>(this->smallestDifferenceValue(other), 1);
671  }
672 };
673 
674 template <typename T, typename SerializerTag>
675 class IsTransparentSerializable<SignedRadian<T>,SerializerTag> : public std::true_type {};
676 
687 template <typename T>
688 class Radian : public RadianBase<T, Radian<T>>
689 {
690  typedef RadianBase<T, Radian<T>> Base;
691 public:
693 
694 
699  static T lower() { return static_cast<T>(0); }
700 
706  return SignedRadian<T>(this->smallestDifferenceValue(other), 1);
707  }
708 };
709 
710 template <typename T, typename SerializerTag>
711 class IsTransparentSerializable<Radian<T>,SerializerTag> : public std::true_type {};
712 
714 
715 // forward decl
716 template <typename T>
717 class Angle;
718 
732 template <typename T>
733 class SignedAngle : public RadianBase<T, SignedAngle<T>>
734 {
736  friend class Angle<T>;
737 public:
739 
740  template <typename Reflector>
741  void reflect(Reflector& r) {
742  r.delegate(getter<T>(convertToSerialized, this->mValue),
743  setter<T>(convertFromSerialized, this->mValue));
744  }
745 
751  static T lower() { return -pi<T>(); }
752 
758  return SignedAngle<T>(this->smallestDifferenceValue(other), 1);
759  }
760 
761 
763  MIRA_DEPRECATED("use Radian<T>(value)", static SignedAngle fromRad(T value)) {
764  return SignedAngle(Radian<T>(value));
765  }
767  MIRA_DEPRECATED("use Degree<T>(value)", static SignedAngle fromDeg(T value)) {
768  return SignedAngle(Degree<T>(value));
769  }
770 
771 public:
772  // overwite convertXYZSerialized since Angle uses different internal and serialized representation.
774  static T convertToSerialized(T value) { return rad2deg<T>(value); }
775 
777  static T convertFromSerialized(T value) { return deg2rad<T>(value); }
778 };
779 
780 template <typename T, typename SerializerTag>
781 class IsTransparentSerializable<SignedAngle<T>,SerializerTag> : public std::true_type {};
782 
783 
797 template <typename T>
798 class Angle : public RadianBase<T, Angle<T>>
799 {
800  typedef RadianBase<T, Angle<T>> Base;
801 public:
803 
804  template <typename Reflector>
805  void reflect(Reflector& r) {
806  r.delegate(getter<T>(convertToSerialized, this->mValue),
807  setter<T>(convertFromSerialized, this->mValue));
808  }
809 
815  static T lower() { return static_cast<T>(0); }
816 
822  return SignedAngle<T>(this->smallestDifferenceValue(other), 1);
823  }
824 
826  MIRA_DEPRECATED("use Radian<T>(value)", static Angle fromRad(T value)) {
827  return Angle(Radian<T>(value));
828  }
830  MIRA_DEPRECATED("use Degree<T>(value)", static Angle fromDeg(T value)) {
831  return Angle(Degree<T>(value));
832  }
833 
834 public:
835  // overwite convertXYZSerialized since Angle uses different internal and serialized representation.
837  static T convertToSerialized(T value) { return rad2deg<T>(value); }
838 
840  static T convertFromSerialized(T value) { return deg2rad<T>(value); }
841 };
842 
843 template <typename T, typename SerializerTag>
844 class IsTransparentSerializable<Angle<T>,SerializerTag> : public std::true_type {};
845 
846 
848 
861 
870 
879 
881 
882 template <>
883 class IsCheapToCopy<SignedDegreei> : public std::true_type {};
884 
885 template <>
886 class IsCheapToCopy<SignedDegreef> : public std::true_type {};
887 
888 template <>
889 class IsCheapToCopy<SignedDegreed> : public std::true_type {};
890 
891 template <>
892 class IsCheapToCopy<Degreei> : public std::true_type {};
893 
894 template <>
895 class IsCheapToCopy<Degreef> : public std::true_type {};
896 
897 template <>
898 class IsCheapToCopy<Degreed> : public std::true_type {};
899 
900 template <>
901 class IsCheapToCopy<SignedRadianf> : public std::true_type {};
902 
903 template <>
904 class IsCheapToCopy<SignedRadiand> : public std::true_type {};
905 
906 template <>
907 class IsCheapToCopy<Radianf> : public std::true_type {};
908 
909 template <>
910 class IsCheapToCopy<Radiand> : public std::true_type {};
911 
912 template <>
913 class IsCheapToCopy<SignedAnglef> : public std::true_type {};
914 
915 template <>
916 class IsCheapToCopy<SignedAngled> : public std::true_type {};
917 
918 template <>
919 class IsCheapToCopy<Anglef> : public std::true_type {};
920 
921 template <>
922 class IsCheapToCopy<Angled> : public std::true_type {};
923 
925 
931 template<typename T>
932 inline T smallestAngleDifference(const T& a, const T& b)
933 {
934  return SignedAngle<T>(a).smallestDifference(SignedAngle<T>(b)).value();
935 }
936 
938 template<typename T>
939 inline bool inAngleInterval(T value, T min, T max)
940 {
941  return SignedAngle<T>(value).isInInterval(SignedAngle<T>(min),
942  SignedAngle<T>(max));
943 }
944 
946 template<typename T>
947 inline bool isInAngleInterval(T value, T min, T max)
948 {
949  return SignedAngle<T>(value).isInInterval(SignedAngle<T>(min),
950  SignedAngle<T>(max));
951 }
953 
968 template <typename T>
969 Getter<T> rad2degGetter(const T& cref)
970 {
971  return getter<T>([&]{return rad2deg<T>(cref);});
972 }
973 
978 struct Deg2RadNonNegativeType { explicit Deg2RadNonNegativeType() = default; };
979 
985 
987 template <typename T>
989 {
990  return setter<T>([&ref](const T& in){ ref = deg2rad<T>(in);});
991 }
992 
1006 template <typename T>
1008 {
1009  // we should throw an exception in error case here as we cannot emit a
1010  // message including the name of the member/property at this place
1011  // --> exception allows to catch on a higher level to add/show more information
1012  return setter<T>([&ref](const T& in){
1013  if (in < 0) {
1014  MIRA_THROW(XInvalidParameter,
1015  "deg2radSetter: input value must be non-negative.");
1016  }
1017  ref = deg2rad<T>(in);
1018  });
1019 }
1020 
1031 template <typename T>
1033  return makeAccessor(rad2degGetter(ref), deg2radSetter(ref));
1034 }
1035 
1047 template <typename T>
1050 }
1051 
1053 
1054 }
1055 
1057 
1058 // specialization of std::abs for all Angle types
1059 namespace std {
1060 template <typename T, typename UnitTag, typename Derived>
1061 inline Derived abs(const mira::AngleBase<T,UnitTag,Derived>& other) {
1062  return Derived(std::abs(other.value()));
1063 }
1064 }
1065 
1067 
1068 #endif
void operator=(const T &other)
Definition: Angle.h:207
MIRA_DEPRECATED("use Radian<T>(value)", static Angle fromRad(T value))
deprecated, use Radian<T>(value) instead
Definition: Angle.h:826
SignedAngle< double > SignedAngled
Double precision signed angle.
Definition: Angle.h:874
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:82
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:509
Base class for angle classes that represent angles using radians.
Definition: Angle.h:523
friend bool operator<=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:391
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:321
Radian< float > Radianf
Float precision angle.
Definition: Angle.h:867
Derived operator-=(const AngleBase< T, OtherUnitTag, OtherDerived > &a)
Subtract other angle from this angle.
Definition: Angle.h:367
Includes often needed math headers and methods and provides additional constants. ...
Degree< double > Degreed
Double precision angle.
Definition: Angle.h:860
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:626
Derived & operator*=(const T &s)
Multiply this angle with scalar.
Definition: Angle.h:378
static const char * unit()
Returns the unit of this angle representation as string, e.g.
Definition: Angle.h:444
friend Derived operator/(const Derived &a, const T &b)
Divide by scalar.
Definition: Angle.h:348
void reflect(Reflector &r)
Definition: Angle.h:805
Getter< T > rad2degGetter(const T &cref)
Create a getter for serializing radians as degrees.
Definition: Angle.h:969
Derived & operator-=(const T &a)
Subtract float value from this angle.
Definition: Angle.h:372
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:767
MIRA_DEPRECATED("use Degree<T>(value)", static Angle fromDeg(T value))
deprecated, use Degree<T>(value) instead
Definition: Angle.h:830
Degree< int > Degreei
Integer precision angle.
Definition: Angle.h:856
friend bool operator<(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:390
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:774
STL namespace.
Signed angle that is represented using degrees.
Definition: Angle.h:571
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:494
A tag type used as parameter type in deg2radSetter, signalling that negative values are not permitted...
Definition: Angle.h:978
AngleBase()
Definition: Angle.h:190
SignedRadian< double > SignedRadiand
Double precision signed angle.
Definition: Angle.h:865
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:815
#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:540
const T & value() const
Returns the raw angle value given in the native unit of the angle class.
Definition: Angle.h:252
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:757
AngleBase(const AngleBase &other)
Definition: Angle.h:192
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:669
Setter< T > deg2radSetter(T &ref)
Create setter for deserializing radians from degrees. See rad2degGetter.
Definition: Angle.h:988
Derived & operator/=(const T &s)
Divide this angle by scalar.
Definition: Angle.h:384
Duration abs(const Duration &duration)
Get the absolute duration from a duration.
Definition: Time.h:401
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:777
Commonly used exception classes.
AngleBase(T value, int)
Definition: Angle.h:188
void setSerializedValue(const T &value)
Sets the value in the unit that is used for serialization.
Definition: Angle.h:275
SignedDegree< double > SignedDegreed
Double precision signed angle.
Definition: Angle.h:854
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:506
SignedAngle< float > SignedAnglef
Float precision signed angle.
Definition: Angle.h:872
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
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:467
Degree< float > Degreef
Float precision angle.
Definition: Angle.h:858
friend Derived operator-(const T &a, const AngleBase &b)
Subtract two angles.
Definition: Angle.h:329
Derived & operator+=(const T &a)
Add float value to this angle.
Definition: Angle.h:360
Unsigned angle that is represented using degrees.
Definition: Angle.h:558
Type trait to define if a class is cheap to copy.
constexpr Deg2RadNonNegativeType Deg2RadNonNegative
Use this constant as second parameter when calling deg2radSetter, in order to prohibit negative value...
Definition: Angle.h:984
Signed angle that is represented using radians.
Definition: Angle.h:651
AngleBase(const AngleBase< OtherT, OtherUnitTag, OtherDerived > &other)
Definition: Angle.h:195
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:705
friend std::ostream & operator<<(std::ostream &o, const AngleBase &v)
stream operator
Definition: Angle.h:433
friend Derived operator+(const Derived &a, const AngleBase< T, OtherUnitTag, OtherDerived > &b)
Add two angles.
Definition: Angle.h:307
friend Derived operator+(const T &a, const AngleBase &b)
Add two angles.
Definition: Angle.h:315
bool inAngleInterval(T value, T min, T max)
Definition: Angle.h:939
Derived abs(const mira::AngleBase< T, UnitTag, Derived > &other)
Definition: Angle.h:1061
friend Derived operator*(const T &a, const Derived &b)
Multiply with scalar.
Definition: Angle.h:343
void operator=(const AngleBase< T, OtherUnitTag, OtherDerived > &other)
Definition: Angle.h:203
T deg() const
Returns the value of the angle in degrees.
Definition: Angle.h:293
Derived operator+=(const AngleBase< T, OtherUnitTag, OtherDerived > &a)
Add other angle to this angle.
Definition: Angle.h:355
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:296
Angle< double > Angled
Double precision angle.
Definition: Angle.h:878
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:932
Unsigned angle that is represented using radians.
Definition: Angle.h:638
SignedDegree< int > SignedDegreei
Integer precision signed angle.
Definition: Angle.h:850
void reflect(Reflector &r)
Definition: Angle.h:214
friend bool operator>=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:393
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:837
T serializedValue() const
Returns the value in the unit that is used for serialization.
Definition: Angle.h:287
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:1032
MIRA_DEPRECATED("use Radian<T>(value)", static SignedAngle fromRad(T value))
deprecated, use Radian<T>(value) instead
Definition: Angle.h:763
friend Derived operator*(const Derived &a, const T &b)
Multiply with scalar.
Definition: Angle.h:339
void reflect(Reflector &r)
Definition: Angle.h:741
void setValue(const T &value)
Set the angle value. The input value is mapped into the angle interval.
Definition: Angle.h:231
AngleBase(T value)
Definition: Angle.h:191
#define MIRA_ANGLE_CONSTRUCTORS_AND_ASSIGNOPS(Type)
Definition: Angle.h:471
Signed angle that is represented using radians.
Definition: Angle.h:733
static T upper()
Returns the upper limit of the defined angle interval.
Definition: Angle.h:225
bool isInInterval(const Derived &min, const Derived &max) const
Returns true, if the angle is in the given interval [min,max].
Definition: Angle.h:423
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:106
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:840
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:543
friend Derived operator-(const AngleBase &a, const T &b)
Subtract two angles.
Definition: Angle.h:325
Derived operator-() const
Unary minus operator.
Definition: Angle.h:334
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:589
SignedDegree< float > SignedDegreef
Float precision signed angle.
Definition: Angle.h:852
friend Derived operator+(const AngleBase &a, const T &b)
Add two angles.
Definition: Angle.h:311
friend bool operator==(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:394
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:821
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:406
SignedRadian< float > SignedRadianf
Float precision signed angle.
Definition: Angle.h:863
static T lower()
Returns the lower limit of the defined angle interval.
Definition: Angle.h:751
Unsigned angle that is represented using radians.
Definition: Angle.h:717
Angle< float > Anglef
Float precision angle.
Definition: Angle.h:876
Base class template for derived Angle implementations.
Definition: Angle.h:183
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:947
friend bool operator>(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:392
Platform dependent defines and macros.
friend bool operator!=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:395
Radian< double > Radiand
Double precision angle.
Definition: Angle.h:869