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  mValue -= Derived::turn() * floor((mValue - Derived::lower())/ Derived::turn());
241 
242  //for integer types the floor operation fails
243  if(mValue < Derived::lower())
244  mValue += Derived::turn();
245  }
246 
248  const T& value() const { return mValue; }
249 
261  explicit operator T() const { return mValue; }
262 
271  void setSerializedValue(const T& value) {
272  setValue(Derived::convertFromSerialized(value));
273  }
274 
283  T serializedValue() const { return Derived::convertToSerialized(mValue); }
284 
285 
286 public:
287 
289  T deg() const { return This()->toDeg(); }
290 
292  T rad() const { return This()->toRad();}
293 
294 public:
295  // operators
296 
297  // note the generic operators take Derived& as first argument, while
298  // the operators, where T& is a parameter take AngleBase& as argument.
299  // this is necessary to resolve the ISO C++ ambiguity with type conversation
300 
302  template <typename OtherUnitTag, typename OtherDerived>
303  friend Derived operator+(const Derived& a, const AngleBase<T,OtherUnitTag,OtherDerived>& b) {
304  return Derived( a.mValue + conv(b) );
305  }
307  friend Derived operator+(const AngleBase& a, const T& b) {
308  return Derived( a.mValue + b);
309  }
311  friend Derived operator+(const T& a, const AngleBase& b) {
312  return Derived( a + b.mValue);
313  }
314 
316  template <typename OtherUnitTag, typename OtherDerived>
317  friend Derived operator-(const Derived& a,const AngleBase<T,OtherUnitTag,OtherDerived>& b) {
318  return Derived( a.mValue - conv(b) );
319  }
321  friend Derived operator-(const AngleBase& a, const T& b) {
322  return Derived( a.mValue - b);
323  }
325  friend Derived operator-(const T& a, const AngleBase& b) {
326  return Derived( a - b.mValue);
327  }
328 
330  Derived operator-() const {
331  return Derived(-mValue);
332  }
333 
335  friend Derived operator*(const Derived& a, const T& b) {
336  return Derived( a.mValue * b);
337  }
339  friend Derived operator*(const T& a, const Derived& b) {
340  return Derived( a * b.mValue);
341  }
342 
344  friend Derived operator/(const Derived& a, const T& b) {
345  return Derived( a.mValue / b);
346  }
347 
348 
350  template <typename OtherUnitTag, typename OtherDerived>
352  setValue(mValue+conv(a));
353  return *This();
354  }
356  Derived& operator+=(const T& a) {
357  setValue(mValue+a);
358  return *This();
359  }
360 
362  template <typename OtherUnitTag, typename OtherDerived>
364  setValue(mValue-conv(a));
365  return *This();
366  }
368  Derived& operator-=(const T& a) {
369  setValue(mValue-a);
370  return *This();
371  }
372 
374  Derived& operator*=(const T& s) {
375  setValue(mValue*s);
376  return *This();
377  }
378 
380  Derived& operator/=(const T& s) {
381  setValue(mValue/s);
382  return *This();
383  }
384 
385 
386  friend bool operator<(const AngleBase& a, const AngleBase& b) { return a.mValue < b.mValue; }
387  friend bool operator<=(const AngleBase& a, const AngleBase& b) { return a.mValue <= b.mValue; }
388  friend bool operator>(const AngleBase& a, const AngleBase& b) { return a.mValue > b.mValue; }
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 
393 
394 public:
395 
402  T smallestDifferenceValue(const Derived& other) const
403  {
404  T d = mValue - other.mValue;
405 
406  static const T halfTurn = Derived::turn() / 2;
407  if(d > halfTurn)
408  d -= Derived::turn();
409  else if(d <= -halfTurn)
410  d += Derived::turn();
411 
412  return d;
413  }
414 
419  bool isInInterval(const Derived& min, const Derived& max) const
420  {
421  if (min.mValue <= max.mValue)
422  return mValue >= min.mValue && mValue <= max.mValue;
423  return mValue >= min.mValue || mValue <= max.mValue;
424  }
425 
426 public:
427 
429  friend std::ostream& operator<<(std::ostream& o, const AngleBase& v ) {
430  o << v.value() << " " << UnitTag::unit();
431  return o;
432  }
433 
434 public:
435 
440  static const char* unit() {
441  return UnitTag::unit();
442  }
443 
444 private:
445 
447  template <typename OtherT, typename OtherUnitTag, typename OtherDerived>
448  static T conv(const AngleBase<OtherT,OtherUnitTag,OtherDerived>& other) {
450  return Private::AngleConverter<type,OtherUnitTag,UnitTag>::convert(other.value());
451  }
452 
453 
455  Derived* This() { return static_cast<Derived*>(this); }
456 
458  const Derived* This() const { return static_cast<const Derived*>(this); }
459 
460 protected:
461 
464 };
465 
466 
467 #define MIRA_ANGLE_CONSTRUCTORS_AND_ASSIGNOPS(Type) \
468 protected: \
469  Type(const T& value, int) : Base(value,1) {} \
470 public: \
471  Type() {} \
472  explicit Type(T value) : Base(value) {} \
473  template <typename OtherT, typename OtherUnitTag, typename OtherDerived> \
474  Type(const AngleBase<OtherT,OtherUnitTag,OtherDerived>& other) : Base(other) {} \
475  template <typename OtherUnitTag, typename OtherDerived> \
476  Type& operator=(const AngleBase<T,OtherUnitTag,OtherDerived>& other) { \
477  Base::operator=(other); \
478  return *this; } \
479  Type& operator=(const T& other) { \
480  Base::operator=(other); \
481  return *this; }
482 
483 
485 
489 template <typename T, typename Derived>
490 class DegreeBase : public AngleBase<T, Private::DegreeUnitTag, Derived>
491 {
492  friend class AngleBase<T, Private::DegreeUnitTag, Derived>;
493  typedef AngleBase<T, Private::DegreeUnitTag, Derived> Base;
494 public:
496 
497 public:
499  static T turn() { return (T)360; }
500 
502  static T convertToSerialized(T value) { return value; }
503 
505  static T convertFromSerialized(T value) { return value; }
506 
507 private:
509  T toDeg() const { return this->mValue; }
510 
512  T toRad() const { return deg2rad(this->mValue); }
513 };
514 
518 template <typename T, typename Derived>
519 class RadianBase : public AngleBase<T, Private::RadianUnitTag, Derived>
520 {
521  static_assert(std::is_floating_point<T>::value,
522  "Radians make sense with floating point types only. "
523  "Use Degree if you want to represent angles with integral types");
524 
525  friend class AngleBase<T, Private::RadianUnitTag, Derived>;
526  typedef AngleBase<T, Private::RadianUnitTag, Derived> Base;
527 
528 public:
530 
531 public:
533  static T turn() { return two_pi<T>(); }
534 
536  static T convertToSerialized(T value) { return value; }
537 
539  static T convertFromSerialized(T value) { return value; }
540 
541 private:
543  T toDeg() const { return rad2deg(this->mValue); }
544 
546  T toRad() const { return this->mValue; }
547 
548 };
549 
551 
552 // forward decl
553 template <typename T>
554 class Degree;
555 
566 template <typename T>
567 class SignedDegree : public DegreeBase<T, SignedDegree<T>>
568 {
570  friend class Degree<T>;
571 public:
573 
574 
579  static T lower() { return static_cast<T>(-180); }
580 
586  return SignedDegree<T>(this->smallestDifferenceValue(other), 1);
587  }
588 };
589 
590 template <typename T, typename SerializerTag>
591 class IsTransparentSerializable<SignedDegree<T>,SerializerTag> : public std::true_type {};
592 
593 
604 template <typename T>
605 class Degree : public DegreeBase<T, Degree<T>>
606 {
607  typedef DegreeBase<T, Degree<T>> Base;
608 public:
610 
611 
616  static T lower() { return static_cast<T>(0); }
617 
623  return SignedDegree<T>(this->smallestDifferenceValue(other), 1);
624  }
625 };
626 
627 template <typename T, typename SerializerTag>
628 class IsTransparentSerializable<Degree<T>,SerializerTag> : public std::true_type {};
629 
631 
632 // forward decl
633 template <typename T>
634 class Radian;
635 
646 template <typename T>
647 class SignedRadian : public RadianBase<T, SignedRadian<T>>
648 {
650  friend class Radian<T>;
651 public:
653 
654 
659  static T lower() { return -pi<T>(); }
660 
666  return SignedRadian<T>(this->smallestDifferenceValue(other), 1);
667  }
668 };
669 
670 template <typename T, typename SerializerTag>
671 class IsTransparentSerializable<SignedRadian<T>,SerializerTag> : public std::true_type {};
672 
683 template <typename T>
684 class Radian : public RadianBase<T, Radian<T>>
685 {
686  typedef RadianBase<T, Radian<T>> Base;
687 public:
689 
690 
695  static T lower() { return static_cast<T>(0); }
696 
702  return SignedRadian<T>(this->smallestDifferenceValue(other), 1);
703  }
704 };
705 
706 template <typename T, typename SerializerTag>
707 class IsTransparentSerializable<Radian<T>,SerializerTag> : public std::true_type {};
708 
710 
711 // forward decl
712 template <typename T>
713 class Angle;
714 
728 template <typename T>
729 class SignedAngle : public RadianBase<T, SignedAngle<T>>
730 {
732  friend class Angle<T>;
733 public:
735 
736  template <typename Reflector>
737  void reflect(Reflector& r) {
738  r.delegate(getter<T>(convertToSerialized, this->mValue),
739  setter<T>(convertFromSerialized, this->mValue));
740  }
741 
747  static T lower() { return -pi<T>(); }
748 
754  return SignedAngle<T>(this->smallestDifferenceValue(other), 1);
755  }
756 
757 
759  MIRA_DEPRECATED("use Radian<T>(value)", static SignedAngle fromRad(T value)) {
760  return SignedAngle(Radian<T>(value));
761  }
763  MIRA_DEPRECATED("use Degree<T>(value)", static SignedAngle fromDeg(T value)) {
764  return SignedAngle(Degree<T>(value));
765  }
766 
767 public:
768  // overwite convertXYZSerialized since Angle uses different internal and serialized representation.
770  static T convertToSerialized(T value) { return rad2deg<T>(value); }
771 
773  static T convertFromSerialized(T value) { return deg2rad<T>(value); }
774 };
775 
776 template <typename T, typename SerializerTag>
777 class IsTransparentSerializable<SignedAngle<T>,SerializerTag> : public std::true_type {};
778 
779 
793 template <typename T>
794 class Angle : public RadianBase<T, Angle<T>>
795 {
796  typedef RadianBase<T, Angle<T>> Base;
797 public:
799 
800  template <typename Reflector>
801  void reflect(Reflector& r) {
802  r.delegate(getter<T>(convertToSerialized, this->mValue),
803  setter<T>(convertFromSerialized, this->mValue));
804  }
805 
811  static T lower() { return static_cast<T>(0); }
812 
818  return SignedAngle<T>(this->smallestDifferenceValue(other), 1);
819  }
820 
822  MIRA_DEPRECATED("use Radian<T>(value)", static Angle fromRad(T value)) {
823  return Angle(Radian<T>(value));
824  }
826  MIRA_DEPRECATED("use Degree<T>(value)", static Angle fromDeg(T value)) {
827  return Angle(Degree<T>(value));
828  }
829 
830 public:
831  // overwite convertXYZSerialized since Angle uses different internal and serialized representation.
833  static T convertToSerialized(T value) { return rad2deg<T>(value); }
834 
836  static T convertFromSerialized(T value) { return deg2rad<T>(value); }
837 };
838 
839 template <typename T, typename SerializerTag>
840 class IsTransparentSerializable<Angle<T>,SerializerTag> : public std::true_type {};
841 
842 
844 
857 
866 
875 
877 
878 template <>
879 class IsCheapToCopy<SignedDegreei> : public std::true_type {};
880 
881 template <>
882 class IsCheapToCopy<SignedDegreef> : public std::true_type {};
883 
884 template <>
885 class IsCheapToCopy<SignedDegreed> : public std::true_type {};
886 
887 template <>
888 class IsCheapToCopy<Degreei> : public std::true_type {};
889 
890 template <>
891 class IsCheapToCopy<Degreef> : public std::true_type {};
892 
893 template <>
894 class IsCheapToCopy<Degreed> : public std::true_type {};
895 
896 template <>
897 class IsCheapToCopy<SignedRadianf> : public std::true_type {};
898 
899 template <>
900 class IsCheapToCopy<SignedRadiand> : public std::true_type {};
901 
902 template <>
903 class IsCheapToCopy<Radianf> : public std::true_type {};
904 
905 template <>
906 class IsCheapToCopy<Radiand> : public std::true_type {};
907 
908 template <>
909 class IsCheapToCopy<SignedAnglef> : public std::true_type {};
910 
911 template <>
912 class IsCheapToCopy<SignedAngled> : public std::true_type {};
913 
914 template <>
915 class IsCheapToCopy<Anglef> : public std::true_type {};
916 
917 template <>
918 class IsCheapToCopy<Angled> : public std::true_type {};
919 
921 
927 template<typename T>
928 inline T smallestAngleDifference(const T& a, const T& b)
929 {
930  return SignedAngle<T>(a).smallestDifference(SignedAngle<T>(b)).value();
931 }
932 
934 template<typename T>
935 inline bool inAngleInterval(T value, T min, T max)
936 {
937  return SignedAngle<T>(value).isInInterval(SignedAngle<T>(min),
938  SignedAngle<T>(max));
939 }
940 
942 template<typename T>
943 inline bool isInAngleInterval(T value, T min, T max)
944 {
945  return SignedAngle<T>(value).isInInterval(SignedAngle<T>(min),
946  SignedAngle<T>(max));
947 }
949 
964 template <typename T>
965 Getter<T> rad2degGetter(const T& cref)
966 {
967  return getter<T>([&]{return rad2deg<T>(cref);});
968 }
969 
974 struct Deg2RadNonNegativeType { explicit Deg2RadNonNegativeType() = default; };
975 
981 
983 template <typename T>
985 {
986  return setter<T>([&ref](const T& in){ ref = deg2rad<T>(in);});
987 }
988 
1002 template <typename T>
1004 {
1005  // we should throw an exception in error case here as we cannot emit a
1006  // message including the name of the member/property at this place
1007  // --> exception allows to catch on a higher level to add/show more information
1008  return setter<T>([&ref](const T& in){
1009  if (in < 0) {
1010  MIRA_THROW(XInvalidParameter,
1011  "deg2radSetter: input value must be non-negative.");
1012  }
1013  ref = deg2rad<T>(in);
1014  });
1015 }
1016 
1027 template <typename T>
1029  return makeAccessor(rad2degGetter(ref), deg2radSetter(ref));
1030 }
1031 
1043 template <typename T>
1046 }
1047 
1049 
1050 }
1051 
1053 
1054 // specialization of std::abs for all Angle types
1055 namespace std {
1056 template <typename T, typename UnitTag, typename Derived>
1057 inline Derived abs(const mira::AngleBase<T,UnitTag,Derived>& other) {
1058  return Derived(std::abs(other.value()));
1059 }
1060 }
1061 
1063 
1064 #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:822
SignedAngle< double > SignedAngled
Double precision signed angle.
Definition: Angle.h:870
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:505
Base class for angle classes that represent angles using radians.
Definition: Angle.h:519
friend bool operator<=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:387
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:317
Radian< float > Radianf
Float precision angle.
Definition: Angle.h:863
Derived operator-=(const AngleBase< T, OtherUnitTag, OtherDerived > &a)
Subtract other angle from this angle.
Definition: Angle.h:363
Includes often needed math headers and methods and provides additional constants. ...
Degree< double > Degreed
Double precision angle.
Definition: Angle.h:856
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:622
Derived & operator*=(const T &s)
Multiply this angle with scalar.
Definition: Angle.h:374
static const char * unit()
Returns the unit of this angle representation as string, e.g.
Definition: Angle.h:440
friend Derived operator/(const Derived &a, const T &b)
Divide by scalar.
Definition: Angle.h:344
void reflect(Reflector &r)
Definition: Angle.h:801
Getter< T > rad2degGetter(const T &cref)
Create a getter for serializing radians as degrees.
Definition: Angle.h:965
Derived & operator-=(const T &a)
Subtract float value from this angle.
Definition: Angle.h:368
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:763
MIRA_DEPRECATED("use Degree<T>(value)", static Angle fromDeg(T value))
deprecated, use Degree<T>(value) instead
Definition: Angle.h:826
Degree< int > Degreei
Integer precision angle.
Definition: Angle.h:852
friend bool operator<(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:386
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:770
STL namespace.
Signed angle that is represented using degrees.
Definition: Angle.h:567
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:490
A tag type used as parameter type in deg2radSetter, signalling that negative values are not permitted...
Definition: Angle.h:974
AngleBase()
Definition: Angle.h:190
SignedRadian< double > SignedRadiand
Double precision signed angle.
Definition: Angle.h:861
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:811
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:536
const T & value() const
Returns the raw angle value given in the native unit of the angle class.
Definition: Angle.h:248
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:753
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:665
Setter< T > deg2radSetter(T &ref)
Create setter for deserializing radians from degrees. See rad2degGetter.
Definition: Angle.h:984
Derived & operator/=(const T &s)
Divide this angle by scalar.
Definition: Angle.h:380
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:773
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:271
SignedDegree< double > SignedDegreed
Double precision signed angle.
Definition: Angle.h:850
static T convertToSerialized(T value)
Converts own representation to serialized representation.
Definition: Angle.h:502
SignedAngle< float > SignedAnglef
Float precision signed angle.
Definition: Angle.h:868
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:463
Degree< float > Degreef
Float precision angle.
Definition: Angle.h:854
friend Derived operator-(const T &a, const AngleBase &b)
Subtract two angles.
Definition: Angle.h:325
Derived & operator+=(const T &a)
Add float value to this angle.
Definition: Angle.h:356
Unsigned angle that is represented using degrees.
Definition: Angle.h:554
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:980
Signed angle that is represented using radians.
Definition: Angle.h:647
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:701
friend std::ostream & operator<<(std::ostream &o, const AngleBase &v)
stream operator
Definition: Angle.h:429
friend Derived operator+(const Derived &a, const AngleBase< T, OtherUnitTag, OtherDerived > &b)
Add two angles.
Definition: Angle.h:303
friend Derived operator+(const T &a, const AngleBase &b)
Add two angles.
Definition: Angle.h:311
bool inAngleInterval(T value, T min, T max)
Definition: Angle.h:935
Derived abs(const mira::AngleBase< T, UnitTag, Derived > &other)
Definition: Angle.h:1057
friend Derived operator*(const T &a, const Derived &b)
Multiply with scalar.
Definition: Angle.h:339
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:289
Derived operator+=(const AngleBase< T, OtherUnitTag, OtherDerived > &a)
Add other angle to this angle.
Definition: Angle.h:351
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:292
Angle< double > Angled
Double precision angle.
Definition: Angle.h:874
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:928
Unsigned angle that is represented using radians.
Definition: Angle.h:634
SignedDegree< int > SignedDegreei
Integer precision signed angle.
Definition: Angle.h:846
void reflect(Reflector &r)
Definition: Angle.h:214
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:833
T serializedValue() const
Returns the value in the unit that is used for serialization.
Definition: Angle.h:283
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:1028
MIRA_DEPRECATED("use Radian<T>(value)", static SignedAngle fromRad(T value))
deprecated, use Radian<T>(value) instead
Definition: Angle.h:759
friend Derived operator*(const Derived &a, const T &b)
Multiply with scalar.
Definition: Angle.h:335
void reflect(Reflector &r)
Definition: Angle.h:737
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:467
Signed angle that is represented using radians.
Definition: Angle.h:729
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:419
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:836
static T convertFromSerialized(T value)
Converts serialized representation to own representation.
Definition: Angle.h:539
friend Derived operator-(const AngleBase &a, const T &b)
Subtract two angles.
Definition: Angle.h:321
Derived operator-() const
Unary minus operator.
Definition: Angle.h:330
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:585
SignedDegree< float > SignedDegreef
Float precision signed angle.
Definition: Angle.h:848
friend Derived operator+(const AngleBase &a, const T &b)
Add two angles.
Definition: Angle.h:307
friend bool operator==(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:390
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:817
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:402
SignedRadian< float > SignedRadianf
Float precision signed angle.
Definition: Angle.h:859
static T lower()
Returns the lower limit of the defined angle interval.
Definition: Angle.h:747
Unsigned angle that is represented using radians.
Definition: Angle.h:713
Angle< float > Anglef
Float precision angle.
Definition: Angle.h:872
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:943
friend bool operator>(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:388
Platform dependent defines and macros.
friend bool operator!=(const AngleBase &a, const AngleBase &b)
Definition: Angle.h:391
Radian< double > Radiand
Double precision angle.
Definition: Angle.h:865