Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Angle.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Common.h"
7
8namespace Stroika::Foundation::Math {
9
10 /*
11 ********************************************************************************
12 *********************************** Math::Angle ********************************
13 ********************************************************************************
14 */
15 inline constexpr Angle::Angle ()
16 : fAngleInRadians_{0}
17 {
18 }
19 inline constexpr Angle::Angle (RepType angle, AngleFormat angleFormat)
20 : fAngleInRadians_{(angleFormat == AngleFormat::eRadians)
21 ? angle
22 : ((angleFormat == AngleFormat::eDegrees) ? (angle * (2 * numbers::pi_v<RepType>) / 360.0)
23 : (angle * (2 * numbers::pi_v<RepType>) / 400.0))}
24 {
25 using namespace Common;
26 Require (ToInt (AngleFormat::eSTART) <= ToInt (angleFormat) and ToInt (angleFormat) < ToInt (AngleFormat::eEND));
27 }
28 inline constexpr Angle::RepType Angle::AsRadians () const
29 {
30 return fAngleInRadians_;
31 }
32 inline constexpr Angle::RepType Angle::AsDegrees () const
33 {
34 return fAngleInRadians_ * 360.0 / (2 * numbers::pi_v<RepType>);
35 }
36 inline constexpr Angle::RepType Angle::AsGradians () const
37 {
38 return fAngleInRadians_ * 400.0 / (2 * numbers::pi_v<RepType>);
39 }
40 inline const Angle& Angle::operator+= (const Angle& rhs)
41 {
42 fAngleInRadians_ += rhs.AsRadians ();
43 return *this;
44 }
45 inline const Angle& Angle::operator-= (const Angle& rhs)
46 {
47 fAngleInRadians_ -= rhs.AsRadians ();
48 return *this;
49 }
50 inline const Angle& Angle::operator*= (RepType rhs)
51 {
52 fAngleInRadians_ *= rhs;
53 return *this;
54 }
55 inline const Angle& Angle::operator/= (RepType rhs)
56 {
57 fAngleInRadians_ /= rhs;
58 return *this;
59 }
60
61 /*
62 ********************************************************************************
63 ************************* Math::Angle operators ********************************
64 ********************************************************************************
65 */
66 constexpr Angle operator+ (const Angle& lhs, const Angle& rhs)
67 {
68 return Angle{lhs.AsRadians () + rhs.AsRadians (), Angle::eRadians};
69 }
70 constexpr Angle operator- (const Angle& lhs, const Angle& rhs)
71 {
72 return Angle{lhs.AsRadians () - rhs.AsRadians (), Angle::eRadians};
73 }
74 constexpr Angle operator* (const Angle& lhs, Angle::RepType rhs)
75 {
76 return Angle{lhs.AsRadians () * rhs, Angle::eRadians};
77 }
78 constexpr Angle operator/ (const Angle& lhs, Angle::RepType rhs)
79 {
80 return Angle{lhs.AsRadians () / rhs, Angle::eRadians};
81 }
82 constexpr Angle operator* (double lhs, const Angle& rhs)
83 {
84 return Angle{lhs * rhs.AsRadians (), Angle::eRadians};
85 }
86 constexpr Angle operator* (const Angle& lhs, const Angle& rhs)
87 {
88 return Angle{lhs.AsRadians () * rhs.AsRadians (), Angle::eRadians};
89 }
90
91 /*
92 ********************************************************************************
93 ****************************** Math::Literals **********************************
94 ********************************************************************************
95 */
96 inline namespace Literals {
97 constexpr Angle operator""_deg (long double n) noexcept
98 {
99 return Angle{static_cast<Angle::RepType> (n), Angle::eDegrees};
100 }
101 constexpr Angle operator""_deg (unsigned long long int n) noexcept
102 {
103 return Angle{static_cast<Angle::RepType> (n), Angle::eDegrees};
104 }
105 constexpr Angle operator""_rad (long double n) noexcept
106 {
107 return Angle{static_cast<Angle::RepType> (n), Angle::eRadians};
108 }
109 constexpr Angle operator""_rad (unsigned long long int n) noexcept
110 {
111 return Angle{static_cast<Angle::RepType> (n), Angle::eRadians};
112 }
113 }
114
115 /*
116 ********************************************************************************
117 *********************************** Math::Min **********************************
118 ********************************************************************************
119 */
120 constexpr Angle Min (const Angle& a1, const Angle& a2)
121 {
122 return (a1 < a2) ? a1 : a2;
123 }
124
125 /*
126 ********************************************************************************
127 *********************************** Math::Max **********************************
128 ********************************************************************************
129 */
130 constexpr Angle Max (const Angle& a1, const Angle& a2)
131 {
132 return (a1 > a2) ? a1 : a2;
133 }
134
135}