From 240203036ba92f44eacfb557fc832903cb8a8aa6 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 14:47:13 +0100 Subject: [PATCH 01/10] Trying to fix specialization before instantiation error --- Angle.cpp | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Angle.cpp b/Angle.cpp index c88afdc..535edd7 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -8,29 +8,9 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; -/* -float Angle::Normalize(float angle) { - if (!isfinite(angle)) - return angle; - - while (angle <= -180) - angle += 360; - while (angle > 180) - angle -= 360; - return angle; -} -*/ //---------------------- -template AngleOf::AngleOf() : value(0) {} - -template const AngleOf AngleOf::zero = AngleOf(); -// template -// const AngleOf AngleOf::deg90 = AngleOf::Degrees(90); -// template -// const AngleOf AngleOf::deg180 = AngleOf::Degrees(180); - //===== AngleSingle, AngleOf template <> AngleOf AngleOf::Degrees(float degrees) { @@ -119,6 +99,10 @@ template <> float AngleOf::InRadians() const { //===== Generic +template AngleOf::AngleOf() : value(0) {} + +template const AngleOf AngleOf::zero = AngleOf(); + template AngleOf AngleOf::Binary(T rawValue) { AngleOf angle = AngleOf(); angle.SetBinary(rawValue); From 47ba024619c6248d7b516ca0fe452f0fd52498ea Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 14:47:13 +0100 Subject: [PATCH 02/10] Trying to fix specialization before instantiation error --- Angle.cpp | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Angle.cpp b/Angle.cpp index c88afdc..535edd7 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -8,29 +8,9 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; -/* -float Angle::Normalize(float angle) { - if (!isfinite(angle)) - return angle; - - while (angle <= -180) - angle += 360; - while (angle > 180) - angle -= 360; - return angle; -} -*/ //---------------------- -template AngleOf::AngleOf() : value(0) {} - -template const AngleOf AngleOf::zero = AngleOf(); -// template -// const AngleOf AngleOf::deg90 = AngleOf::Degrees(90); -// template -// const AngleOf AngleOf::deg180 = AngleOf::Degrees(180); - //===== AngleSingle, AngleOf template <> AngleOf AngleOf::Degrees(float degrees) { @@ -119,6 +99,10 @@ template <> float AngleOf::InRadians() const { //===== Generic +template AngleOf::AngleOf() : value(0) {} + +template const AngleOf AngleOf::zero = AngleOf(); + template AngleOf AngleOf::Binary(T rawValue) { AngleOf angle = AngleOf(); angle.SetBinary(rawValue); From 52de55d7d097eb906b01036429a0163877d1cb2d Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 14:52:20 +0100 Subject: [PATCH 03/10] 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 From e97aee99b1af6275cc1cb7a8b432833b04c2adca Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 14:58:05 +0100 Subject: [PATCH 04/10] Trying to fix specialization before instantiation error --- Angle.cpp | 10 +++------- Angle.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Angle.cpp b/Angle.cpp index cb7b6e0..39f12df 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -9,16 +9,12 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; -//---------------------- - -template AngleOf::AngleOf() : value(0) {} - -template const AngleOf AngleOf::zero = AngleOf(); - //===== Generic template AngleOf::AngleOf() : value(0) {} +template AngleOf::AngleOf(T rawValue) : value(rawValue) {} + template const AngleOf AngleOf::zero = AngleOf(); template AngleOf AngleOf::Binary(T rawValue) { @@ -286,7 +282,7 @@ template <> AngleOf AngleOf::Degrees(float degrees) { degrees -= 360; } - return Binary(degrees); + return AngleOf(degrees); } template <> AngleOf AngleOf::Radians(float radians) { diff --git a/Angle.h b/Angle.h index f8a215f..501a2dd 100644 --- a/Angle.h +++ b/Angle.h @@ -211,7 +211,7 @@ public: private: T value; - AngleOf(T value); + AngleOf(T rawValue); }; // using Angle = AngleOf; From 06e86236d52d363a2e5a25876157ee770e4d7cb6 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 15:00:28 +0100 Subject: [PATCH 05/10] Trying to fix specialization before instantiation error --- Angle.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Angle.cpp b/Angle.cpp index 39f12df..0993af6 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -9,6 +9,17 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; +template <> AngleOf AngleOf::Degrees(float degrees) { + if (isfinite(degrees)) { + while (degrees < -180) + degrees += 360; + while (degrees >= 180) + degrees -= 360; + } + + return AngleOf(degrees); +} + //===== Generic template AngleOf::AngleOf() : value(0) {} @@ -274,17 +285,6 @@ 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 AngleOf(degrees); -} - template <> AngleOf AngleOf::Radians(float radians) { if (isfinite(radians)) { while (radians <= -pi) From b877d4d2f3e8880899ab7e01cd370da8f91b1aea Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 15:06:34 +0100 Subject: [PATCH 06/10] Trying to fix specialization before instantiation error --- Angle.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Angle.h b/Angle.h index 501a2dd..e6e81a5 100644 --- a/Angle.h +++ b/Angle.h @@ -33,13 +33,13 @@ public: /// @return The angle value static AngleOf Degrees(float degrees); /// @brief Short-hand Deg alias for the Degrees function - constexpr static auto Deg = Degrees; + // constexpr static auto Deg = Degrees; /// @brief Creates an angle in radians /// @param radians the angle in radians /// @return The angle value static AngleOf Radians(float radians); /// @brief Short-hand Rad alias for the Radians function - constexpr static auto Rad = Radians; + // 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 @@ -214,7 +214,6 @@ private: AngleOf(T rawValue); }; -// using Angle = AngleOf; using AngleSingle = AngleOf; using Angle16 = AngleOf; using Angle8 = AngleOf; From f47e504bf42422c6a46c0f729301be478c36d861 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 15:10:51 +0100 Subject: [PATCH 07/10] Trying to fix specialization before instantiation error --- Angle.cpp | 22 +++++++++++----------- Angle.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Angle.cpp b/Angle.cpp index 0993af6..39f12df 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -9,17 +9,6 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; -template <> AngleOf AngleOf::Degrees(float degrees) { - if (isfinite(degrees)) { - while (degrees < -180) - degrees += 360; - while (degrees >= 180) - degrees -= 360; - } - - return AngleOf(degrees); -} - //===== Generic template AngleOf::AngleOf() : value(0) {} @@ -285,6 +274,17 @@ 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 AngleOf(degrees); +} + template <> AngleOf AngleOf::Radians(float radians) { if (isfinite(radians)) { while (radians <= -pi) diff --git a/Angle.h b/Angle.h index e6e81a5..22a39b5 100644 --- a/Angle.h +++ b/Angle.h @@ -28,12 +28,12 @@ public: // const static AngleOf deg90; // const static AngleOf deg180; + constexpr static auto Deg = Degrees; /// @brief Creates an angle in degrees /// @param degrees the angle in degrees /// @return The angle value static AngleOf 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 From e445e5bb930ebb493149bab8b5bb4c6c98c6e693 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 15:14:47 +0100 Subject: [PATCH 08/10] Trying to fix specialization before instantiation error --- Angle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Angle.h b/Angle.h index 22a39b5..72cbda9 100644 --- a/Angle.h +++ b/Angle.h @@ -28,7 +28,6 @@ public: // const static AngleOf deg90; // const static AngleOf deg180; - constexpr static auto Deg = Degrees; /// @brief Creates an angle in degrees /// @param degrees the angle in degrees /// @return The angle value @@ -37,6 +36,7 @@ public: /// @brief Creates an angle in radians /// @param radians the angle in radians /// @return The angle value + constexpr static auto Deg = &Degrees; static AngleOf Radians(float radians); /// @brief Short-hand Rad alias for the Radians function // constexpr static auto Rad = Radians; From d212db27832648be7937b559685279912d5b2b08 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 15:19:42 +0100 Subject: [PATCH 09/10] Trying to fix specialization before instantiation error --- Angle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Angle.h b/Angle.h index 72cbda9..d066d4a 100644 --- a/Angle.h +++ b/Angle.h @@ -36,7 +36,7 @@ public: /// @brief Creates an angle in radians /// @param radians the angle in radians /// @return The angle value - constexpr static auto Deg = &Degrees; + constexpr static AngleOf (*Deg)(float degrees) = &Degrees; static AngleOf Radians(float radians); /// @brief Short-hand Rad alias for the Radians function // constexpr static auto Rad = Radians; From 2b5f5cd175b20fa01e04b696dfe0cfbe2c4ad9da Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 28 Dec 2024 15:22:46 +0100 Subject: [PATCH 10/10] Removed shorthand Deg/Rad aliases... (see below) --- Angle.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Angle.h b/Angle.h index d066d4a..e8f1f63 100644 --- a/Angle.h +++ b/Angle.h @@ -32,14 +32,11 @@ public: /// @param degrees the angle in degrees /// @return The angle value static AngleOf Degrees(float degrees); - /// @brief Short-hand Deg alias for the Degrees function /// @brief Creates an angle in radians /// @param radians the angle in radians /// @return The angle value - constexpr static AngleOf (*Deg)(float degrees) = &Degrees; static AngleOf 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