From 52de55d7d097eb906b01036429a0163877d1cb2d Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 14:52:20 +0100 Subject: [PATCH] Trying to fix specialization before instantiation error --- Angle.cpp | 178 +++++++++++++++++++++++++++--------------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/Angle.cpp b/Angle.cpp index 535edd7..8acbdf8 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -11,98 +11,12 @@ const float Deg2Rad = 0.0174532924F; //---------------------- -//===== AngleSingle, AngleOf - -template <> AngleOf AngleOf::Degrees(float degrees) { - if (isfinite(degrees)) { - while (degrees < -180) - degrees += 360; - while (degrees >= 180) - degrees -= 360; - } - - return Binary(degrees); -} - -template <> AngleOf AngleOf::Radians(float radians) { - if (isfinite(radians)) { - while (radians <= -pi) - radians += 2 * pi; - while (radians > pi) - radians -= 2 * pi; - } - - return Binary(radians * Rad2Deg); -} - -template <> float AngleOf::InDegrees() const { return this->value; } - -template <> float AngleOf::InRadians() const { - return this->value * Deg2Rad; -} - -//===== Angle16, AngleOf - -template <> -AngleOf AngleOf::Degrees(float degrees) { - // map float [-180..180) to integer [-32768..32767] - signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F); - return Binary(value); -} - -template <> -AngleOf AngleOf::Radians(float radians) { - if (!isfinite(radians)) - return AngleOf::zero; - - // map float [-PI..PI) to integer [-32768..32767] - signed short value = (signed short)roundf(radians / pi * 32768.0F); - return Binary(value); -} - -template <> float AngleOf::InDegrees() const { - float degrees = this->value / 65536.0f * 360.0f; - return degrees; -} - -template <> float AngleOf::InRadians() const { - float radians = this->value / 65536.0f * (2 * pi); - return radians; -} - -//===== Angle8, AngleOf - -template <> AngleOf AngleOf::Degrees(float degrees) { - // map float [-180..180) to integer [-128..127) - signed char value = (signed char)roundf(degrees / 360.0F * 256.0F); - return Binary(value); -} - -template <> AngleOf AngleOf::Radians(float radians) { - if (!isfinite(radians)) - return AngleOf::zero; - - // map float [-pi..pi) to integer [-128..127) - signed char value = (signed char)roundf(radians / pi * 128.0f); - return Binary(value); -} - -template <> float AngleOf::InDegrees() const { - float degrees = this->value / 256.0f * 360.0f; - return degrees; -} - -template <> float AngleOf::InRadians() const { - float radians = this->value / 128.0f * pi; - return radians; -} - -//===== Generic - template AngleOf::AngleOf() : value(0) {} template const AngleOf AngleOf::zero = AngleOf(); +//===== Generic + template AngleOf AngleOf::Binary(T rawValue) { AngleOf angle = AngleOf(); angle.SetBinary(rawValue); @@ -356,4 +270,90 @@ AngleOf AngleOf::SineRuleAngle(float a, AngleOf beta, float b) { template class AngleOf; template class AngleOf; -template class AngleOf; \ No newline at end of file +template class AngleOf; + +//===== AngleSingle, AngleOf + +template <> AngleOf AngleOf::Degrees(float degrees) { + if (isfinite(degrees)) { + while (degrees < -180) + degrees += 360; + while (degrees >= 180) + degrees -= 360; + } + + return Binary(degrees); +} + +template <> AngleOf AngleOf::Radians(float radians) { + if (isfinite(radians)) { + while (radians <= -pi) + radians += 2 * pi; + while (radians > pi) + radians -= 2 * pi; + } + + return Binary(radians * Rad2Deg); +} + +template <> float AngleOf::InDegrees() const { return this->value; } + +template <> float AngleOf::InRadians() const { + return this->value * Deg2Rad; +} + +//===== Angle16, AngleOf + +template <> +AngleOf AngleOf::Degrees(float degrees) { + // map float [-180..180) to integer [-32768..32767] + signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F); + return Binary(value); +} + +template <> +AngleOf AngleOf::Radians(float radians) { + if (!isfinite(radians)) + return AngleOf::zero; + + // map float [-PI..PI) to integer [-32768..32767] + signed short value = (signed short)roundf(radians / pi * 32768.0F); + return Binary(value); +} + +template <> float AngleOf::InDegrees() const { + float degrees = this->value / 65536.0f * 360.0f; + return degrees; +} + +template <> float AngleOf::InRadians() const { + float radians = this->value / 65536.0f * (2 * pi); + return radians; +} + +//===== Angle8, AngleOf + +template <> AngleOf AngleOf::Degrees(float degrees) { + // map float [-180..180) to integer [-128..127) + signed char value = (signed char)roundf(degrees / 360.0F * 256.0F); + return Binary(value); +} + +template <> AngleOf AngleOf::Radians(float radians) { + if (!isfinite(radians)) + return AngleOf::zero; + + // map float [-pi..pi) to integer [-128..127) + signed char value = (signed char)roundf(radians / pi * 128.0f); + return Binary(value); +} + +template <> float AngleOf::InDegrees() const { + float degrees = this->value / 256.0f * 360.0f; + return degrees; +} + +template <> float AngleOf::InRadians() const { + float radians = this->value / 128.0f * pi; + return radians; +} \ No newline at end of file