From 0ebfce48d7517ffe5f5a39bc36af2dd8273ef510 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 24 Sep 2024 11:48:25 +0200 Subject: [PATCH] Spherical direction --- Angle16.cpp | 97 ---------------------------------------- Angle16.h | 41 ----------------- Angle32.h | 31 ------------- Angle8.cpp | 60 ------------------------- Angle8.h | 35 --------------- Polar.cpp | 4 +- Spherical.cpp | 43 ++++++++++-------- Spherical.h | 19 ++++---- SwingTwist.cpp | 6 +-- Vector3.cpp | 6 +-- test/Spherical16_test.cc | 58 +++++++++++++++--------- test/Spherical_test.cc | 72 +++++++++++++++++------------ 12 files changed, 122 insertions(+), 350 deletions(-) delete mode 100644 Angle16.cpp delete mode 100644 Angle16.h delete mode 100644 Angle32.h delete mode 100644 Angle8.cpp delete mode 100644 Angle8.h diff --git a/Angle16.cpp b/Angle16.cpp deleted file mode 100644 index 50a0d8d..0000000 --- a/Angle16.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0.If a copy of the MPL was not distributed with this -// file, You can obtain one at https ://mozilla.org/MPL/2.0/. -/* -#include -#include -#include "Angle.h" - -template <> -AngleOf::AngleOf(int angle) { - signed long long_angle = (signed short)angle * 65536; - this->value = (signed short)(long_angle / 360); -} - -template <> -AngleOf::AngleOf(float angle) { - if (!isfinite(angle)) { - value = 0; - return; - } - - // map float [-180..180) to integer [-32768..32767] - this->value = (signed short)(angle / 360.0F * 65536.0F); -} - -// template <> -// AngleOf::operator float() const { -// float f = ((this->value * 180) / 32768.0F); -// return f; -// } - -template <> -float AngleOf::ToFloat() const { - float f = ((this->value * 180) / 32768.0F); - return f; -} - -template <> -AngleOf AngleOf::operator-() const { - AngleOf angle = AngleOf(); - angle.value = -this->value; - return angle; -} - -template <> -AngleOf AngleOf::operator-( - const AngleOf& a) const { - AngleOf angle = AngleOf(); - angle.value = this->value - a.value; - return angle; -} - -template <> -AngleOf AngleOf::operator+( - const AngleOf& a) const { - AngleOf angle = AngleOf(); - angle.value = this->value + a.value; - return angle; -} - -// Not correct!!! just for syntactical compilation ATM -template <> -AngleOf AngleOf::CosineRuleSide( - float a, - float b, - AngleOf gamma) { - float a2 = a * a; - float b2 = b * b; - float d = a2 + b2 - - 2 * a * b * cosf(gamma.ToFloat() * Passer::LinearAlgebra::Deg2Rad); - // Catch edge cases where float inacuracies lead tot nans - if (d < 0) - return 0.0f; - - float c = sqrtf(d); - return c; -} - -// Not correct!!! just for syntactical compilation ATM -template <> -AngleOf AngleOf::CosineRuleAngle(float a, - float b, - float c) { - float a2 = a * a; - float b2 = b * b; - float c2 = c * c; - float d = (a2 + b2 - c2) / (2 * a * b); - // Catch edge cases where float inacuracies lead tot nans - if (d >= 1) - return 0.0f; - if (d <= -1) - return 180.0f; - - float gamma = acosf(d) * Passer::LinearAlgebra::Rad2Deg; - return gamma; -} -*/ \ No newline at end of file diff --git a/Angle16.h b/Angle16.h deleted file mode 100644 index 60d18de..0000000 --- a/Angle16.h +++ /dev/null @@ -1,41 +0,0 @@ -// #include "AngleUsing.h" -/* -#include -#include -#include "Angle.h" - -namespace Passer { -namespace LinearAlgebra { - -typedef AngleOf Angle16; - -// template <> -// inline static Angle16 Angle16::Degrees(short angle) { -// long long_angle = angle * 65535; -// long_angle = div(long_angle, (long)360); -// return Angle16(long_angle); //(long_angle / 360); -// } - -// template <> -// inline static Angle16 Angle16::Degrees(float angle) { -// return (angle / 360.0F * 65536.0F); -// } -// template <> Angle16::AngleOf(float angle) { -// if (!isfinite(angle)) { -// value = 0; -// return; -// } - -// // map float [-180..180) to integer [-32768..32767] -// this->value = (signed short)((angle / 360.0F) * 65536.0F); -// } - -// template <> float Angle16::ToFloat() const { -// float f = ((this->value * 180) / 32768.0F); -// return f; -// } - -} // namespace LinearAlgebra -} // namespace Passer -using namespace Passer::LinearAlgebra; -*/ \ No newline at end of file diff --git a/Angle32.h b/Angle32.h deleted file mode 100644 index 4ca8434..0000000 --- a/Angle32.h +++ /dev/null @@ -1,31 +0,0 @@ -// #include "AngleUsing.h" -/* -#include -#include "Angle.h" - -namespace Passer { -namespace LinearAlgebra { - -typedef AngleOf Angle32; - -// template <> -// Angle32::AngleOf(float angle) { -// if (!isfinite(angle)) { -// value = 0; -// return; -// } - -// // map float [-180..180) to integer [-2147483648..2147483647] -// this->value = (signed long)((angle / 360.0F) * 4294967295.0F); -// } - -// template <> -// float Angle32::ToFloat() const { -// float f = ((this->value * 180) / 2147483648.0F); -// return f; -// } - -} // namespace LinearAlgebra -} // namespace Passer -using namespace Passer::LinearAlgebra; -*/ \ No newline at end of file diff --git a/Angle8.cpp b/Angle8.cpp deleted file mode 100644 index a45d1a6..0000000 --- a/Angle8.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0.If a copy of the MPL was not distributed with this -// file, You can obtain one at https ://mozilla.org/MPL/2.0/. -/* -#include -#include "Angle.h" - -template <> -AngleOf::AngleOf(int angle) { - signed short short_angle = (signed char)angle * 256; - this->value = (signed char)(short_angle / 360); -} - -template <> -AngleOf::AngleOf(float angle) { - if (!isfinite(angle)) { - value = 0; - return; - } - - // map float [-180..180) to integer [-128..127] - float f = angle / 360.0F; - this->value = (signed char)(f * 256.0F); -} - -// template <> -// AngleOf::operator float() const { -// float f = (this->value * 180) / 128.0F; -// return f; -// } - -template <> -float AngleOf::ToFloat() const { - float f = (this->value * 180) / 128.0F; - return f; -} - -template <> -AngleOf AngleOf::operator-() const { - AngleOf angle = AngleOf(); - angle.value = -this->value; - return angle; -} - -template <> -AngleOf AngleOf::operator-( - const AngleOf& a) const { - AngleOf angle = AngleOf(); - angle.value = this->value - a.value; - return angle; -} - -template <> -AngleOf AngleOf::operator+( - const AngleOf& a) const { - AngleOf angle = AngleOf(); - angle.value = this->value + a.value; - return angle; -} -*/ \ No newline at end of file diff --git a/Angle8.h b/Angle8.h deleted file mode 100644 index 7d4508e..0000000 --- a/Angle8.h +++ /dev/null @@ -1,35 +0,0 @@ -// #include "AngleUsing.h" -/* -#include -#include "Angle.h" - -namespace Passer { -namespace LinearAlgebra { - -typedef AngleOf Angle8; - -// template <> -// inline static Angle8 Angle8::Degrees(float angle) { -// return (angle / 360.0F * 256.0F); -// } - -// template <> Angle8::AngleOf(float angle) { -// if (!isfinite(angle)) { -// value = 0; -// return; -// } - -// // map float [-180..180) to integer [-128..127] -// float f = angle / 360.0F; -// this->value = (signed char)(f * 256.0F); -// } - -// template <> float Angle8::ToFloat() const { -// float f = (this->value * 180) / 128.0F; -// return f; -// } - -} // namespace LinearAlgebra -} // namespace Passer -using namespace Passer::LinearAlgebra; -*/ \ No newline at end of file diff --git a/Polar.cpp b/Polar.cpp index d40bad5..2ca014b 100644 --- a/Polar.cpp +++ b/Polar.cpp @@ -33,9 +33,9 @@ PolarOf PolarOf::FromVector2(Vector2 v) { } template PolarOf PolarOf::FromSpherical(SphericalOf v) { - float distance = v.distance * cosf(v.vertical.InDegrees() * + float distance = v.distance * cosf(v.direction.vertical.InDegrees() * Passer::LinearAlgebra::Deg2Rad); - AngleOf angle = v.horizontal; + AngleOf angle = v.direction.horizontal; PolarOf p = PolarOf(distance, angle); return p; } diff --git a/Spherical.cpp b/Spherical.cpp index 3fc8666..a88f704 100644 --- a/Spherical.cpp +++ b/Spherical.cpp @@ -8,8 +8,9 @@ template SphericalOf::SphericalOf() { this->distance = 0.0f; - this->horizontal = AngleOf(); - this->vertical = AngleOf(); + this->direction = DirectionOf(); + // this->horizontal = AngleOf(); + // this->vertical = AngleOf(); } // template <> @@ -24,8 +25,15 @@ SphericalOf::SphericalOf(float distance, AngleOf horizontal, AngleOf vertical) { this->distance = distance; - this->horizontal = horizontal; - this->vertical = vertical; + this->direction = DirectionOf(horizontal, vertical); + // this->horizontal = horizontal; + // this->vertical = vertical; +} + +template +SphericalOf::SphericalOf(float distance, DirectionOf direction) { + this->distance = distance; + this->direction = direction; } // template <> @@ -70,8 +78,8 @@ SphericalOf SphericalOf::FromVector3(Vector3 v) { template Vector3 SphericalOf::ToVector3() const { - float verticalRad = (pi / 2) - this->vertical.InRadians(); - float horizontalRad = this->horizontal.InRadians(); + float verticalRad = (pi / 2) - this->direction.vertical.InRadians(); + float horizontalRad = this->direction.horizontal.InRadians(); float cosVertical = cosf(verticalRad); float sinVertical = sinf(verticalRad); @@ -108,21 +116,17 @@ template const SphericalOf SphericalOf::down = SphericalOf(1.0f, AngleOf(), AngleOf::Degrees(-90)); -template <> -const SphericalOf SphericalOf::zero = - SphericalOf(0.0f, AngleOf(), AngleOf()); - template SphericalOf SphericalOf::WithDistance(float distance) { - SphericalOf v = SphericalOf(distance, this->horizontal, this->vertical); + SphericalOf v = SphericalOf(distance, this->direction); return SphericalOf(); } template SphericalOf SphericalOf::operator-() const { - SphericalOf v = SphericalOf(this->distance, - this->horizontal + AngleOf::Degrees(180), - this->vertical + AngleOf::Degrees(180)); + SphericalOf v = SphericalOf( + this->distance, this->direction.horizontal + AngleOf::Degrees(180), + this->direction.vertical + AngleOf::Degrees(180)); return v; } @@ -266,20 +270,23 @@ template SphericalOf SphericalOf::Rotate(const SphericalOf& v, AngleOf horizontalAngle, AngleOf verticalAngle) { - SphericalOf r = SphericalOf(v.distance, v.horizontal + horizontalAngle, - v.vertical + verticalAngle); + SphericalOf r = + SphericalOf(v.distance, v.direction.horizontal + horizontalAngle, + v.direction.vertical + verticalAngle); return r; } template SphericalOf SphericalOf::RotateHorizontal(const SphericalOf& v, AngleOf a) { - SphericalOf r = SphericalOf(v.distance, v.horizontal + a, v.vertical); + SphericalOf r = + SphericalOf(v.distance, v.direction.horizontal + a, v.direction.vertical); return r; } template SphericalOf SphericalOf::RotateVertical(const SphericalOf& v, AngleOf a) { - SphericalOf r = SphericalOf(v.distance, v.horizontal, v.vertical + a); + SphericalOf r = + SphericalOf(v.distance, v.direction.horizontal, v.direction.vertical + a); return r; } diff --git a/Spherical.h b/Spherical.h index 89480e2..8d71891 100644 --- a/Spherical.h +++ b/Spherical.h @@ -5,8 +5,7 @@ #ifndef SPHERICAL_H #define SPHERICAL_H -#include "Angle.h" -// #include "Polar.h" +#include "Direction.h" namespace Passer { namespace LinearAlgebra { @@ -23,13 +22,15 @@ class SphericalOf { float distance; /// @brief The angle in the horizontal plane in degrees, clockwise rotation /// @details The angle is automatically normalized to -180 .. 180 - AngleOf horizontal; + // AngleOf horizontal; /// @brief The angle in the vertical plane in degrees. Positive is upward. /// @details The angle is automatically normalized to -180 .. 180 - AngleOf vertical; + // AngleOf vertical; + DirectionOf direction; SphericalOf(); SphericalOf(float distance, AngleOf horizontal, AngleOf vertical); + SphericalOf(float distance, DirectionOf direction); static SphericalOf FromPolar(PolarOf v); @@ -76,11 +77,10 @@ class SphericalOf { /// @remark This operation will scale the distance of the vector. The angle /// will be unaffected. friend SphericalOf operator*(const SphericalOf& v, float f) { - return SphericalOf(v.distance * f, v.horizontal, v.vertical); + return SphericalOf(v.distance * f, v.direction); } friend SphericalOf operator*(float f, const SphericalOf& v) { - return SphericalOf(v.distance * f, v.horizontal, - v.vertical); // not correct, should be f * v.distance + return SphericalOf(f * v.distance, v.direction); } SphericalOf operator*=(float f); /// @brief Scale the vector uniformly down @@ -89,11 +89,10 @@ class SphericalOf { /// @remark This operation will scale the distance of the vector. The angle /// will be unaffected. friend SphericalOf operator/(const SphericalOf& v, float f) { - return SphericalOf(v.distance / f, v.horizontal, v.vertical); + return SphericalOf(v.distance / f, v.direction); } friend SphericalOf operator/(float f, const SphericalOf& v) { - return SphericalOf(v.distance / f, v.horizontal, - v.vertical); // not correct, should be f / v.distance + return SphericalOf(f / v.distance, v.direction); } SphericalOf operator/=(float f); diff --git a/SwingTwist.cpp b/SwingTwist.cpp index 57f7db5..88390a2 100644 --- a/SwingTwist.cpp +++ b/SwingTwist.cpp @@ -62,9 +62,9 @@ const SwingTwistOf SwingTwistOf::identity = SwingTwistOf(); template SphericalOf SwingTwistOf::operator*(const SphericalOf& vector) const { - SphericalOf v = SphericalOf(vector.distance, - vector.horizontal + this->swing.horizontal, - vector.vertical + this->swing.vertical); + SphericalOf v = SphericalOf( + vector.distance, vector.direction.horizontal + this->swing.horizontal, + vector.direction.vertical + this->swing.vertical); return v; } diff --git a/Vector3.cpp b/Vector3.cpp index 52ad3a0..958fdaf 100644 --- a/Vector3.cpp +++ b/Vector3.cpp @@ -31,10 +31,10 @@ Vector3::Vector3(Vector2 v) { } Vector3::Vector3(Spherical s) { - float verticalRad = - (90.0f - s.vertical.InDegrees()) * Passer::LinearAlgebra::Deg2Rad; + float verticalRad = (90.0f - s.direction.vertical.InDegrees()) * + Passer::LinearAlgebra::Deg2Rad; float horizontalRad = - s.horizontal.InDegrees() * Passer::LinearAlgebra::Deg2Rad; + s.direction.horizontal.InDegrees() * Passer::LinearAlgebra::Deg2Rad; float cosVertical = cosf(verticalRad); float sinVertical = sinf(verticalRad); float cosHorizontal = cosf(horizontalRad); diff --git a/test/Spherical16_test.cc b/test/Spherical16_test.cc index b73499b..4f445c9 100644 --- a/test/Spherical16_test.cc +++ b/test/Spherical16_test.cc @@ -13,22 +13,24 @@ TEST(Spherical16, FromVector3) { Spherical16 s = Spherical16::FromVector3(v); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance 0 0 1"; - EXPECT_FLOAT_EQ((float)s.horizontal.InDegrees(), 0.0F) << "s.hor 0 0 1"; - EXPECT_FLOAT_EQ((float)s.vertical.InDegrees(), 0.0F) << "s.vert 0 0 1"; + EXPECT_FLOAT_EQ((float)s.direction.horizontal.InDegrees(), 0.0F) + << "s.hor 0 0 1"; + EXPECT_FLOAT_EQ((float)s.direction.vertical.InDegrees(), 0.0F) + << "s.vert 0 0 1"; v = Vector3(0, 1, 0); s = Spherical16::FromVector3(v); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance 0 1 0"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 0.0F) << "s.hor 0 1 0"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 90.0F) << "s.vert 0 1 0"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 0.0F) << "s.hor 0 1 0"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 90.0F) << "s.vert 0 1 0"; v = Vector3(1, 0, 0); s = Spherical16::FromVector3(v); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance 1 0 0"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 90.0F) << "s.hor 1 0 0"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert 1 0 0"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 90.0F) << "s.hor 1 0 0"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) << "s.vert 1 0 0"; } // TEST(Spherical16, FromPolar) { @@ -75,10 +77,14 @@ TEST(Spherical16, Incident1) { Spherical16 sr = Spherical16(2.49F, Angle16::Degrees(98.18f), Angle16::Degrees(24.4F)); EXPECT_NEAR(s.distance, sr.distance, 1.0e-01); - EXPECT_NEAR(s.horizontal.InDegrees(), sr.horizontal.InDegrees(), 1.0e-02); - EXPECT_NEAR(s.vertical.InDegrees(), sr.vertical.InDegrees(), 1.0e-02); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), + sr.direction.horizontal.InDegrees(), 1.0e-02); + EXPECT_NEAR(s.direction.vertical.InDegrees(), + sr.direction.vertical.InDegrees(), 1.0e-02); - Vector3 r = Spherical16(sr.distance, sr.horizontal, sr.vertical).ToVector3(); + Vector3 r = + Spherical16(sr.distance, sr.direction.horizontal, sr.direction.vertical) + .ToVector3(); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-02) << "toVector3.x 1 0 0"; EXPECT_NEAR(r.Up(), v.Up(), 1.0e-02) << "toVector3.y 1 0 0"; EXPECT_NEAR(r.Forward(), v.Forward(), 1.0e-02) << "toVector3.z 1 0 0"; @@ -91,10 +97,14 @@ TEST(Spherical16, Incident2) { Spherical16 sr = Spherical16(1.4142135623F, Angle16::Degrees(45.0f), Angle16::Degrees(0.0F)); EXPECT_NEAR(s.distance, sr.distance, 1.0e-05); - EXPECT_NEAR(s.horizontal.InDegrees(), sr.horizontal.InDegrees(), 1.0e-05); - EXPECT_NEAR(s.vertical.InDegrees(), sr.vertical.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), + sr.direction.horizontal.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.vertical.InDegrees(), + sr.direction.vertical.InDegrees(), 1.0e-05); - Vector3 r = Spherical16(sr.distance, sr.horizontal, sr.vertical).ToVector3(); + Vector3 r = + Spherical16(sr.distance, sr.direction.horizontal, sr.direction.vertical) + .ToVector3(); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-06); EXPECT_NEAR(r.Up(), v.Up(), 1.0e-06); EXPECT_NEAR(r.Forward(), v.Forward(), 1.0e-06); @@ -104,21 +114,25 @@ TEST(Spherical16, Incident2) { sr = Spherical16(1.4142135623F, Angle16::Degrees(0), Angle16::Degrees(45)); EXPECT_NEAR(s.distance, sr.distance, 1.0e-05); - EXPECT_NEAR(s.horizontal.InDegrees(), sr.horizontal.InDegrees(), 1.0e-05); - EXPECT_NEAR(s.vertical.InDegrees(), sr.vertical.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), + sr.direction.horizontal.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.vertical.InDegrees(), + sr.direction.vertical.InDegrees(), 1.0e-05); - r = Spherical16(sr.distance, sr.horizontal, sr.vertical).ToVector3(); + r = Spherical16(sr.distance, sr.direction.horizontal, sr.direction.vertical) + .ToVector3(); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-06); EXPECT_NEAR(r.Up(), v.Up(), 1.0e-06); EXPECT_NEAR(r.Forward(), v.Forward(), 1.0e-06); v = Vector3(1.0f, 1.0f, 1.0f); s = Spherical16::FromVector3(v); - r = Spherical16(s.distance, s.horizontal, s.vertical).ToVector3(); + r = Spherical16(s.distance, s.direction.horizontal, s.direction.vertical) + .ToVector3(); EXPECT_NEAR(s.distance, 1.73205080F, 1.0e-02); - EXPECT_NEAR(s.horizontal.InDegrees(), 45.0F, 1.0e-02); - EXPECT_NEAR(s.vertical.InDegrees(), 35.26F, 1.0e-02); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), 45.0F, 1.0e-02); + EXPECT_NEAR(s.direction.vertical.InDegrees(), 35.26F, 1.0e-02); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-04); EXPECT_NEAR(r.Up(), v.Up(), 1.0e-04); @@ -146,14 +160,14 @@ TEST(Spherical16, Addition) { v2 = Spherical16(1, Angle16::Degrees(-45), Angle16::Degrees(0)); r = v1 + v2; EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 -45 0)"; - EXPECT_FLOAT_EQ(r.horizontal.InDegrees(), 0) << "Addition(1 -45 0)"; - EXPECT_FLOAT_EQ(r.vertical.InDegrees(), 0) << "Addition(1 -45 0)"; + EXPECT_FLOAT_EQ(r.direction.horizontal.InDegrees(), 0) << "Addition(1 -45 0)"; + EXPECT_FLOAT_EQ(r.direction.vertical.InDegrees(), 0) << "Addition(1 -45 0)"; v2 = Spherical16(1, Angle16::Degrees(0), Angle16::Degrees(90)); r = v1 + v2; EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 0 90)"; - EXPECT_FLOAT_EQ(r.horizontal.InDegrees(), 45) << "Addition(1 0 90)"; - EXPECT_FLOAT_EQ(r.vertical.InDegrees(), 45) << "Addition(1 0 90)"; + EXPECT_FLOAT_EQ(r.direction.horizontal.InDegrees(), 45) << "Addition(1 0 90)"; + EXPECT_FLOAT_EQ(r.direction.vertical.InDegrees(), 45) << "Addition(1 0 90)"; } #endif \ No newline at end of file diff --git a/test/Spherical_test.cc b/test/Spherical_test.cc index 7b4c50f..cd8dcad 100644 --- a/test/Spherical_test.cc +++ b/test/Spherical_test.cc @@ -12,22 +12,22 @@ TEST(Spherical, FromVector3) { Spherical s = Spherical::FromVector3(v); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance 0 0 1"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 0.0F) << "s.hor 0 0 1"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert 0 0 1"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 0.0F) << "s.hor 0 0 1"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) << "s.vert 0 0 1"; v = Vector3(0, 1, 0); s = Spherical::FromVector3(v); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance 0 1 0"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 0.0F) << "s.hor 0 1 0"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 90.0F) << "s.vert 0 1 0"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 0.0F) << "s.hor 0 1 0"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 90.0F) << "s.vert 0 1 0"; v = Vector3(1, 0, 0); s = Spherical::FromVector3(v); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance 1 0 0"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 90.0F) << "s.hor 1 0 0"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert 1 0 0"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 90.0F) << "s.hor 1 0 0"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) << "s.vert 1 0 0"; } TEST(Spherical, FromPolar) { @@ -35,36 +35,46 @@ TEST(Spherical, FromPolar) { Spherical s = Spherical::FromPolar(p); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(1 0)"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 0.0F) << "s.hor Polar(1 0)"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert Polar(1 0)"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 0.0F) + << "s.hor Polar(1 0)"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) + << "s.vert Polar(1 0)"; p = Polar(1, Angle::Degrees(45)); s = Spherical::FromPolar(p); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(1 45)"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 45.0F) << "s.hor Polar(1 45)"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert Polar(1 45)"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 45.0F) + << "s.hor Polar(1 45)"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) + << "s.vert Polar(1 45)"; p = Polar(1, Angle::Degrees(-45)); s = Spherical::FromPolar(p); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(1 -45)"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), -45.0F) << "s.hor Polar(1 -45)"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert Polar(1 -45)"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), -45.0F) + << "s.hor Polar(1 -45)"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) + << "s.vert Polar(1 -45)"; p = Polar(0, Angle::Degrees(0)); s = Spherical::FromPolar(p); EXPECT_FLOAT_EQ(s.distance, 0.0F) << "s.distance Polar(0 0)"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 0.0F) << "s.hor Polar(0 0)"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert Polar(0 0)"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 0.0F) + << "s.hor Polar(0 0)"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) + << "s.vert Polar(0 0)"; p = Polar(-1, Angle::Degrees(0)); s = Spherical::FromPolar(p); EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(-1 0)"; - EXPECT_FLOAT_EQ(s.horizontal.InDegrees(), 180.0F) << "s.hor Polar(-1 0)"; - EXPECT_FLOAT_EQ(s.vertical.InDegrees(), 0.0F) << "s.vert Polar(-1 0)"; + EXPECT_FLOAT_EQ(s.direction.horizontal.InDegrees(), 180.0F) + << "s.hor Polar(-1 0)"; + EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F) + << "s.vert Polar(-1 0)"; } TEST(Spherical, Incident1) { @@ -74,8 +84,10 @@ TEST(Spherical, Incident1) { Spherical sr = Spherical(2.49F, Angle::Degrees(98.18f), Angle::Degrees(24.4F)); EXPECT_NEAR(s.distance, sr.distance, 1.0e-01); - EXPECT_NEAR(s.horizontal.InDegrees(), sr.horizontal.InDegrees(), 1.0e-02); - EXPECT_NEAR(s.vertical.InDegrees(), sr.vertical.InDegrees(), 1.0e-02); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), + sr.direction.horizontal.InDegrees(), 1.0e-02); + EXPECT_NEAR(s.direction.vertical.InDegrees(), + sr.direction.vertical.InDegrees(), 1.0e-02); Vector3 r = Vector3(sr); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-02) << "toVector3.x 1 0 0"; @@ -90,8 +102,10 @@ TEST(Spherical, Incident2) { Spherical sr = Spherical(1.4142135623F, Angle::Degrees(45.0f), Angle::Degrees(0.0F)); EXPECT_NEAR(s.distance, sr.distance, 1.0e-05); - EXPECT_NEAR(s.horizontal.InDegrees(), sr.horizontal.InDegrees(), 1.0e-05); - EXPECT_NEAR(s.vertical.InDegrees(), sr.vertical.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), + sr.direction.horizontal.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.vertical.InDegrees(), + sr.direction.vertical.InDegrees(), 1.0e-05); Vector3 r = Vector3(sr); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-06); @@ -103,8 +117,10 @@ TEST(Spherical, Incident2) { sr = Spherical(1.4142135623F, Angle::Degrees(0.0f), Angle::Degrees(45.0F)); EXPECT_NEAR(s.distance, sr.distance, 1.0e-05); - EXPECT_NEAR(s.horizontal.InDegrees(), sr.horizontal.InDegrees(), 1.0e-05); - EXPECT_NEAR(s.vertical.InDegrees(), sr.vertical.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), + sr.direction.horizontal.InDegrees(), 1.0e-05); + EXPECT_NEAR(s.direction.vertical.InDegrees(), + sr.direction.vertical.InDegrees(), 1.0e-05); r = Vector3(sr); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-06); @@ -116,8 +132,8 @@ TEST(Spherical, Incident2) { r = Vector3(s); EXPECT_NEAR(s.distance, 1.73205080F, 1.0e-02); - EXPECT_NEAR(s.horizontal.InDegrees(), 45.0F, 1.0e-02); - EXPECT_NEAR(s.vertical.InDegrees(), 35.26F, 1.0e-02); + EXPECT_NEAR(s.direction.horizontal.InDegrees(), 45.0F, 1.0e-02); + EXPECT_NEAR(s.direction.vertical.InDegrees(), 35.26F, 1.0e-02); EXPECT_NEAR(r.Right(), v.Right(), 1.0e-06); EXPECT_NEAR(r.Up(), v.Up(), 1.0e-06); @@ -145,14 +161,14 @@ TEST(Spherical, Addition) { v2 = Spherical(1, Angle::Degrees(-45), Angle::Degrees(0)); r = v1 + v2; EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 -45 0)"; - EXPECT_FLOAT_EQ(r.horizontal.InDegrees(), 0) << "Addition(1 -45 0)"; - EXPECT_FLOAT_EQ(r.vertical.InDegrees(), 0) << "Addition(1 -45 0)"; + EXPECT_FLOAT_EQ(r.direction.horizontal.InDegrees(), 0) << "Addition(1 -45 0)"; + EXPECT_FLOAT_EQ(r.direction.vertical.InDegrees(), 0) << "Addition(1 -45 0)"; v2 = Spherical(1, Angle::Degrees(0), Angle::Degrees(90)); r = v1 + v2; EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 0 90)"; - EXPECT_FLOAT_EQ(r.horizontal.InDegrees(), 45) << "Addition(1 0 90)"; - EXPECT_FLOAT_EQ(r.vertical.InDegrees(), 45) << "Addition(1 0 90)"; + EXPECT_FLOAT_EQ(r.direction.horizontal.InDegrees(), 45) << "Addition(1 0 90)"; + EXPECT_FLOAT_EQ(r.direction.vertical.InDegrees(), 45) << "Addition(1 0 90)"; } #endif \ No newline at end of file