Move Vectormath main
C++20 game and graphics mathematics
Loading...
Searching...
No Matches
Angles.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
6
7namespace mv::math
8{
9 template <typename T>
10 requires std::is_floating_point_v<T>
11 class Radians
12 {
13 public:
14 constexpr explicit Radians(T value) noexcept : Value_(value)
15 {
16 }
17
18 [[nodiscard]] constexpr T Value() const noexcept
19 {
20 return Value_;
21 }
22
23 [[nodiscard]] friend constexpr bool operator==(
24 Radians, Radians) noexcept = default;
25
26 private:
27 T Value_;
28 };
29
30 template <typename T>
31 requires std::is_floating_point_v<T>
32 class Degrees
33 {
34 public:
35 constexpr explicit Degrees(T value) noexcept : Value_(value)
36 {
37 }
38
39 [[nodiscard]] constexpr T Value() const noexcept
40 {
41 return Value_;
42 }
43
44 [[nodiscard]] friend constexpr bool operator==(
45 Degrees, Degrees) noexcept = default;
46
47 private:
48 T Value_;
49 };
50
55
56 template <typename T>
57 [[nodiscard]] constexpr Radians<T> ToRadians(Degrees<T> value) noexcept
58 {
59 return Radians<T>(value.Value() * (Pi<T> / T(180)));
60 }
61
62 template <typename T>
64 {
65 return Degrees<T>(value.Value() * (T(180) / Pi<T>));
66 }
67
68 namespace literals
69 {
70 [[nodiscard]] constexpr Degreesf operator""_deg(
71 long double value) noexcept
72 {
73 return Degreesf(static_cast<float>(value));
74 }
75
76 [[nodiscard]] constexpr Degreesf operator""_deg(
77 unsigned long long value) noexcept
78 {
79 return Degreesf(static_cast<float>(value));
80 }
81
82 [[nodiscard]] constexpr Radiansf operator""_rad(
83 long double value) noexcept
84 {
85 return Radiansf(static_cast<float>(value));
86 }
87
88 [[nodiscard]] constexpr Radiansf operator""_rad(
89 unsigned long long value) noexcept
90 {
91 return Radiansf(static_cast<float>(value));
92 }
93 } // namespace literals
94} // namespace mv::math
95
96static_assert(sizeof(mv::math::Radiansf) == sizeof(float));
97static_assert(sizeof(mv::math::Degreesf) == sizeof(float));
98static_assert(std::is_trivially_copyable_v<mv::math::Radiansf>);
99static_assert(std::is_trivially_copyable_v<mv::math::Degreesf>);
friend constexpr bool operator==(Degrees, Degrees) noexcept=default
constexpr Degrees(T value) noexcept
Definition Angles.hpp:35
constexpr T Value() const noexcept
Definition Angles.hpp:39
constexpr Radians(T value) noexcept
Definition Angles.hpp:14
constexpr T Value() const noexcept
Definition Angles.hpp:18
friend constexpr bool operator==(Radians, Radians) noexcept=default
Radians< float > Radiansf
Definition Angles.hpp:51
constexpr Radians< T > ToRadians(Degrees< T > value) noexcept
Definition Angles.hpp:57
constexpr Degrees< T > ToDegrees(Radians< T > value) noexcept
Definition Angles.hpp:63
Degrees< float > Degreesf
Definition Angles.hpp:53