libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
cycle_value.hpp
1#pragma once
2
3#include <cmath>
4
5#include "libxr_def.hpp"
6
7namespace LibXR
8{
9
10using DefaultScalar = LIBXR_DEFAULT_SCALAR;
11
25template <typename Scalar = DefaultScalar>
27{
28 public:
39 CycleValue &operator=(const CycleValue &) = default;
40
51 {
52 value = std::fmod(value, M_2PI);
53 if (value < 0)
54 {
55 value += M_2PI;
56 }
57 return value;
58 }
59
68
77 {
78 while (value_ >= M_2PI)
79 {
80 value_ -= M_2PI;
81 }
82
83 while (value_ < 0)
84 {
85 value_ += M_2PI;
86 }
87 }
88
93 CycleValue() : value_(0.0f) {}
94
105
107 {
108 return CycleValue(value.value_ + value_);
109 }
110
121 {
123 return *this;
124 }
125
127 {
129 while (ans >= M_2PI)
130 {
131 ans -= M_2PI;
132 }
133
134 while (ans < 0)
135 {
136 ans += M_2PI;
137 }
138
139 value_ = ans;
140 return *this;
141 }
142
154 {
157 while (ans >= M_PI)
158 {
159 ans -= M_2PI;
160 }
161
162 while (ans < -M_PI)
163 {
164 ans += M_2PI;
165 }
166
167 return ans;
168 }
169
171 {
173 while (ans >= M_PI)
174 {
175 ans -= M_2PI;
176 }
177
178 while (ans < -M_PI)
179 {
180 ans += M_2PI;
181 }
182
183 return ans;
184 }
185
196 {
198 return *this;
199 }
200
202 {
204 while (ans >= M_2PI)
205 {
206 ans -= M_2PI;
207 }
208
209 while (ans < 0)
210 {
211 ans += M_2PI;
212 }
213
214 value_ = ans;
215 return *this;
216 }
217
225 CycleValue operator-() { return CycleValue(M_2PI - value_); }
226
234 operator Scalar() { return this->value_; }
235
246 {
248 return *this;
249 }
250
258 Scalar Value() { return value_; }
259
260 private:
262};
263
264} // namespace LibXR
角度循环处理类,用于处理周期性角度计算。 A cyclic angle handling class for periodic angle calculations.
Scalar Value()
获取当前的角度值。 Retrieves the current angle value.
static Scalar Calculate(Scalar value)
计算角度值并归一化到 0 到 2π 之间。 Computes and normalizes the angle value within the range of 0 to 2π.
CycleValue operator-=(const Scalar &value)
复合减法运算符重载。 Overloaded compound subtraction operator.
CycleValue & operator=(const CycleValue &)=default
赋值运算符重载。 Overloaded assignment operator.
CycleValue & operator=(const Scalar &value)
赋值运算符重载,更新角度值并归一化。 Overloaded assignment operator, updating and normalizing the angle value.
Scalar operator-(const Scalar &raw_value)
减法运算符重载,计算角度差值并归一化到 -π 到 π 之间。 Overloaded subtraction operator, computing the angle difference and no...
Scalar value_
存储的角度值。 The stored angle value.
CycleValue operator+=(const Scalar &value)
复合加法运算符重载。 Overloaded compound addition operator.
CycleValue operator+(const Scalar &value)
加法运算符重载。 Overloaded addition operator.
CycleValue(const CycleValue &value)
拷贝构造函数,确保角度值在合法范围内。 Copy constructor ensuring the angle value remains within valid limits.
CycleValue operator-()
取反运算符重载,将角度转换到 2π - value_。 Overloaded negation operator, converting the angle to 2π - value_.
CycleValue(const Scalar &value)
使用给定值初始化 CycleValue。 Initializes CycleValue with a given value.
CycleValue()
默认构造函数,初始化为 0。 Default constructor initializing the angle to 0.
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值