libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::CycleValue< Scalar > Class Template Reference

角度循环处理类,用于处理周期性角度计算。 A cyclic angle handling class for periodic angle calculations. More...

#include <cycle_value.hpp>

Public Member Functions

CycleValueoperator= (const CycleValue &)=default
 赋值运算符重载。 Overloaded assignment operator.
 
 CycleValue (const Scalar &value)
 使用给定值初始化 CycleValue。 Initializes CycleValue with a given value.
 
 CycleValue (const CycleValue &value)
 拷贝构造函数,确保角度值在合法范围内。 Copy constructor ensuring the angle value remains within valid limits.
 
 CycleValue ()
 默认构造函数,初始化为 0。 Default constructor initializing the angle to 0.
 
CycleValue operator+ (const Scalar &value)
 加法运算符重载。 Overloaded addition operator.
 
CycleValue operator+ (const CycleValue &value)
 
CycleValue operator+= (const Scalar &value)
 复合加法运算符重载。 Overloaded compound addition operator.
 
CycleValue operator+= (const CycleValue &value)
 
Scalar operator- (const Scalar &raw_value)
 减法运算符重载,计算角度差值并归一化到 π 之间。 Overloaded subtraction operator, computing the angle difference and normalizing it to to π.
 
Scalar operator- (const CycleValue &value)
 
CycleValue operator-= (const Scalar &value)
 复合减法运算符重载。 Overloaded compound subtraction operator.
 
CycleValue operator-= (const CycleValue &value)
 
CycleValue operator- ()
 取反运算符重载,将角度转换到 2π - value_。 Overloaded negation operator, converting the angle to 2π - value_.
 
 operator Scalar ()
 类型转换操作符,将 CycleValue 转换为 Scalar。 Type conversion operator to convert CycleValue to Scalar.
 
CycleValueoperator= (const Scalar &value)
 赋值运算符重载,更新角度值并归一化。 Overloaded assignment operator, updating and normalizing the angle value.
 
Scalar Value ()
 获取当前的角度值。 Retrieves the current angle value.
 

Static Public Member Functions

static Scalar Calculate (Scalar value)
 计算角度值并归一化到 0 到 2π 之间。 Computes and normalizes the angle value within the range of 0 to 2π.
 

Private Attributes

Scalar value_
 存储的角度值。 The stored angle value.
 

Detailed Description

template<typename Scalar = DefaultScalar>
class LibXR::CycleValue< Scalar >

角度循环处理类,用于处理周期性角度计算。 A cyclic angle handling class for periodic angle calculations.

该类用于处理 0 到 2π 之间的角度运算,确保角度始终保持在合法范围内, 并提供加减运算和类型转换功能。 This class handles angle calculations within the range of 0 to 2π, ensuring values stay within valid limits and supporting addition, subtraction, and type conversion operations.

Template Parameters
Scalar角度的存储类型,默认为 DefaultScalar。 The storage type for angles, default is DefaultScalar.

Definition at line 26 of file cycle_value.hpp.

Constructor & Destructor Documentation

◆ CycleValue() [1/3]

template<typename Scalar = DefaultScalar>
LibXR::CycleValue< Scalar >::CycleValue ( const Scalar value)
inline

使用给定值初始化 CycleValue。 Initializes CycleValue with a given value.

Parameters
value需要存储的角度值。 The angle value to be stored.

Definition at line 67 of file cycle_value.hpp.

static Scalar Calculate(Scalar value)
计算角度值并归一化到 0 到 2π 之间。 Computes and normalizes the angle value within the range of 0 to 2π.
Scalar value_
存储的角度值。 The stored angle value.
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

◆ CycleValue() [2/3]

template<typename Scalar = DefaultScalar>
LibXR::CycleValue< Scalar >::CycleValue ( const CycleValue< Scalar > &  value)
inline

拷贝构造函数,确保角度值在合法范围内。 Copy constructor ensuring the angle value remains within valid limits.

Parameters
value另一个 CycleValue 对象。 Another CycleValue object.

Definition at line 76 of file cycle_value.hpp.

76 : value_(value.value_)
77 {
78 while (value_ >= M_2PI)
79 {
80 value_ -= M_2PI;
81 }
82
83 while (value_ < 0)
84 {
85 value_ += M_2PI;
86 }
87 }

◆ CycleValue() [3/3]

template<typename Scalar = DefaultScalar>
LibXR::CycleValue< Scalar >::CycleValue ( )
inline

默认构造函数,初始化为 0。 Default constructor initializing the angle to 0.

Definition at line 93 of file cycle_value.hpp.

93: value_(0.0f) {}

Member Function Documentation

◆ Calculate()

template<typename Scalar = DefaultScalar>
static Scalar LibXR::CycleValue< Scalar >::Calculate ( Scalar  value)
inlinestatic

计算角度值并归一化到 0 到 2π 之间。 Computes and normalizes the angle value within the range of 0 to 2π.

Parameters
value输入角度值。 The input angle value.
Returns
归一化后的角度值。 The normalized angle value.

Definition at line 50 of file cycle_value.hpp.

51 {
52 value = std::fmod(value, M_2PI);
53 if (value < 0)
54 {
55 value += M_2PI;
56 }
57 return value;
58 }

◆ operator Scalar()

template<typename Scalar = DefaultScalar>
LibXR::CycleValue< Scalar >::operator Scalar ( )
inline

类型转换操作符,将 CycleValue 转换为 Scalar。 Type conversion operator to convert CycleValue to Scalar.

Returns
Scalar 形式返回角度值。 Returns the angle value as Scalar.

Definition at line 234 of file cycle_value.hpp.

234{ return this->value_; }

◆ operator+() [1/2]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator+ ( const CycleValue< Scalar > &  value)
inline

Definition at line 106 of file cycle_value.hpp.

107 {
108 return CycleValue(value.value_ + value_);
109 }
CycleValue()
默认构造函数,初始化为 0。 Default constructor initializing the angle to 0.

◆ operator+() [2/2]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator+ ( const Scalar value)
inline

加法运算符重载。 Overloaded addition operator.

Parameters
value需要加上的角度值。 The angle value to be added.
Returns
返回新的 CycleValue 对象。 Returns a new CycleValue object.

Definition at line 104 of file cycle_value.hpp.

104{ return CycleValue(value + value_); }

◆ operator+=() [1/2]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator+= ( const CycleValue< Scalar > &  value)
inline

Definition at line 126 of file cycle_value.hpp.

127 {
128 Scalar ans = value.value_ + value_;
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 }

◆ operator+=() [2/2]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator+= ( const Scalar value)
inline

复合加法运算符重载。 Overloaded compound addition operator.

Parameters
value需要加上的角度值。 The angle value to be added.
Returns
返回自身的引用。 Returns a reference to itself.

Definition at line 120 of file cycle_value.hpp.

121 {
123 return *this;
124 }

◆ operator-() [1/3]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator- ( )
inline

取反运算符重载,将角度转换到 2π - value_。 Overloaded negation operator, converting the angle to 2π - value_.

Returns
返回取反后的 CycleValue。 Returns the negated CycleValue.

Definition at line 225 of file cycle_value.hpp.

225{ return CycleValue(M_2PI - value_); }

◆ operator-() [2/3]

template<typename Scalar = DefaultScalar>
Scalar LibXR::CycleValue< Scalar >::operator- ( const CycleValue< Scalar > &  value)
inline

Definition at line 170 of file cycle_value.hpp.

171 {
172 Scalar ans = value_ - value.value_;
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 }

◆ operator-() [3/3]

template<typename Scalar = DefaultScalar>
Scalar LibXR::CycleValue< Scalar >::operator- ( const Scalar raw_value)
inline

减法运算符重载,计算角度差值并归一化到 π 之间。 Overloaded subtraction operator, computing the angle difference and normalizing it to to π.

Parameters
raw_value需要减去的角度值。 The angle value to be subtracted.
Returns
归一化后的角度差值。 The normalized angle difference.

Definition at line 153 of file cycle_value.hpp.

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 }

◆ operator-=() [1/2]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator-= ( const CycleValue< Scalar > &  value)
inline

Definition at line 201 of file cycle_value.hpp.

202 {
203 Scalar ans = value_ - value.value_;
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 }

◆ operator-=() [2/2]

template<typename Scalar = DefaultScalar>
CycleValue LibXR::CycleValue< Scalar >::operator-= ( const Scalar value)
inline

复合减法运算符重载。 Overloaded compound subtraction operator.

Parameters
value需要减去的角度值。 The angle value to be subtracted.
Returns
返回自身的引用。 Returns a reference to itself.

Definition at line 195 of file cycle_value.hpp.

196 {
198 return *this;
199 }

◆ operator=() [1/2]

template<typename Scalar = DefaultScalar>
CycleValue & LibXR::CycleValue< Scalar >::operator= ( const CycleValue< Scalar > &  )
default

赋值运算符重载。 Overloaded assignment operator.

赋值运算符默认使用编译器生成的实现。 The assignment operator uses the default compiler-generated implementation.

Returns
返回赋值后的 CycleValue 对象。 Returns the assigned CycleValue object.

◆ operator=() [2/2]

template<typename Scalar = DefaultScalar>
CycleValue & LibXR::CycleValue< Scalar >::operator= ( const Scalar value)
inline

赋值运算符重载,更新角度值并归一化。 Overloaded assignment operator, updating and normalizing the angle value.

Parameters
value需要赋值的新角度值。 The new angle value to be assigned.
Returns
返回自身的引用。 Returns a reference to itself.

Definition at line 245 of file cycle_value.hpp.

246 {
248 return *this;
249 }

◆ Value()

template<typename Scalar = DefaultScalar>
Scalar LibXR::CycleValue< Scalar >::Value ( )
inline

获取当前的角度值。 Retrieves the current angle value.

Returns
角度值。 The angle value.

Definition at line 258 of file cycle_value.hpp.

258{ return value_; }

Field Documentation

◆ value_

template<typename Scalar = DefaultScalar>
Scalar LibXR::CycleValue< Scalar >::value_
private

存储的角度值。 The stored angle value.

Definition at line 261 of file cycle_value.hpp.


The documentation for this class was generated from the following file: