FluxSand 1.0
FluxSand - Interactive Digital Hourglass
Loading...
Searching...
No Matches
Type::CycleValue Class Reference

A class to represent and manipulate cyclic values (e.g., angles). More...

#include <comp_type.hpp>

Public Member Functions

CycleValueoperator= (const CycleValue &)=default
 Default copy assignment operator.
 
 CycleValue (const float &value)
 Constructs a CycleValue object from a float.
 
 CycleValue (const double &value)
 Constructs a CycleValue object from a double.
 
 CycleValue (const CycleValue &value)
 Copy constructor. Ensures the copied value remains within [0, 2π).
 
 CycleValue ()
 Default constructor. Initializes the value to 0.
 
CycleValue operator+ (const float &value)
 Adds a float value and returns the resulting CycleValue.
 
CycleValue operator+ (const double &value)
 Adds a double value and returns the resulting CycleValue.
 
CycleValue operator+ (const CycleValue &value)
 Adds another CycleValue and returns the result.
 
CycleValue operator+= (const float &value)
 In-place addition of a float value.
 
CycleValue operator+= (const double &value)
 In-place addition of a double value.
 
CycleValue operator+= (const CycleValue &value)
 In-place addition of another CycleValue.
 
float operator- (const float &raw_value)
 Computes the difference between this value and a float value.
 
float operator- (const double &raw_value)
 Computes the difference between this value and a double value.
 
float operator- (const CycleValue &value)
 Computes the difference between this value and another CycleValue.
 
CycleValue operator- ()
 Negates the current value.
 
 operator float ()
 Implicit conversion to float.
 
CycleValueoperator= (const float &value)
 Assigns a float value.
 
CycleValueoperator= (const double &value)
 Assigns a double value.
 
float Value ()
 Returns the current value.
 

Static Public Member Functions

static float Calculate (float value)
 Normalizes a value to the range [0, 2π).
 

Private Attributes

float value_
 

Detailed Description

A class to represent and manipulate cyclic values (e.g., angles).

This class ensures that values remain within a cyclic range, such as [0, 2π), and provides arithmetic operations while preserving this property.

Definition at line 13 of file comp_type.hpp.

Constructor & Destructor Documentation

◆ CycleValue() [1/4]

Type::CycleValue::CycleValue ( const float &  value)
inline

Constructs a CycleValue object from a float.

Parameters
valueThe input value.

Definition at line 39 of file comp_type.hpp.

39: value_(Calculate(value)) {}
static float Calculate(float value)
Normalizes a value to the range [0, 2π).
Definition comp_type.hpp:26

◆ CycleValue() [2/4]

Type::CycleValue::CycleValue ( const double &  value)
inline

Constructs a CycleValue object from a double.

Parameters
valueThe input value.

Definition at line 46 of file comp_type.hpp.

47 : value_(Calculate(static_cast<float>(value))) {}

◆ CycleValue() [3/4]

Type::CycleValue::CycleValue ( const CycleValue value)
inline

Copy constructor. Ensures the copied value remains within [0, 2π).

Parameters
valueAnother CycleValue object.

Definition at line 54 of file comp_type.hpp.

54 : value_(value.value_) {
55 while (value_ >= M_2PI) {
56 value_ -= M_2PI;
57 }
58
59 while (value_ < 0) {
60 value_ += M_2PI;
61 }
62 }

◆ CycleValue() [4/4]

Type::CycleValue::CycleValue ( )
inline

Default constructor. Initializes the value to 0.

Definition at line 67 of file comp_type.hpp.

67: value_(0.0f) {}

Member Function Documentation

◆ Calculate()

static float Type::CycleValue::Calculate ( float  value)
inlinestatic

Normalizes a value to the range [0, 2π).

Parameters
valueThe input value (in radians).
Returns
The normalized value within [0, 2π).

Definition at line 26 of file comp_type.hpp.

26 {
27 value = std::fmodf(value, M_2PI);
28 if (value < 0) {
29 value += M_2PI;
30 }
31 return value;
32 }

◆ operator float()

Type::CycleValue::operator float ( )
inline

Implicit conversion to float.

Returns
The normalized value as a float.

Definition at line 203 of file comp_type.hpp.

203{ return this->value_; }

◆ operator+() [1/3]

CycleValue Type::CycleValue::operator+ ( const CycleValue value)
inline

Adds another CycleValue and returns the result.

Parameters
valueAnother CycleValue object.
Returns
A new CycleValue object.

Definition at line 95 of file comp_type.hpp.

95 {
96 return CycleValue(value.value_ + value_);
97 }
CycleValue()
Default constructor. Initializes the value to 0.
Definition comp_type.hpp:67

◆ operator+() [2/3]

CycleValue Type::CycleValue::operator+ ( const double &  value)
inline

Adds a double value and returns the resulting CycleValue.

Parameters
valueThe value to add.
Returns
A new CycleValue object.

Definition at line 85 of file comp_type.hpp.

85 {
86 return CycleValue(static_cast<float>(value) + value_);
87 }

◆ operator+() [3/3]

CycleValue Type::CycleValue::operator+ ( const float &  value)
inline

Adds a float value and returns the resulting CycleValue.

Parameters
valueThe value to add.
Returns
A new CycleValue object.

Definition at line 75 of file comp_type.hpp.

75 {
76 return CycleValue(value + value_);
77 }

◆ operator+=() [1/3]

CycleValue Type::CycleValue::operator+= ( const CycleValue value)
inline

In-place addition of another CycleValue.

Parameters
valueAnother CycleValue object.
Returns
A reference to this object.

Definition at line 127 of file comp_type.hpp.

127 {
128 value_ = Calculate(value.value_ + value_);
129 return *this;
130 }

◆ operator+=() [2/3]

CycleValue Type::CycleValue::operator+= ( const double &  value)
inline

In-place addition of a double value.

Parameters
valueThe value to add.
Returns
A reference to this object.

Definition at line 116 of file comp_type.hpp.

116 {
117 value_ = Calculate(static_cast<float>(value) + value_);
118 return *this;
119 }

◆ operator+=() [3/3]

CycleValue Type::CycleValue::operator+= ( const float &  value)
inline

In-place addition of a float value.

Parameters
valueThe value to add.
Returns
A reference to this object.

Definition at line 105 of file comp_type.hpp.

105 {
106 value_ = Calculate(value + value_);
107 return *this;
108 }

◆ operator-() [1/4]

CycleValue Type::CycleValue::operator- ( )
inline

Negates the current value.

Returns
A new CycleValue object.

Definition at line 196 of file comp_type.hpp.

196{ return CycleValue(M_2PI - value_); }

◆ operator-() [2/4]

float Type::CycleValue::operator- ( const CycleValue value)
inline

Computes the difference between this value and another CycleValue.

Parameters
valueAnother CycleValue object.
Returns
The difference normalized to [-π, π).

Definition at line 178 of file comp_type.hpp.

178 {
179 float ans = value_ - value.value_;
180 while (ans >= M_PI) {
181 ans -= M_2PI;
182 }
183
184 while (ans < -M_PI) {
185 ans += M_2PI;
186 }
187
188 return ans;
189 }

◆ operator-() [3/4]

float Type::CycleValue::operator- ( const double &  raw_value)
inline

Computes the difference between this value and a double value.

Parameters
raw_valueThe value to subtract.
Returns
The difference normalized to [-π, π).

Definition at line 158 of file comp_type.hpp.

158 {
159 float value = Calculate(static_cast<float>(raw_value));
160 float ans = value_ - value;
161 while (ans >= M_PI) {
162 ans -= M_2PI;
163 }
164
165 while (ans < -M_PI) {
166 ans += M_2PI;
167 }
168
169 return ans;
170 }

◆ operator-() [4/4]

float Type::CycleValue::operator- ( const float &  raw_value)
inline

Computes the difference between this value and a float value.

Parameters
raw_valueThe value to subtract.
Returns
The difference normalized to [-π, π).

Definition at line 138 of file comp_type.hpp.

138 {
139 float value = Calculate(raw_value);
140 float ans = value_ - value;
141 while (ans >= M_PI) {
142 ans -= M_2PI;
143 }
144
145 while (ans < -M_PI) {
146 ans += M_2PI;
147 }
148
149 return ans;
150 }

◆ operator=() [1/2]

CycleValue & Type::CycleValue::operator= ( const double &  value)
inline

Assigns a double value.

Parameters
valueThe value to assign.
Returns
A reference to this object.

Definition at line 222 of file comp_type.hpp.

222 {
223 value_ = Calculate(static_cast<float>(value));
224 return *this;
225 }

◆ operator=() [2/2]

CycleValue & Type::CycleValue::operator= ( const float &  value)
inline

Assigns a float value.

Parameters
valueThe value to assign.
Returns
A reference to this object.

Definition at line 211 of file comp_type.hpp.

211 {
212 value_ = Calculate(value);
213 return *this;
214 }

◆ Value()

float Type::CycleValue::Value ( )
inline

Returns the current value.

Returns
The value as a float.

Definition at line 232 of file comp_type.hpp.

232{ return value_; }

Field Documentation

◆ value_

float Type::CycleValue::value_
private

Definition at line 235 of file comp_type.hpp.


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