Made it work on MacOS

This commit is contained in:
Pascal Serrarens 2025-01-01 22:32:56 +01:00
parent d0ba29e69b
commit 5b89234762
8 changed files with 104 additions and 104 deletions

178
Angle.cpp
View File

@ -9,6 +9,92 @@
const float Rad2Deg = 57.29578F;
const float Deg2Rad = 0.0174532924F;
//===== AngleSingle, AngleOf<float>
template <> AngleOf<float> Passer::LinearAlgebra::AngleOf<float>::Degrees(float degrees) {
if (isfinite(degrees)) {
while (degrees < -180)
degrees += 360;
while (degrees >= 180)
degrees -= 360;
}
return AngleOf<float>(degrees);
}
template <> AngleOf<float> AngleOf<float>::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<float>::InDegrees() const { return this->value; }
template <> float AngleOf<float>::InRadians() const {
return this->value * Deg2Rad;
}
//===== Angle16, AngleOf<signed short>
template <>
AngleOf<signed short> AngleOf<signed short>::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<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(radians / pi * 32768.0F);
return Binary(value);
}
template <> float AngleOf<signed short>::InDegrees() const {
float degrees = this->value / 65536.0f * 360.0f;
return degrees;
}
template <> float AngleOf<signed short>::InRadians() const {
float radians = this->value / 65536.0f * (2 * pi);
return radians;
}
//===== Angle8, AngleOf<signed char>
template <> AngleOf<signed char> AngleOf<signed char>::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<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(radians / pi * 128.0f);
return Binary(value);
}
template <> float AngleOf<signed char>::InDegrees() const {
float degrees = this->value / 256.0f * 360.0f;
return degrees;
}
template <> float AngleOf<signed char>::InRadians() const {
float radians = this->value / 128.0f * pi;
return radians;
}
//===== Generic
template <typename T> AngleOf<T>::AngleOf() : value(0) {}
@ -268,92 +354,6 @@ AngleOf<T> AngleOf<T>::SineRuleAngle(float a, AngleOf<T> beta, float b) {
return alpha;
}
template class AngleOf<float>;
template class AngleOf<signed char>;
template class AngleOf<signed short>;
//===== AngleSingle, AngleOf<float>
template <> AngleOf<float> AngleOf<float>::Degrees(float degrees) {
if (isfinite(degrees)) {
while (degrees < -180)
degrees += 360;
while (degrees >= 180)
degrees -= 360;
}
return AngleOf<float>(degrees);
}
template <> AngleOf<float> AngleOf<float>::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<float>::InDegrees() const { return this->value; }
template <> float AngleOf<float>::InRadians() const {
return this->value * Deg2Rad;
}
//===== Angle16, AngleOf<signed short>
template <>
AngleOf<signed short> AngleOf<signed short>::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<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(radians / pi * 32768.0F);
return Binary(value);
}
template <> float AngleOf<signed short>::InDegrees() const {
float degrees = this->value / 65536.0f * 360.0f;
return degrees;
}
template <> float AngleOf<signed short>::InRadians() const {
float radians = this->value / 65536.0f * (2 * pi);
return radians;
}
//===== Angle8, AngleOf<signed char>
template <> AngleOf<signed char> AngleOf<signed char>::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<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(radians / pi * 128.0f);
return Binary(value);
}
template <> float AngleOf<signed char>::InDegrees() const {
float degrees = this->value / 256.0f * 360.0f;
return degrees;
}
template <> float AngleOf<signed char>::InRadians() const {
float radians = this->value / 128.0f * pi;
return radians;
}
template class Passer::LinearAlgebra::AngleOf<float>;
template class Passer::LinearAlgebra::AngleOf<signed char>;
template class Passer::LinearAlgebra::AngleOf<signed short>;

View File

@ -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)

View File

@ -99,5 +99,5 @@ template <typename T> void DirectionOf<T>::Normalize() {
}
}
template class DirectionOf<float>;
template class DirectionOf<signed short>;
template class Passer::LinearAlgebra::DirectionOf<float>;
template class Passer::LinearAlgebra::DirectionOf<signed short>;

View File

@ -48,7 +48,7 @@ Vector3 MatrixOf<float>::Multiply(const MatrixOf<float> *m, Vector3 v) {
}
template <typename T> Vector3 MatrixOf<T>::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<float> v_m = MatrixOf<float>(3, 1, vData);
float *rData = new float[3]{};
MatrixOf<float> r_m = MatrixOf<float>(3, 1, rData);

View File

@ -161,5 +161,5 @@ PolarOf<T> PolarOf<T>::Rotate(const PolarOf &v, AngleOf<T> angle) {
return r;
}
template class PolarOf<float>;
template class PolarOf<signed short>;
template class Passer::LinearAlgebra::PolarOf<float>;
template class Passer::LinearAlgebra::PolarOf<signed short>;

View File

@ -290,5 +290,5 @@ SphericalOf<T> SphericalOf<T>::RotateVertical(const SphericalOf<T> &v,
return r;
}
template class SphericalOf<float>;
template class SphericalOf<signed short>;
template class Passer::LinearAlgebra::SphericalOf<float>;
template class Passer::LinearAlgebra::SphericalOf<signed short>;

View File

@ -164,5 +164,5 @@ void SwingTwistOf<T>::Normalize() {
}
}
template class SwingTwistOf<float>;
template class SwingTwistOf<signed short>;
template class Passer::LinearAlgebra::SwingTwistOf<float>;
template class Passer::LinearAlgebra::SwingTwistOf<signed short>;

View File

@ -1,5 +1,5 @@
#if GTEST
#include <gtest/gtest.h>
#include "gtest/gtest.h"
#include <limits>
#include <math.h>