Plasma Engine  2.0
Loading...
Searching...
No Matches
Angle_inl.h
1#pragma once
2
3template <typename Type>
4constexpr PL_ALWAYS_INLINE Type plAngle::Pi()
5{
6 return static_cast<Type>(3.1415926535897932384626433832795);
7}
8
9template <typename Type>
10constexpr PL_ALWAYS_INLINE Type plAngle::DegToRadMultiplier()
11{
12 return Pi<Type>() / (Type)180;
13}
14
15template <typename Type>
16constexpr PL_ALWAYS_INLINE Type plAngle::RadToDegMultiplier()
17{
18 return ((Type)180) / Pi<Type>();
19}
20
21template <typename Type>
22constexpr Type plAngle::DegToRad(Type f)
23{
24 return f * DegToRadMultiplier<Type>();
25}
26
27template <typename Type>
28constexpr Type plAngle::RadToDeg(Type f)
29{
30 return f * RadToDegMultiplier<Type>();
31}
32
33constexpr inline plAngle plAngle::MakeFromDegree(float fDegree)
34{
35 return plAngle(DegToRad(fDegree));
36}
37
38constexpr PL_ALWAYS_INLINE plAngle plAngle::MakeFromRadian(float fRadian)
39{
40 return plAngle(fRadian);
41}
42
43constexpr inline float plAngle::GetDegree() const
44{
45 return RadToDeg(m_fRadian);
46}
47
48constexpr PL_ALWAYS_INLINE float plAngle::GetRadian() const
49{
50 return m_fRadian;
51}
52
54{
55 plAngle out(m_fRadian);
56 out.NormalizeRange();
57 return out;
58}
59
60inline bool plAngle::IsEqualSimple(plAngle rhs, plAngle epsilon) const
61{
62 const plAngle diff = AngleBetween(*this, rhs);
63
64 return ((diff.m_fRadian >= -epsilon.m_fRadian) && (diff.m_fRadian <= epsilon.m_fRadian));
65}
66
67inline bool plAngle::IsEqualNormalized(plAngle rhs, plAngle epsilon) const
68{
69 // equality between normalized angles
70 const plAngle aNorm = GetNormalizedRange();
71 const plAngle bNorm = rhs.GetNormalizedRange();
72
73 return aNorm.IsEqualSimple(bNorm, epsilon);
74}
75
76constexpr PL_ALWAYS_INLINE plAngle plAngle::operator-() const
77{
78 return plAngle(-m_fRadian);
79}
80
81PL_ALWAYS_INLINE void plAngle::operator+=(plAngle r)
82{
83 m_fRadian += r.m_fRadian;
84}
85
86PL_ALWAYS_INLINE void plAngle::operator-=(plAngle r)
87{
88 m_fRadian -= r.m_fRadian;
89}
90
91constexpr inline plAngle plAngle::operator+(plAngle r) const
92{
93 return plAngle(m_fRadian + r.m_fRadian);
94}
95
96constexpr inline plAngle plAngle::operator-(plAngle r) const
97{
98 return plAngle(m_fRadian - r.m_fRadian);
99}
100
101constexpr PL_ALWAYS_INLINE bool plAngle::operator==(const plAngle& r) const
102{
103 return m_fRadian == r.m_fRadian;
104}
105
106constexpr PL_ALWAYS_INLINE bool plAngle::operator!=(const plAngle& r) const
107{
108 return m_fRadian != r.m_fRadian;
109}
110
111constexpr PL_ALWAYS_INLINE bool plAngle::operator<(const plAngle& r) const
112{
113 return m_fRadian < r.m_fRadian;
114}
115
116constexpr PL_ALWAYS_INLINE bool plAngle::operator>(const plAngle& r) const
117{
118 return m_fRadian > r.m_fRadian;
119}
120
121constexpr PL_ALWAYS_INLINE bool plAngle::operator<=(const plAngle& r) const
122{
123 return m_fRadian <= r.m_fRadian;
124}
125
126constexpr PL_ALWAYS_INLINE bool plAngle::operator>=(const plAngle& r) const
127{
128 return m_fRadian >= r.m_fRadian;
129}
130
131constexpr inline plAngle operator*(plAngle a, float f)
132{
133 return plAngle::MakeFromRadian(a.GetRadian() * f);
134}
135
136constexpr inline plAngle operator*(float f, plAngle a)
137{
138 return plAngle::MakeFromRadian(a.GetRadian() * f);
139}
140
141constexpr inline plAngle operator/(plAngle a, float f)
142{
143 return plAngle::MakeFromRadian(a.GetRadian() / f);
144}
145
146constexpr inline float operator/(plAngle a, plAngle b)
147{
148 return a.GetRadian() / b.GetRadian();
149}
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
constexpr float GetDegree() const
Returns the degree value. (Performs a conversion)
Definition Angle_inl.h:43
constexpr plAngle()
Standard constructor, initializing with 0.
Definition Angle.h:40
plAngle GetNormalizedRange() const
Returns an equivalent angle with range between 0 degree - 360 degree.
Definition Angle_inl.h:53
bool IsEqualSimple(plAngle rhs, plAngle epsilon) const
Equality check with epsilon. Simple check without normalization. 360 degree will equal 0 degree,...
Definition Angle_inl.h:60
bool IsEqualNormalized(plAngle rhs, plAngle epsilon) const
Equality check with epsilon that uses normalized angles. Will recognize 720 degree == 0 degree.
Definition Angle_inl.h:67
static constexpr Type RadToDeg(Type f)
Converts an angle in radians to degree.
Definition Angle_inl.h:28
static constexpr plAngle MakeFromDegree(float fDegree)
Creates an instance of plAngle that was initialized from degree. (Performs a conversion)
Definition Angle_inl.h:33
void NormalizeRange()
Brings the angle into the range of 0 degree - 360 degree.
Definition Math.cpp:226
static constexpr plAngle MakeFromRadian(float fRadian)
Creates an instance of plAngle that was initialized from radian. (No need for any conversion)
Definition Angle_inl.h:38
static constexpr Type DegToRad(Type f)
Converts an angle in degree to radians.
Definition Angle_inl.h:22
static constexpr PL_ALWAYS_INLINE Type DegToRadMultiplier()
Returns the constant to multiply with an angle in degree to convert it to radians.
Definition Angle_inl.h:10
constexpr float GetRadian() const
Returns the radian value. (No need for any conversion)
Definition Angle_inl.h:48
static constexpr PL_ALWAYS_INLINE Type RadToDegMultiplier()
Returns the constant to multiply with an angle in degree to convert it to radians.
Definition Angle_inl.h:16
static constexpr plAngle AngleBetween(plAngle a, plAngle b)
Computes the smallest angle between the two given angles. The angle will always be a positive value.
Definition Math_inl.h:456