Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Angle.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Math_Angle_h_
5#define _Stroika_Foundation_Math_Angle_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <compare>
10
11#include "Stroika/Foundation/Common/Common.h"
14
15/**
16 * \file
17 *
18 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
19 */
20
21namespace Stroika::Foundation::Math {
22
23 /**
24 * \todo Consider if this class should automatically normalize (0..2pi) or at least have a normalize method.
25 */
26 class Angle {
27 public:
28 using RepType = double;
29
30 public:
31 enum class AngleFormat : uint8_t {
32 eRadians,
33 eDegrees,
34 eGradians,
35
36 Stroika_Define_Enum_Bounds (eRadians, eGradians)
37 };
38
39 public:
40 static constexpr AngleFormat eRadians = AngleFormat::eRadians;
41 static constexpr AngleFormat eDegrees = AngleFormat::eDegrees;
42 static constexpr AngleFormat eGradians = AngleFormat::eGradians;
43
44 public:
45 /**
46 */
47 constexpr Angle ();
48 constexpr Angle (RepType angle, AngleFormat angleFormat);
49
50 public:
51 /**
52 */
53 nonvirtual constexpr RepType AsRadians () const;
54
55 public:
56 /**
57 */
58 nonvirtual constexpr RepType AsDegrees () const;
59
60 public:
61 /**
62 */
63 nonvirtual constexpr RepType AsGradians () const;
64
65 public:
66 /**
67 *
68 * \note <a href="Design-Overview.md#Comparisons">Comparisons</a>:
69 * o static_assert (totally_ordered<Angle>);
70 * o partial_ordering because floating point admits only partial ordering.
71 *
72 */
73 nonvirtual partial_ordering operator<=> (const Angle& rhs) const = default;
74
75 public:
76 nonvirtual const Angle& operator+= (const Angle& rhs);
77 nonvirtual const Angle& operator-= (const Angle& rhs);
78 nonvirtual const Angle& operator*= (RepType rhs);
79 nonvirtual const Angle& operator/= (RepType rhs);
80
81 private:
82 double fAngleInRadians_;
83 };
84 static_assert (totally_ordered<Angle>);
85
86 /**
87 */
88 constexpr Angle operator+ (const Angle& lhs, const Angle& rhs);
89
90 /**
91 */
92 constexpr Angle operator- (const Angle& lhs, const Angle& rhs);
93
94 /**
95 */
96 constexpr Angle operator* (double lhs, const Angle& rhs);
97 constexpr Angle operator* (const Angle& lhs, Angle::RepType rhs);
98 constexpr Angle operator* (const Angle& lhs, Angle& rhs);
99
100 /**
101 */
102 constexpr Angle operator/ (const Angle& lhs, Angle::RepType rhs);
103
104 inline namespace Literals {
105 /**
106 */
107 constexpr Angle operator"" _deg (long double n) noexcept;
108 constexpr Angle operator"" _deg (unsigned long long int n) noexcept;
109
110 /**
111 */
112 constexpr Angle operator"" _rad (long double n) noexcept;
113 constexpr Angle operator"" _rad (unsigned long long int n) noexcept;
114 }
115
116 /**
117 */
118 constexpr Angle Min (const Angle& a1, const Angle& a2);
119
120 /**
121 */
122 constexpr Angle Max (const Angle& a1, const Angle& a2);
123
124}
125
126/*
127 ********************************************************************************
128 ***************************** Implementation Details ***************************
129 ********************************************************************************
130 */
131#include "Angle.inl"
132
133#endif /*_Stroika_Foundation_Math_Angle_h_*/
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
nonvirtual partial_ordering operator<=>(const Angle &rhs) const =default