Completed AngleOf documentation
This commit is contained in:
parent
5f58a2c69e
commit
58beb363ea
209
Angle.cpp
209
Angle.cpp
@ -25,36 +25,34 @@ float Angle::Normalize(float angle) {
|
||||
|
||||
template <typename T> AngleOf<T>::AngleOf() : value(0) {}
|
||||
|
||||
// template <typename T> AngleOf<T>::AngleOf(T angle) : value(angle) {}
|
||||
template <typename T> const AngleOf<T> AngleOf<T>::zero = AngleOf<T>();
|
||||
// template <typename T>
|
||||
// const AngleOf<T> AngleOf<T>::deg90 = AngleOf<T>::Degrees(90);
|
||||
// template <typename T>
|
||||
// const AngleOf<T> AngleOf<T>::deg180 = AngleOf<T>::Degrees(180);
|
||||
|
||||
//===== AngleSingle, AngleOf<float>
|
||||
|
||||
template <> AngleOf<float> AngleOf<float>::Degrees(float angle) {
|
||||
if (isfinite(angle)) {
|
||||
while (angle < -180)
|
||||
angle += 360;
|
||||
while (angle >= 180)
|
||||
angle -= 360;
|
||||
template <> AngleOf<float> AngleOf<float>::Degrees(float degrees) {
|
||||
if (isfinite(degrees)) {
|
||||
while (degrees < -180)
|
||||
degrees += 360;
|
||||
while (degrees >= 180)
|
||||
degrees -= 360;
|
||||
}
|
||||
|
||||
return AngleOf(angle);
|
||||
return Binary(degrees);
|
||||
}
|
||||
|
||||
template <> AngleOf<float> AngleOf<float>::Radians(float angle) {
|
||||
if (isfinite(angle)) {
|
||||
while (angle <= -pi)
|
||||
angle += 2 * pi;
|
||||
while (angle > pi)
|
||||
angle -= 2 * pi;
|
||||
template <> AngleOf<float> AngleOf<float>::Radians(float radians) {
|
||||
if (isfinite(radians)) {
|
||||
while (radians <= -pi)
|
||||
radians += 2 * pi;
|
||||
while (radians > pi)
|
||||
radians -= 2 * pi;
|
||||
}
|
||||
|
||||
return AngleOf(angle * Rad2Deg);
|
||||
}
|
||||
|
||||
template <typename T> AngleOf<T> AngleOf<T>::Binary(T x) {
|
||||
AngleOf<T> angle = AngleOf<T>();
|
||||
angle.value = x;
|
||||
return angle;
|
||||
return Binary(radians * Rad2Deg);
|
||||
}
|
||||
|
||||
template <> float AngleOf<float>::InDegrees() const { return this->value; }
|
||||
@ -65,19 +63,21 @@ template <> float AngleOf<float>::InRadians() const {
|
||||
|
||||
//===== Angle16, AngleOf<signed short>
|
||||
|
||||
template <> AngleOf<signed short> AngleOf<signed short>::Degrees(float angle) {
|
||||
template <>
|
||||
AngleOf<signed short> AngleOf<signed short>::Degrees(float degrees) {
|
||||
// map float [-180..180) to integer [-32768..32767]
|
||||
signed short value = (signed short)roundf(angle / 360.0F * 65536.0F);
|
||||
return AngleOf<signed short>(value);
|
||||
signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F);
|
||||
return Binary(value);
|
||||
}
|
||||
|
||||
template <> AngleOf<signed short> AngleOf<signed short>::Radians(float angle) {
|
||||
if (!isfinite(angle))
|
||||
return AngleOf<signed short>(0);
|
||||
template <>
|
||||
AngleOf<signed short> AngleOf<signed short>::Radians(float radians) {
|
||||
if (!isfinite(radians))
|
||||
return AngleOf<signed short>::zero;
|
||||
|
||||
// map float [-PI..PI) to integer [-32768..32767]
|
||||
signed short value = (signed short)roundf(angle / pi * 32768.0F);
|
||||
return AngleOf<signed short>(value);
|
||||
signed short value = (signed short)roundf(radians / pi * 32768.0F);
|
||||
return Binary(value);
|
||||
}
|
||||
|
||||
template <> float AngleOf<signed short>::InDegrees() const {
|
||||
@ -92,19 +92,19 @@ template <> float AngleOf<signed short>::InRadians() const {
|
||||
|
||||
//===== Angle8, AngleOf<signed char>
|
||||
|
||||
template <> AngleOf<signed char> AngleOf<signed char>::Degrees(float angle) {
|
||||
template <> AngleOf<signed char> AngleOf<signed char>::Degrees(float degrees) {
|
||||
// map float [-180..180) to integer [-128..127)
|
||||
signed char value = (signed char)roundf(angle / 360.0F * 256.0F);
|
||||
return AngleOf<signed char>(value);
|
||||
signed char value = (signed char)roundf(degrees / 360.0F * 256.0F);
|
||||
return Binary(value);
|
||||
}
|
||||
|
||||
template <> AngleOf<signed char> AngleOf<signed char>::Radians(float angle) {
|
||||
if (!isfinite(angle))
|
||||
return AngleOf<signed char>(0);
|
||||
template <> AngleOf<signed char> AngleOf<signed char>::Radians(float radians) {
|
||||
if (!isfinite(radians))
|
||||
return AngleOf<signed char>::zero;
|
||||
|
||||
// map float [-pi..pi) to integer [-128..127)
|
||||
signed char value = (signed char)roundf(angle / pi * 128.0f);
|
||||
return AngleOf<signed char>(value);
|
||||
signed char value = (signed char)roundf(radians / pi * 128.0f);
|
||||
return Binary(value);
|
||||
}
|
||||
|
||||
template <> float AngleOf<signed char>::InDegrees() const {
|
||||
@ -119,90 +119,109 @@ template <> float AngleOf<signed char>::InRadians() const {
|
||||
|
||||
//===== Generic
|
||||
|
||||
// template <typename T>
|
||||
// const AngleOf<T> AngleOf<T>::zero = AngleOf<T>();
|
||||
// template <typename T>
|
||||
// const AngleOf<T> AngleOf<T>::deg90 = AngleOf<T>::Degrees(90);
|
||||
// template <typename T>
|
||||
// const AngleOf<T> AngleOf<T>::deg180 = AngleOf<T>::Degrees(180);
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator==(const AngleOf<T> a) const {
|
||||
return this->value == a.value;
|
||||
template <typename T> AngleOf<T> AngleOf<T>::Binary(T rawValue) {
|
||||
AngleOf<T> angle = AngleOf<T>();
|
||||
angle.SetBinary(rawValue);
|
||||
return angle;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator>(AngleOf<T> a) const {
|
||||
return this->value > a.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator>=(AngleOf<T> a) const {
|
||||
return this->value >= a.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator<(AngleOf<T> a) const {
|
||||
return this->value < a.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator<=(AngleOf<T> a) const {
|
||||
return this->value <= a.value;
|
||||
template <typename T> T AngleOf<T>::GetBinary() const { return this->value; }
|
||||
template <typename T> void AngleOf<T>::SetBinary(T rawValue) {
|
||||
this->value = rawValue;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
signed int Passer::LinearAlgebra::AngleOf<T>::Sign(AngleOf<T> a) {
|
||||
if (a.value < 0)
|
||||
bool AngleOf<T>::operator==(const AngleOf<T> angle) const {
|
||||
return this->value == angle.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator>(AngleOf<T> angle) const {
|
||||
return this->value > angle.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator>=(AngleOf<T> angle) const {
|
||||
return this->value >= angle.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator<(AngleOf<T> angle) const {
|
||||
return this->value < angle.value;
|
||||
}
|
||||
|
||||
template <typename T> bool AngleOf<T>::operator<=(AngleOf<T> angle) const {
|
||||
return this->value <= angle.value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
signed int Passer::LinearAlgebra::AngleOf<T>::Sign(AngleOf<T> angle) {
|
||||
if (angle.value < 0)
|
||||
return -1;
|
||||
if (a.value > 0)
|
||||
if (angle.value > 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AngleOf<T> Passer::LinearAlgebra::AngleOf<T>::Abs(AngleOf<T> a) {
|
||||
if (Sign(a) < 0)
|
||||
return -a;
|
||||
AngleOf<T> Passer::LinearAlgebra::AngleOf<T>::Abs(AngleOf<T> angle) {
|
||||
if (Sign(angle) < 0)
|
||||
return -angle;
|
||||
else
|
||||
return a;
|
||||
return angle;
|
||||
}
|
||||
|
||||
template <typename T> AngleOf<T> AngleOf<T>::operator-() const {
|
||||
AngleOf<T> angle = AngleOf(-this->value);
|
||||
AngleOf<T> angle = Binary(-this->value);
|
||||
return angle;
|
||||
}
|
||||
|
||||
template <>
|
||||
AngleOf<float> AngleOf<float>::operator-(const AngleOf<float> &a) const {
|
||||
AngleOf<float> angle = AngleOf(this->value - a.value);
|
||||
angle = Normalize(angle);
|
||||
return angle;
|
||||
AngleOf<float> AngleOf<float>::operator-(const AngleOf<float> &angle) const {
|
||||
AngleOf<float> r = Binary(this->value - angle.value);
|
||||
r = Normalize(r);
|
||||
return r;
|
||||
}
|
||||
template <typename T>
|
||||
AngleOf<T> AngleOf<T>::operator-(const AngleOf<T> &a) const {
|
||||
AngleOf<T> angle = AngleOf(this->value - a.value);
|
||||
return angle;
|
||||
AngleOf<T> AngleOf<T>::operator-(const AngleOf<T> &angle) const {
|
||||
AngleOf<T> r = Binary(this->value - angle.value);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <>
|
||||
AngleOf<float> AngleOf<float>::operator+(const AngleOf<float> &a) const {
|
||||
AngleOf<float> angle = AngleOf(this->value + a.value);
|
||||
angle = Normalize(angle);
|
||||
return angle;
|
||||
AngleOf<float> AngleOf<float>::operator+(const AngleOf<float> &angle) const {
|
||||
AngleOf<float> r = Binary(this->value + angle.value);
|
||||
r = Normalize(r);
|
||||
return r;
|
||||
}
|
||||
template <typename T>
|
||||
AngleOf<T> AngleOf<T>::operator+(const AngleOf<T> &a) const {
|
||||
AngleOf<T> angle = AngleOf(this->value + a.value);
|
||||
return angle;
|
||||
AngleOf<T> AngleOf<T>::operator+(const AngleOf<T> &angle) const {
|
||||
AngleOf<T> r = Binary(this->value + angle.value);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <> AngleOf<float> AngleOf<float>::operator+=(const AngleOf<float> &a) {
|
||||
this->value += a.value;
|
||||
template <>
|
||||
AngleOf<float> AngleOf<float>::operator+=(const AngleOf<float> &angle) {
|
||||
this->value += angle.value;
|
||||
this->Normalize();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> AngleOf<T> AngleOf<T>::operator+=(const AngleOf<T> &a) {
|
||||
this->value += a.value;
|
||||
template <typename T>
|
||||
AngleOf<T> AngleOf<T>::operator+=(const AngleOf<T> &angle) {
|
||||
this->value += angle.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// This defintion is not matching the declaration in the header file somehow
|
||||
// template <typename T>
|
||||
// AngleOf<T> operator*(const AngleOf<T> &angle, float factor) {
|
||||
// return AngleOf::Degrees((float)angle.InDegrees() * factor);
|
||||
// }
|
||||
|
||||
// This defintion is not matching the declaration in the header file somehow
|
||||
// template <typename T>
|
||||
// AngleOf<T> operator*(float factor, const AngleOf<T> &angle) {
|
||||
// return AngleOf::Degrees((float)factor * angle.InDegrees());
|
||||
// }
|
||||
|
||||
template <typename T> void AngleOf<T>::Normalize() {
|
||||
float angleValue = this->InDegrees();
|
||||
if (!isfinite(angleValue))
|
||||
@ -246,14 +265,14 @@ AngleOf<T> AngleOf<T>::MoveTowards(AngleOf<T> fromAngle, AngleOf<T> toAngle,
|
||||
return fromAngle + d;
|
||||
}
|
||||
|
||||
template <typename T> float AngleOf<T>::Cos(AngleOf<T> a) {
|
||||
return cosf(a.InRadians());
|
||||
template <typename T> float AngleOf<T>::Cos(AngleOf<T> angle) {
|
||||
return cosf(angle.InRadians());
|
||||
}
|
||||
template <typename T> float AngleOf<T>::Sin(AngleOf<T> a) {
|
||||
return sinf(a.InRadians());
|
||||
template <typename T> float AngleOf<T>::Sin(AngleOf<T> angle) {
|
||||
return sinf(angle.InRadians());
|
||||
}
|
||||
template <typename T> float AngleOf<T>::Tan(AngleOf<T> a) {
|
||||
return tanf(a.InRadians());
|
||||
template <typename T> float AngleOf<T>::Tan(AngleOf<T> angle) {
|
||||
return tanf(angle.InRadians());
|
||||
}
|
||||
|
||||
template <typename T> AngleOf<T> AngleOf<T>::Acos(float f) {
|
||||
@ -267,8 +286,8 @@ template <typename T> AngleOf<T> AngleOf<T>::Atan(float f) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AngleOf<T> Passer::LinearAlgebra::AngleOf<T>::Atan2(float f1, float f2) {
|
||||
return AngleOf<T>::Radians(atan2f(f1, f2));
|
||||
AngleOf<T> Passer::LinearAlgebra::AngleOf<T>::Atan2(float y, float x) {
|
||||
return AngleOf<T>::Radians(atan2f(y, x));
|
||||
}
|
||||
|
||||
// template <>
|
||||
@ -353,4 +372,4 @@ AngleOf<T> AngleOf<T>::SineRuleAngle(float a, AngleOf<T> beta, float b) {
|
||||
|
||||
template class AngleOf<float>;
|
||||
template class AngleOf<signed char>;
|
||||
template class AngleOf<signed short>;
|
||||
template class AngleOf<signed short>;
|
188
Angle.h
188
Angle.h
@ -13,77 +13,205 @@ static float pi = 3.1415927410125732421875F;
|
||||
static float Rad2Deg = 360.0f / (pi * 2);
|
||||
static float Deg2Rad = (pi * 2) / 360.0f;
|
||||
|
||||
/// @brief An angle in various representations.
|
||||
/// @tparam T The internal type used for the representation of the angle.
|
||||
/// The angle is internally limited to <-180..180] degrees or <-PI...PI]
|
||||
/// radians. When an angle exceeds this range, it is normalized to a value
|
||||
/// within the range.
|
||||
template <typename T> class AngleOf {
|
||||
public:
|
||||
/// @brief Create a new angle with a zero value
|
||||
AngleOf<T>();
|
||||
|
||||
static AngleOf<T> Degrees(float f);
|
||||
static AngleOf<T> Radians(float f);
|
||||
static AngleOf<T> Binary(T x);
|
||||
|
||||
// const static AngleOf<T> zero;
|
||||
/// @brief An zero value angle
|
||||
const static AngleOf<T> zero;
|
||||
// const static AngleOf<T> deg90;
|
||||
// const static AngleOf<T> deg180;
|
||||
|
||||
/// @brief Creates an angle in degrees
|
||||
/// @param degrees the angle in degrees
|
||||
/// @return The angle value
|
||||
static AngleOf<T> Degrees(float degrees);
|
||||
/// @brief Short-hand Deg alias for the Degrees function
|
||||
constexpr static auto Deg = Degrees;
|
||||
/// @brief Creates an angle in radians
|
||||
/// @param radians the angle in radians
|
||||
/// @return The angle value
|
||||
static AngleOf<T> Radians(float radians);
|
||||
/// @brief Short-hand Rad alias for the Radians function
|
||||
constexpr static auto Rad = Radians;
|
||||
/// @brief Creates an angle from a raw value
|
||||
/// @param rawValue the raw value to use for the angle
|
||||
/// @return The the angle
|
||||
static AngleOf<T> Binary(T rawValue);
|
||||
|
||||
/// @brief Get the angle value in degrees
|
||||
/// @return The angle value in degrees
|
||||
float InDegrees() const;
|
||||
/// @brief Get the angle value in radians
|
||||
/// @return The angle value in radians
|
||||
float InRadians() const;
|
||||
|
||||
inline T GetBinary() const { return this->value; }
|
||||
inline void SetBinary(T x) { this->value = x; }
|
||||
/// @brief Get the raw value for the angle
|
||||
/// @return The raw value
|
||||
T GetBinary() const;
|
||||
/// @brief Set the raw value of the angle
|
||||
/// @param rawValue The raw value
|
||||
void SetBinary(T rawValue);
|
||||
|
||||
bool operator==(const AngleOf<T> a) const;
|
||||
bool operator>(AngleOf<T> a) const;
|
||||
bool operator>=(AngleOf<T> a) const;
|
||||
bool operator<(AngleOf<T> a) const;
|
||||
bool operator<=(AngleOf<T> a) const;
|
||||
/// @brief Tests whether this angle is equal to the given angle
|
||||
/// @param angle The angle to compare to
|
||||
/// @return True when the angles are equal, False otherwise
|
||||
/// @note The equality is determine within the limits of precision of the raw
|
||||
/// type T
|
||||
bool operator==(const AngleOf<T> angle) const;
|
||||
/// @brief Tests if this angle is greater than the given angle
|
||||
/// @param angle The given angle
|
||||
/// @return True when this angle is greater than the given angle, False
|
||||
/// otherwise
|
||||
bool operator>(AngleOf<T> angle) const;
|
||||
/// @brief Tests if this angle is greater than or equal to the given angle
|
||||
/// @param angle The given angle
|
||||
/// @return True when this angle is greater than or equal to the given angle.
|
||||
/// False otherwise.
|
||||
bool operator>=(AngleOf<T> angle) const;
|
||||
/// @brief Tests if this angle is less than the given angle
|
||||
/// @param angle The given angle
|
||||
/// @return True when this angle is less than the given angle. False
|
||||
/// otherwise.
|
||||
bool operator<(AngleOf<T> angle) const;
|
||||
/// @brief Tests if this angle is less than or equal to the given angle
|
||||
/// @param angle The given angle
|
||||
/// @return True when this angle is less than or equal to the given angle.
|
||||
/// False otherwise.
|
||||
bool operator<=(AngleOf<T> angle) const;
|
||||
|
||||
static signed int Sign(AngleOf<T> a);
|
||||
static AngleOf<T> Abs(AngleOf<T> a);
|
||||
/// @brief Returns the sign of the angle
|
||||
/// @param angle The angle
|
||||
/// @return -1 when the angle is negative, 1 when it is positive and 0
|
||||
/// otherwise.
|
||||
static signed int Sign(AngleOf<T> angle);
|
||||
/// @brief Returns the magnitude of the angle
|
||||
/// @param angle The angle
|
||||
/// @return The positive magitude of the angle.
|
||||
/// Negative values are negated to get a positive result
|
||||
static AngleOf<T> Abs(AngleOf<T> angle);
|
||||
|
||||
/// @brief Negate the angle
|
||||
/// @return The negated angle
|
||||
AngleOf<T> operator-() const;
|
||||
AngleOf<T> operator-(const AngleOf<T> &a) const;
|
||||
AngleOf<T> operator+(const AngleOf<T> &a) const;
|
||||
AngleOf<T> operator+=(const AngleOf<T> &a);
|
||||
/// @brief Substract another angle from this angle
|
||||
/// @param angle The angle to subtract from this angle
|
||||
/// @return The result of the subtraction
|
||||
AngleOf<T> operator-(const AngleOf<T> &angle) const;
|
||||
/// @brief Add another angle from this angle
|
||||
/// @param angle The angle to add to this angle
|
||||
/// @return The result of the addition
|
||||
AngleOf<T> operator+(const AngleOf<T> &angle) const;
|
||||
/// @brief Add another angle to this angle
|
||||
/// @param angle The angle to add to this angle
|
||||
/// @return The result of the addition
|
||||
AngleOf<T> operator+=(const AngleOf<T> &angle);
|
||||
|
||||
friend AngleOf<T> operator*(const AngleOf<T> &a, float f) {
|
||||
return AngleOf::Degrees((float)a.InDegrees() * f);
|
||||
/// @brief Mutliplies the angle
|
||||
/// @param angle The angle to multiply
|
||||
/// @param factor The factor by which the angle is multiplied
|
||||
/// @return The multiplied angle
|
||||
friend AngleOf<T> operator*(const AngleOf<T> &angle, float factor) {
|
||||
return AngleOf::Degrees((float)angle.InDegrees() * factor);
|
||||
}
|
||||
friend AngleOf<T> operator*(float f, const AngleOf<T> &a) {
|
||||
return AngleOf::Degrees((float)f * a.InDegrees());
|
||||
/// @brief Multiplies the angle
|
||||
/// @param factor The factor by which the angle is multiplies
|
||||
/// @param angle The angle to multiply
|
||||
/// @return The multiplied angle
|
||||
friend AngleOf<T> operator*(float factor, const AngleOf<T> &angle) {
|
||||
return AngleOf::Degrees((float)factor * angle.InDegrees());
|
||||
}
|
||||
|
||||
/// @brief Normalizes the angle to (-180..180] or (-PI..PI]
|
||||
/// Should not be needed but available in case it is.
|
||||
void Normalize();
|
||||
/// @brief Normalizes the angle to (-180..180] or (-PI..PI]
|
||||
/// @param angle The angle to normalize
|
||||
/// @return The normalized angle;
|
||||
static AngleOf<T> Normalize(AngleOf<T> angle);
|
||||
static AngleOf<T> Clamp(AngleOf<T> a, AngleOf<T> min, AngleOf<T> max);
|
||||
/// @brief Clamps the angle value between the two given angles
|
||||
/// @param angle The angle to clamp
|
||||
/// @param min The minimum angle
|
||||
/// @param max The maximum angle
|
||||
/// @return The clamped value
|
||||
/// @remark When the min value is greater than the max value, angle is
|
||||
/// returned unclamped.
|
||||
static AngleOf<T> Clamp(AngleOf<T> angle, AngleOf<T> min, AngleOf<T> max);
|
||||
// static AngleOf<T> Difference(AngleOf<T> a, AngleOf<T> b) {
|
||||
// AngleOf<T> r = Normalize(b.InDegrees() - a.InDegrees());
|
||||
// return r;
|
||||
// };
|
||||
|
||||
/// @brief Rotates an angle towards another angle with a max distance
|
||||
/// @param fromAngle The angle to start from
|
||||
/// @param toAngle The angle to rotate towards
|
||||
/// @param maxAngle The maximum angle to rotate
|
||||
/// @return The rotated angle
|
||||
static AngleOf<T> MoveTowards(AngleOf<T> fromAngle, AngleOf<T> toAngle,
|
||||
float maxAngle);
|
||||
|
||||
static float Cos(AngleOf<T> a);
|
||||
static float Sin(AngleOf<T> a);
|
||||
static float Tan(AngleOf<T> a);
|
||||
/// @brief Calculates the cosine of an angle
|
||||
/// @param angle The given angle
|
||||
/// @return The cosine of the angle
|
||||
static float Cos(AngleOf<T> angle);
|
||||
/// @brief Calculates the sine of an angle
|
||||
/// @param angle The given angle
|
||||
/// @return The sine of the angle
|
||||
static float Sin(AngleOf<T> angle);
|
||||
/// @brief Calculates the tangent of an angle
|
||||
/// @param angle The given angle
|
||||
/// @return The tangent of the angle
|
||||
static float Tan(AngleOf<T> angle);
|
||||
|
||||
/// @brief Calculates the arc cosine angle
|
||||
/// @param f The value
|
||||
/// @return The arc cosine for the given value
|
||||
static AngleOf<T> Acos(float f);
|
||||
/// @brief Calculates the arc sine angle
|
||||
/// @param f The value
|
||||
/// @return The arc sine for the given value
|
||||
static AngleOf<T> Asin(float f);
|
||||
/// @brief Calculates the arc tangent angle
|
||||
/// @param f The value
|
||||
/// @return The arc tangent for the given value
|
||||
static AngleOf<T> Atan(float f);
|
||||
static AngleOf<T> Atan2(float f1, float f2);
|
||||
/// @brief Calculates the tangent for the given values
|
||||
/// @param y The vertical value
|
||||
/// @param x The horizontal value
|
||||
/// @return The tanget for the given values
|
||||
/// Uses the y and x signs to compute the quadrant
|
||||
static AngleOf<T> Atan2(float y, float x);
|
||||
|
||||
/// @brief Computes the length of a side using the rule of cosines
|
||||
/// @param a The length of side A
|
||||
/// @param b The length of side B
|
||||
/// @param gamma The angle of the corner opposing side C
|
||||
/// @return The length of side C
|
||||
static float CosineRuleSide(float a, float b, AngleOf<T> gamma);
|
||||
/// @brief Computes the angle of a corner using the rule of cosines
|
||||
/// @param a The length of side A
|
||||
/// @param b The length of side B
|
||||
/// @param c The length of side C
|
||||
/// @return The angle of the corner opposing side C
|
||||
static AngleOf<T> CosineRuleAngle(float a, float b, float c);
|
||||
|
||||
/// @brief Computes the angle of a corner using the rule of sines
|
||||
/// @param a The length of side A
|
||||
/// @param beta the angle of the corner opposing side B
|
||||
/// @param c The length of side C
|
||||
/// @return The angle of the corner opposing side A
|
||||
static AngleOf<T> SineRuleAngle(float a, AngleOf<T> beta, float c);
|
||||
|
||||
private:
|
||||
T value;
|
||||
|
||||
AngleOf<T>(T value);
|
||||
// These are deprecated, will move to private.
|
||||
// Use Degrees/Radians instead
|
||||
// AngleOf(signed int f);
|
||||
// AngleOf(float f);
|
||||
};
|
||||
|
||||
using Angle = AngleOf<float>;
|
||||
|
@ -9,6 +9,8 @@ const float Float::epsilon = 1e-05f;
|
||||
const float Float::sqrEpsilon = 1e-10f;
|
||||
|
||||
float Float::Clamp(float f, float min, float max) {
|
||||
if (max < min)
|
||||
return f;
|
||||
if (f < min)
|
||||
return min;
|
||||
if (f > max)
|
||||
|
@ -1,8 +1,8 @@
|
||||
#if GTEST
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
#include <math.h>
|
||||
|
||||
#include "Angle.h"
|
||||
|
||||
@ -86,7 +86,7 @@ TEST(Angle16, Normalize) {
|
||||
r = Angle16::Normalize(Angle16::Degrees(0));
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "Normalize 0";
|
||||
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
// Infinites are not supported
|
||||
r = Angle16::Normalize(Angle16::Degrees(FLOAT_INFINITY));
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), FLOAT_INFINITY) << "Normalize INFINITY";
|
||||
@ -123,9 +123,9 @@ TEST(Angle16, Clamp) {
|
||||
|
||||
r = Angle16::Clamp(Angle16::Degrees(0), Angle16::Degrees(10),
|
||||
Angle16::Degrees(-10));
|
||||
EXPECT_NEAR(r.InDegrees(), 10, 1.0e-2) << "Clamp 0 10 -10";
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "Clamp 0 10 -10";
|
||||
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
// Infinites are not supported
|
||||
r = Angle16::Clamp(Angle16::Degrees(10), Angle16::Degrees(0),
|
||||
Angle16::Degrees(FLOAT_INFINITY));
|
||||
@ -216,7 +216,7 @@ TEST(Angle16, MoveTowards) {
|
||||
r = Angle16::MoveTowards(Angle16::Degrees(0), Angle16::Degrees(0), 30);
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "MoveTowards 0 0 30";
|
||||
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
// infinites are not supported
|
||||
r = Angle16::MoveTowards(Angle16::Degrees(0), Angle16::Degrees(90),
|
||||
FLOAT_INFINITY);
|
||||
|
@ -1,8 +1,8 @@
|
||||
#if GTEST
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
#include <math.h>
|
||||
|
||||
#include "Angle.h"
|
||||
|
||||
@ -86,7 +86,7 @@ TEST(Angle8, Normalize) {
|
||||
r = Angle8::Normalize(Angle8::Degrees(0));
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "Normalize 0";
|
||||
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
// Infinites are not supported
|
||||
r = Angle8::Normalize(Angle8::Degrees(FLOAT_INFINITY));
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), FLOAT_INFINITY) << "Normalize INFINITY";
|
||||
@ -122,9 +122,9 @@ TEST(Angle8, Clamp) {
|
||||
|
||||
r = Angle8::Clamp(Angle8::Degrees(0), Angle8::Degrees(10),
|
||||
Angle8::Degrees(-10));
|
||||
EXPECT_NEAR(r.InDegrees(), 10, 1.0e-0) << "Clamp 0 10 -10";
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "Clamp 0 10 -10";
|
||||
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
// Infinites are not supported
|
||||
r = Angle8::Clamp(Angle8::Degrees(10), Angle8::Degrees(0),
|
||||
Angle8::Degrees(FLOAT_INFINITY));
|
||||
@ -215,7 +215,7 @@ TEST(Angle8, MoveTowards) {
|
||||
r = Angle8::MoveTowards(Angle8::Degrees(0), Angle8::Degrees(0), 30);
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "MoveTowards 0 0 30";
|
||||
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
if (false) { // std::numeric_limits<float>::is_iec559) {
|
||||
// infinites are not supported
|
||||
r = Angle8::MoveTowards(Angle8::Degrees(0), Angle8::Degrees(90),
|
||||
FLOAT_INFINITY);
|
||||
|
@ -1,8 +1,8 @@
|
||||
#if GTEST
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
#include <math.h>
|
||||
|
||||
#include "Angle.h"
|
||||
|
||||
@ -120,7 +120,7 @@ TEST(AngleSingle, Clamp) {
|
||||
|
||||
r = AngleSingle::Clamp(AngleSingle::Degrees(0), AngleSingle::Degrees(1),
|
||||
AngleSingle::Degrees(-1));
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 1) << "Clamp 0 1 -1";
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 0) << "Clamp 0 1 -1";
|
||||
|
||||
if (std::numeric_limits<float>::is_iec559) {
|
||||
r = AngleSingle::Clamp(AngleSingle::Degrees(1), AngleSingle::Degrees(0),
|
||||
|
@ -1,8 +1,8 @@
|
||||
#if GTEST
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
#include <math.h>
|
||||
|
||||
#include "FloatSingle.h"
|
||||
|
||||
@ -27,7 +27,7 @@ TEST(FloatC, Clamp) {
|
||||
EXPECT_FLOAT_EQ(r, 0) << "Clamp 0 0 0";
|
||||
|
||||
r = Float::Clamp(0, 1, -1);
|
||||
EXPECT_FLOAT_EQ(r, 1) << "Clamp 0 1 -1";
|
||||
EXPECT_FLOAT_EQ(r, 0) << "Clamp 0 1 -1";
|
||||
|
||||
if (std::numeric_limits<float>::is_iec559) {
|
||||
r = Float::Clamp(1, 0, FLOAT_INFINITY);
|
||||
|
Loading…
x
Reference in New Issue
Block a user