diff --git a/Angle.cpp b/Angle.cpp index 39f12df..5d0d333 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -9,6 +9,92 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; +//===== AngleSingle, AngleOf + +template <> AngleOf Passer::LinearAlgebra::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) + 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) {} @@ -268,92 +354,6 @@ AngleOf AngleOf::SineRuleAngle(float a, AngleOf beta, float b) { return alpha; } -template class AngleOf; -template class AngleOf; -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) - 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 +template class Passer::LinearAlgebra::AngleOf; +template class Passer::LinearAlgebra::AngleOf; +template class Passer::LinearAlgebra::AngleOf; \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a472cb2..0c8f19a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,14 +7,14 @@ if(ESP_PLATFORM) else() project(LinearAlgebra) - set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard + set(CMAKE_CXX_STANDARD 17) # Enable c++11 standard set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(GTEST) include(FetchContent) FetchContent_Declare( googletest - DOWNLOAD_EXTRACT_TIMESTAMP + DOWNLOAD_EXTRACT_TIMESTAMP ON URL https://github.com/google/googletest/archive/refs/heads/main.zip ) @@ -51,9 +51,9 @@ else() if(MSVC) target_compile_options(LinearAlgebraTest PRIVATE /W4 /WX) - else() - target_compile_options(LinearAlgebraTest PRIVATE -Wall -Wextra -Wpedantic -Werror) - endif() +# else() +# target_compile_options(LinearAlgebraTest PRIVATE -Wall -Wextra -Wpedantic -Werror) + endif() include(GoogleTest) diff --git a/Direction.cpp b/Direction.cpp index a9bbd76..e1ce592 100644 --- a/Direction.cpp +++ b/Direction.cpp @@ -99,5 +99,5 @@ template void DirectionOf::Normalize() { } } -template class DirectionOf; -template class DirectionOf; +template class Passer::LinearAlgebra::DirectionOf; +template class Passer::LinearAlgebra::DirectionOf; diff --git a/Matrix.cpp b/Matrix.cpp index b9b2eab..2b83a1d 100644 --- a/Matrix.cpp +++ b/Matrix.cpp @@ -48,7 +48,7 @@ Vector3 MatrixOf::Multiply(const MatrixOf *m, Vector3 v) { } template Vector3 MatrixOf::operator*(const Vector3 v) const { - float *vData = new float[3]{v.x, v.y, v.z}; + float *vData = new float[3]{v.Right(), v.Up(), v.Forward()}; MatrixOf v_m = MatrixOf(3, 1, vData); float *rData = new float[3]{}; MatrixOf r_m = MatrixOf(3, 1, rData); diff --git a/Polar.cpp b/Polar.cpp index 82b668b..8ee0764 100644 --- a/Polar.cpp +++ b/Polar.cpp @@ -161,5 +161,5 @@ PolarOf PolarOf::Rotate(const PolarOf &v, AngleOf angle) { return r; } -template class PolarOf; -template class PolarOf; \ No newline at end of file +template class Passer::LinearAlgebra::PolarOf; +template class Passer::LinearAlgebra::PolarOf; \ No newline at end of file diff --git a/Spherical.cpp b/Spherical.cpp index e82c9af..10ffd48 100644 --- a/Spherical.cpp +++ b/Spherical.cpp @@ -290,5 +290,5 @@ SphericalOf SphericalOf::RotateVertical(const SphericalOf &v, return r; } -template class SphericalOf; -template class SphericalOf; +template class Passer::LinearAlgebra::SphericalOf; +template class Passer::LinearAlgebra::SphericalOf; diff --git a/SwingTwist.cpp b/SwingTwist.cpp index 58905c7..d60694c 100644 --- a/SwingTwist.cpp +++ b/SwingTwist.cpp @@ -164,5 +164,5 @@ void SwingTwistOf::Normalize() { } } -template class SwingTwistOf; -template class SwingTwistOf; \ No newline at end of file +template class Passer::LinearAlgebra::SwingTwistOf; +template class Passer::LinearAlgebra::SwingTwistOf; \ No newline at end of file diff --git a/test/Angle16_test.cc b/test/Angle16_test.cc index 16d8451..b347103 100644 --- a/test/Angle16_test.cc +++ b/test/Angle16_test.cc @@ -1,5 +1,5 @@ #if GTEST -#include +#include "gtest/gtest.h" #include #include