From 33e3949af659a7fed018daf39d2cb6df1ff9e7a3 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 3 Jun 2025 17:37:45 +0200 Subject: [PATCH 1/5] Fixed issues from latest commits --- LinearAlgebra/src/Direction.cs | 7 ++++--- src/Things/TouchSensor.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/LinearAlgebra/src/Direction.cs b/LinearAlgebra/src/Direction.cs index d544d90..863de2b 100644 --- a/LinearAlgebra/src/Direction.cs +++ b/LinearAlgebra/src/Direction.cs @@ -24,10 +24,11 @@ namespace LinearAlgebra { horizontal = 0; vertical = 0; } - // public Direction(Angle horizontal, Angle vertical) { - // this.horizontal = horizontal.inDegrees; + public Direction(Angle horizontal, Angle vertical) { + this.horizontal = horizontal.inDegrees; + this.vertical = vertical.inDegrees; + } - // } // public Direction(float horizontal, float vertical) { // this.horizontal = horizontal; // this.vertical = vertical; diff --git a/src/Things/TouchSensor.cs b/src/Things/TouchSensor.cs index 4235c30..cdeb0dc 100644 --- a/src/Things/TouchSensor.cs +++ b/src/Things/TouchSensor.cs @@ -70,7 +70,7 @@ namespace RoboidControl { touchUpdated = false; return bytes; #else - return 0; + return Array.Empty(); #endif } From 2d78cb24814f43fc17754399b9920743907dd5aa Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 3 Jun 2025 17:47:49 +0200 Subject: [PATCH 2/5] Fix Direction Unit test --- LinearAlgebra/src/Direction.cs | 34 ++++++++++++++++++++++++----- LinearAlgebra/test/DirectionTest.cs | 6 +++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/LinearAlgebra/src/Direction.cs b/LinearAlgebra/src/Direction.cs index 863de2b..7d0b75b 100644 --- a/LinearAlgebra/src/Direction.cs +++ b/LinearAlgebra/src/Direction.cs @@ -27,14 +27,9 @@ namespace LinearAlgebra { public Direction(Angle horizontal, Angle vertical) { this.horizontal = horizontal.inDegrees; this.vertical = vertical.inDegrees; + this.Normalize(); } - // public Direction(float horizontal, float vertical) { - // this.horizontal = horizontal; - // this.vertical = vertical; - // //Normalize(); - // } - public static Direction Degrees(float horizontal, float vertical) { Direction d = new() { horizontal = horizontal, @@ -83,6 +78,33 @@ namespace LinearAlgebra { Vector3Float v = new(x, y, z); return v; } + + public static bool operator ==(Direction d1, Direction d2) { + bool horizontalEq = d1.horizontal == d2.horizontal; + bool verticalEq = d1.vertical == d2.vertical; + return horizontalEq && verticalEq; + } + + public static bool operator !=(Direction d1, Direction d2) { + bool horizontalNEq = d1.horizontal != d2.horizontal; + bool verticalNEq = d1.vertical != d2.vertical; + return horizontalNEq || verticalNEq; + } + + public override bool Equals(object obj) { + if (obj is not Direction d) + return false; + + bool horizontalEq = this.horizontal == d.horizontal; + bool verticalEq = this.vertical == d.vertical; + return horizontalEq && verticalEq; + } + + + public override int GetHashCode() { + return (this.horizontal, this.vertical).GetHashCode(); + } + } } \ No newline at end of file diff --git a/LinearAlgebra/test/DirectionTest.cs b/LinearAlgebra/test/DirectionTest.cs index 3cebe1a..2e099af 100644 --- a/LinearAlgebra/test/DirectionTest.cs +++ b/LinearAlgebra/test/DirectionTest.cs @@ -9,10 +9,12 @@ namespace LinearAlgebra.Test { [Test] public void Compare() { - Direction d = Direction.Degrees(45, 135); + Direction d1 = Direction.Degrees(45, 135); + Direction d2 = new(Angle.Degrees(45), Angle.Degrees(135)); bool r; - r = d == new Direction(Angle.Degrees(45), Angle.Degrees(135)); + r = d1 == d2; Assert.True(r); + Assert.AreEqual(d1, d2); } }; } From 5306dea1a269781d3e7080a57732ebe8ac311dac Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 3 Jun 2025 17:48:55 +0200 Subject: [PATCH 3/5] Fix Angle Construct Unity test --- LinearAlgebra/test/AngleTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LinearAlgebra/test/AngleTest.cs b/LinearAlgebra/test/AngleTest.cs index 00e4981..67110e4 100644 --- a/LinearAlgebra/test/AngleTest.cs +++ b/LinearAlgebra/test/AngleTest.cs @@ -35,7 +35,7 @@ namespace LinearAlgebra.Test { angle = (float)Math.PI * 1.5f; a = Angle.Radians(angle); - Assert.AreEqual(-Math.PI * 0.5f, a.inRadians); + Assert.AreEqual(-Math.PI * 0.5f, a.inRadians, 1.0E-05F); // Revolutions angle = 0.0f; From 8b7316e2ddb21951664cf764adb5956e86eba262 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 3 Jun 2025 17:49:30 +0200 Subject: [PATCH 4/5] Fix Spherical Addition Unity test --- LinearAlgebra/test/SphericalTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LinearAlgebra/test/SphericalTest.cs b/LinearAlgebra/test/SphericalTest.cs index 8539dc0..4ec4429 100644 --- a/LinearAlgebra/test/SphericalTest.cs +++ b/LinearAlgebra/test/SphericalTest.cs @@ -46,7 +46,7 @@ namespace LinearAlgebra.Test { r = v1 + v2; Assert.AreEqual(Math.Sqrt(2), r.distance, 1.0E-05F, "Addition(1 0 90)"); Assert.AreEqual(45.0f, r.direction.horizontal, "Addition(1 0 90)"); - Assert.AreEqual(45.0f, r.direction.vertical, "Addition(1 0 90)"); + Assert.AreEqual(45.0f, r.direction.vertical, 1.0E-05F, "Addition(1 0 90)"); } } } From fd01740d76fd6ffc797b63124ef2991aee16506f Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 3 Jun 2025 17:49:51 +0200 Subject: [PATCH 5/5] Squashed 'LinearAlgebra/' changes from 9b2a047..493c19c 493c19c Fix ToVector3 35b6830 Support sending poses from Unity changes 6d74649 Compatibility git-subtree-dir: LinearAlgebra git-subtree-split: 493c19cbe22465ead382a42ff952b06a24f60dda --- src/Spherical.cs | 2 +- src/SwingTwist.cs | 9 ++++++++- test/DirectionTest.cs | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Spherical.cs b/src/Spherical.cs index 183aa01..e138e7c 100644 --- a/src/Spherical.cs +++ b/src/Spherical.cs @@ -106,7 +106,7 @@ namespace LinearAlgebra { // } public Vector3 ToVector3() { - float verticalRad = (float)(Math.PI / 2 - this.direction.vertical) * Angle.Deg2Rad; + float verticalRad = (float)(90 - this.direction.vertical) * Angle.Deg2Rad; float horizontalRad = this.direction.horizontal * Angle.Deg2Rad; float cosVertical = (float)Math.Cos(verticalRad); float sinVertical = (float)Math.Sin(verticalRad); diff --git a/src/SwingTwist.cs b/src/SwingTwist.cs index 22eb0bb..58c1a1a 100644 --- a/src/SwingTwist.cs +++ b/src/SwingTwist.cs @@ -29,11 +29,18 @@ namespace LinearAlgebra { } #if UNITY_5_3_OR_NEWER + public static SwingTwist FromQuaternion(Quaternion q) { + // q.ToAngles(out float right, out float up, out float forward); + UnityEngine.Vector3 angles = q.eulerAngles; + SwingTwist r = new SwingTwist(angles.y, angles.x, angles.z); + return r; + } + public Quaternion ToQuaternion() { Quaternion q = Quaternion.Euler(-this.swing.vertical, this.swing.horizontal, this.twist); - return q; + return q; } #endif } diff --git a/test/DirectionTest.cs b/test/DirectionTest.cs index e31af4c..3cebe1a 100644 --- a/test/DirectionTest.cs +++ b/test/DirectionTest.cs @@ -1,3 +1,4 @@ +#if !UNITY_5_6_OR_NEWER using NUnit.Framework; namespace LinearAlgebra.Test { @@ -14,4 +15,5 @@ namespace LinearAlgebra.Test { Assert.True(r); } }; -} \ No newline at end of file +} +#endif \ No newline at end of file