ZeusMath-Library  2.0.4
Angle.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Math Library
5  * Module : Angle
6  * Package : Zeus.ZeusMath.System
7  * Author : Martin Abbuehl
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef AngleH
33 #define AngleH
34 
35 #include <math.h>
38 #include <zeusbase/System/Float.h>
39 
40 
41 BEGIN_NAMESPACE_Zeus
42 
43 
44 /******************************************************************************/
51 /******************************************************************************/
53 {
54  public:
56  inline TAngle() { setRadians(0); }
57 
59  TAngle(const Float& fAngle, ESystem eSystem);
60 
62  inline TAngle(const TAngle& rAngle) { *this = rAngle; }
63 
65  inline TAngle(const IAngle& rAngle) { *this = rAngle; }
66 
68  virtual inline ~TAngle() { }
69 
70  // Methods of IAngle.
71  virtual inline Float MQUALIFIER getRadians() const { return m_fRadians; }
72  virtual inline Float MQUALIFIER getDegrees() const { return radiansToDegrees(getRadians()); }
73 
74  virtual inline void MQUALIFIER setRadians(const Float& fAngle) { m_fRadians = fAngle; }
75  virtual inline void MQUALIFIER setDegrees(const Float& fAngle) { setRadians(degreesToRadians(fAngle)); }
76 
77  virtual inline void MQUALIFIER assign(const IAngle& rAngle) { *this = rAngle; }
78 
79  virtual bool MQUALIFIER isEqual(const IAngle& rAngle,
80  bool bNormalizeToSingleCircle = false) const;
81 
82  virtual inline Float MQUALIFIER cos() const { return TFloat(getRadians()).cos(); }
83  virtual inline Float MQUALIFIER sin() const { return TFloat(getRadians()).sin(); }
84  virtual inline Float MQUALIFIER tan() const { return TFloat(getRadians()).tan(); }
85 
86  virtual void MQUALIFIER normalizeToInterval(const IAngle& rAngleMin,
87  const IAngle& rAngleMax,
88  bool bIncludeMin, bool bIncludeMax);
89 
90  virtual void MQUALIFIER normalizeToSingleCircle();
91 
93  inline const TAngle& operator=(const IAngle& rAngle) { setRadians(rAngle.getRadians()); return *this; }
94 
96  inline const TAngle& operator=(const TAngle& rAngle) { setRadians(rAngle.getRadians()); return *this; }
97 
98  //Mathematical operators
99  inline TAngle operator+ (const IAngle& rAngle) const { return TAngle(getRadians() + rAngle.getRadians(), etRadians); }
100  inline TAngle operator- (const IAngle& rAngle) const { return TAngle(getRadians() - rAngle.getRadians(), etRadians); }
101  inline const TAngle& operator+=(const IAngle& rAngle) { *this = *this + rAngle; return *this; }
102  inline const TAngle& operator-=(const IAngle& rAngle) { *this = *this - rAngle; return *this; }
103  inline TAngle operator* (const Float& rFloat) const { return TAngle(getRadians() * rFloat, etRadians); }
104  inline TAngle operator/ (const Float& rFloat) const { return *this * (Float(1) / rFloat); }
105 
106  //Compare operators
107  inline bool operator==(const IAngle& rAngle) const { return TFloat::equalsFloat(getRadians(), rAngle.getRadians()); }
108  inline bool operator!=(const IAngle& rAngle) const { return !(*this == rAngle); }
109 
110  inline bool operator< (const IAngle& rAngle) const { return (getRadians() < rAngle.getRadians()); }
111  inline bool operator<=(const IAngle& rAngle) const { return (getRadians() <= rAngle.getRadians()); }
112  inline bool operator> (const IAngle& rAngle) const { return (getRadians() > rAngle.getRadians()); }
113  inline bool operator>=(const IAngle& rAngle) const { return (getRadians() >= rAngle.getRadians()); }
114 
115  /**************************************************************************/
120  /**************************************************************************/
121  static inline Float radiansToDegrees(const Float& fAngle) { return fAngle * TConstants::RadiansToDegrees; }
122 
123  /**************************************************************************/
128  /**************************************************************************/
129  static inline Float degreesToRadians(const Float& fAngle) { return fAngle * TConstants::DegreesToRadians; }
130 
131  Float getValue(ESystem eSystem) const;
132 
133  private:
135  Float m_fRadians;
136 };
137 
138 //Global operators.
139 /******************************************************************************/
142 /******************************************************************************/
143 inline TAngle operator-(const IAngle& rAngle) { return TAngle(-rAngle.getRadians(), IAngle::etRadians); }
144 
145 /******************************************************************************/
148 /******************************************************************************/
149 inline TAngle operator+(const IAngle& rAngle) { return TAngle(rAngle); }
150 
151 
152 END_NAMESPACE_Zeus
153 
154 #endif
155 
TAngle operator-(const IAngle &rAngle)
Definition: Angle.h:143
Definition: Angle.h:52
virtual Float MQUALIFIER getDegrees() const
Definition: Angle.h:72
virtual void MQUALIFIER setRadians(const Float &fAngle)
Definition: Angle.h:74
virtual Float MQUALIFIER tan() const
Definition: Angle.h:84
bool operator>=(const IAngle &rAngle) const
Definition: Angle.h:113
virtual Float MQUALIFIER getRadians() const =0
bool operator==(const IAngle &rAngle) const
Definition: Angle.h:107
const TAngle & operator+=(const IAngle &rAngle)
Definition: Angle.h:101
virtual Float MQUALIFIER cos() const
Definition: Angle.h:82
virtual void MQUALIFIER assign(const IAngle &rAngle)
Definition: Angle.h:77
const TAngle & operator=(const TAngle &rAngle)
Assignment of class type object.
Definition: Angle.h:96
#define zeusmath_class
Definition: PlatformDefines.hpp:48
virtual Float MQUALIFIER sin() const
Definition: Angle.h:83
virtual Float MQUALIFIER getRadians() const
Definition: Angle.h:71
TAngle()
Default constructor.
Definition: Angle.h:56
TAngle operator+(const IAngle &rAngle)
Definition: Angle.h:149
static Float degreesToRadians(const Float &fAngle)
Definition: Angle.h:129
bool operator!=(const IAngle &rAngle) const
Definition: Angle.h:108
TAngle(const TAngle &rAngle)
Copy constructor: Constructor taking class type object.
Definition: Angle.h:62
const TAngle & operator-=(const IAngle &rAngle)
Definition: Angle.h:102
TVector2D operator*(const Float &f, const IVector2D &rVector)
Definition: Vector2D.h:693
ESystem
Definition: IAngle.hpp:53
virtual ~TAngle()
Virtual destructor.
Definition: Angle.h:68
virtual void MQUALIFIER setDegrees(const Float &fAngle)
Definition: Angle.h:75
Definition: IAngle.hpp:47
TAngle(const IAngle &rAngle)
Constructor taking interface type object.
Definition: Angle.h:65
static Float radiansToDegrees(const Float &fAngle)
Definition: Angle.h:121
bool operator<=(const IAngle &rAngle) const
Definition: Angle.h:111
const TAngle & operator=(const IAngle &rAngle)
Assignment of interface type object.
Definition: Angle.h:93


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Wed Sep 14 2016 06:45:50