KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
Angle.hpp
[詳解]
1#pragma once
2
3#include "KisaragiMath.hpp"
4#include "../RangeNum.hpp"
5#include "../utility.hpp"
6
7namespace Kisaragi_Lib
8{
9 template <typename Num>
10 class Radian;
11
12 template <typename Num>
13 class Degree;
14
15 /// <summary>
16 /// 精度レベル(度数法)
17 /// </summary>
18 /// <typeparam name="Num">使用する小数点型</typeparam>
19 template<typename Num,
20 std::enable_if_t<std::is_floating_point<Num>::value,int> = 0>
22 {
23 public:
24 inline constexpr static Num E_LOOSE = 1e-3;
25 inline constexpr static Num E_NORMAL = 1e-6;
26 inline constexpr static Num E_STRICT = 1e-9;
27 inline constexpr static Num E_VERYSTRICT = 1e-12;
28 };
29
30 /// <summary>
31 /// 精度レベル(ラジアン)
32 /// </summary>
33 /// <typeparam name="Num">使用する小数点型</typeparam>
34 template<typename Num,
35 std::enable_if_t<std::is_floating_point<Num>::value, int> = 0>
37 {
38 public:
39 inline constexpr static Num E_LOOSE = 1e-3 * PI / DEGREES_HALF;
40 inline constexpr static Num E_NORMAL = 1e-6 * PI / DEGREES_HALF;
41 inline constexpr static Num E_STRICT = 1e-9 * PI / DEGREES_HALF;
42 inline constexpr static Num E_VERYSTRICT = 1e-12 * PI / DEGREES_HALF;
43 };
44
45
46
47 /// <summary>
48 /// 度数法の値型
49 /// </summary>
50 /// <typeparam name="Num">角度の値型</typeparam>
51 template<typename Num>
52 class Degree
53 {
54 static_assert(std::is_floating_point<Num>::value, "Degreeに小数点型で無い型が渡されました");
55
56 private:
58
59
60 public:
61
62 /// <summary>
63 /// 比較の際に許す誤差の範囲
64 /// </summary>
66
71
72 Degree(Num _num)
73 {
74 angle = _num;
76 }
77
78 /********************************************************
79 *
80 * operator
81 *
82 ********************************************************/
83
84 template<typename T>
86 {
87 angle += _add;
88
89 return *this;
90 }
91
92 Radian<Num> ToRadian() const;
93
94 operator Num () const
95 {
96 return angle;
97 }
98
99 /********************************************************
100 *
101 * 比較演算子
102 *
103 ********************************************************/
104
105
106 bool operator==(const Degree<Num>& _degree) const
107 {
108 return this->EpsilonIf(_degree,epsilon);
109 }
110
111 bool operator==(const Radian<Num>& _radian) const
112 {
113 return this->EpsilonIf(_radian, epsilon);
114 }
115
116 bool operator==(const Num& _angle) const
117 {
118 return this->EpsilonIf(_angle, epsilon);
119 }
120
121
122 /// <summary>
123 /// 差が許容範囲内か調べる
124 /// </summary>
125 /// <param name="_degree">度数法の角度</param>
126 /// <param name="_epsilon">許容範囲</param>
127 /// <returns>許容範囲か否か</returns>
128 bool EpsilonIf(const Degree<Num>& _degree, const Num& _epsilon) const
129 {
130 return Kisaragi_Lib::EpsilonIf((Num)angle, (Num)_degree.angle, (Num)_epsilon);
131 }
132
133 /// <summary>
134 /// 差が許容範囲内か調べる
135 /// </summary>
136 /// <param name="_degree">弧度法の角度</param>
137 /// <param name="_epsilon">許容範囲</param>
138 /// <returns>許容範囲か否か</returns>
139 bool EpsilonIf(const Radian<Num>& _radian, const Num& _epsilon) const
140 {
141 return Kisaragi_Lib::EpsilonIf((Num)angle, (Num)_radian.ToDegree(), (Num)_epsilon);
142 }
143
144 /// <summary>
145 /// 差が許容範囲内か調べる
146 /// </summary>
147 /// <param name="_degree">度数法の角度</param>
148 /// <param name="_epsilon">許容範囲</param>
149 /// <returns>許容範囲か否か</returns>
150 bool EpsilonIf(const Num& _angle, const Num& _epsilon) const
151 {
152 return Kisaragi_Lib::EpsilonIf((Num)angle, (Num)_angle, (Num)_epsilon);
153 }
154
155
156 };
157
158 /// <summary>
159 /// 弧度法
160 /// </summary>
161 /// <typeparam name="Num"></typeparam>
162 template<typename Num>
163 class Radian
164 {
165 static_assert(std::is_floating_point<Num>::value, "Degreeに小数点型で無い型が渡されました");
166
167 private:
169
170 public:
171
172 /// <summary>
173 /// 比較の際に許す誤差の範囲
174 /// </summary>
176
181
182 /// <summary>
183 /// コンストラクタ
184 /// </summary>
185 /// <param name="_num">ラジアン値</param>
186 Radian(Num _num)
187 {
188 angle = _num;
190 }
191
192 /// <summary>
193 /// 0~360度の度数法に変換したものを返します
194 /// </summary>
195 /// <returns>度数法に変換した値</returns>
196 Degree<Num> ToDegree() const;
197
198 template<typename T>
200 {
201 angle += _add;
202
203 return *this;
204 }
205
206 operator Num () const
207 {
208 return angle;
209 }
210
211 /********************************************************
212 *
213 * 比較演算子
214 *
215 ********************************************************/
216
217 bool operator==(const Degree<Num>& _degree) const
218 {
219 return EpsilonIf(_degree, epsilon);
220 }
221
222 bool operator==(const Radian<Num>& _radian) const
223 {
224 return EpsilonIf(_radian, epsilon);
225 }
226
227 bool operator==(const Num& _angle) const
228 {
229 return EpsilonIf(_angle, epsilon);
230 }
231
232 /// <summary>
233 /// 差が許容範囲内か調べる
234 /// </summary>
235 /// <param name="_degree">度数法の角度</param>
236 /// <param name="_epsilon">許容範囲</param>
237 /// <returns>許容範囲か否か</returns>
238 bool EpsilonIf(const Degree<Num>& _degree, const Num& _epsilon) const
239 {
240 return Kisaragi_Lib::EpsilonIf((Num)angle, (Num)_degree.ToRadian(), (Num)_epsilon);
241 }
242
243 /// <summary>
244 /// 差が許容範囲内か調べる
245 /// </summary>
246 /// <param name="_degree">弧度法の角度</param>
247 /// <param name="_epsilon">許容範囲</param>
248 /// <returns>許容範囲か否か</returns>
249 bool EpsilonIf(const Radian<Num>& _radian, const Num& _epsilon) const
250 {
251 return Kisaragi_Lib::EpsilonIf((Num)angle, (Num)_radian.angle, (Num)_epsilon);
252 }
253
254 /// <summary>
255 /// 差が許容範囲内か調べる
256 /// </summary>
257 /// <param name="_degree">弧度法の角度</param>
258 /// <param name="_epsilon">許容範囲</param>
259 /// <returns>許容範囲か否か</returns>
260 bool EpsilonIf(const Num& _angle, const Num& _epsilon) const
261 {
262 return Kisaragi_Lib::EpsilonIf((Num)angle, (Num)_angle, (Num)_epsilon);
263 }
264 };
265
266
267
268
269
270 template<typename Num>
272 {
273 return Radian<Num>{ (Num)angle * (Num)PI / (Num)DEGREES_HALF };
274 }
275
276 template<typename Num>
278 {
279 return Degree<Num>{ (Num)angle * (Num)DEGREES_HALF / (Num)PI };
280 }
281}
独自のMathを提供します
範囲指定の値型を提供します。
精度レベル(度数法)
Definition Angle.hpp:22
static constexpr Num E_VERYSTRICT
Definition Angle.hpp:27
static constexpr Num E_STRICT
Definition Angle.hpp:26
static constexpr Num E_LOOSE
Definition Angle.hpp:24
static constexpr Num E_NORMAL
Definition Angle.hpp:25
精度レベル(ラジアン)
Definition Angle.hpp:37
static constexpr Num E_STRICT
Definition Angle.hpp:41
static constexpr Num E_NORMAL
Definition Angle.hpp:40
static constexpr Num E_LOOSE
Definition Angle.hpp:39
static constexpr Num E_VERYSTRICT
Definition Angle.hpp:42
度数法の値型
Definition Angle.hpp:53
bool operator==(const Degree< Num > &_degree) const
Definition Angle.hpp:106
Degree(Num _num)
Definition Angle.hpp:72
bool operator==(const Radian< Num > &_radian) const
Definition Angle.hpp:111
bool operator==(const Num &_angle) const
Definition Angle.hpp:116
bool EpsilonIf(const Num &_angle, const Num &_epsilon) const
差が許容範囲内か調べる
Definition Angle.hpp:150
RangeNum< Num, LoopOutOfRange > angle
Definition Angle.hpp:57
Radian< Num > ToRadian() const
Definition Angle.hpp:271
bool EpsilonIf(const Radian< Num > &_radian, const Num &_epsilon) const
差が許容範囲内か調べる
Definition Angle.hpp:139
Degree< Num > & operator+=(T _add)
Definition Angle.hpp:85
Degree()
Definition Angle.hpp:67
RangeNum< Num, LoopOutOfRange > epsilon
比較の際に許す誤差の範囲
Definition Angle.hpp:65
bool EpsilonIf(const Degree< Num > &_degree, const Num &_epsilon) const
差が許容範囲内か調べる
Definition Angle.hpp:128
弧度法
Definition Angle.hpp:164
Radian(Num _num)
コンストラクタ
Definition Angle.hpp:186
RangeNum< Num, LoopOutOfRange > angle
Definition Angle.hpp:168
bool operator==(const Num &_angle) const
Definition Angle.hpp:227
Radian< Num > & operator+=(T _add)
Definition Angle.hpp:199
Radian()
Definition Angle.hpp:177
bool EpsilonIf(const Num &_angle, const Num &_epsilon) const
差が許容範囲内か調べる
Definition Angle.hpp:260
bool operator==(const Degree< Num > &_degree) const
Definition Angle.hpp:217
bool operator==(const Radian< Num > &_radian) const
Definition Angle.hpp:222
bool EpsilonIf(const Radian< Num > &_radian, const Num &_epsilon) const
差が許容範囲内か調べる
Definition Angle.hpp:249
bool EpsilonIf(const Degree< Num > &_degree, const Num &_epsilon) const
差が許容範囲内か調べる
Definition Angle.hpp:238
Degree< Num > ToDegree() const
0~360度の度数法に変換したものを返します
Definition Angle.hpp:277
RangeNum< Num, LoopOutOfRange > epsilon
比較の際に許す誤差の範囲
Definition Angle.hpp:175
特定範囲の値を管理するための数値型
Definition RangeNum.hpp:123
Definition Accessor.hpp:110
static const double TWO_PI
Definition KisaragiMath.hpp:25
static const double PI
Definition KisaragiMath.hpp:20
static const double DEGREES_HALF
Definition KisaragiMath.hpp:30
static bool EpsilonIf(T _val01, T _val02, T _epsilon)
_valの差が_許容範囲内か調べる
Definition utility.hpp:44
纏めるのが思いつかなかった汎用関数