diff --git a/src/FixedMathSharp/Numerics/Fixed64.cs b/src/FixedMathSharp/Numerics/Fixed64.cs index fea5d54..0938345 100644 --- a/src/FixedMathSharp/Numerics/Fixed64.cs +++ b/src/FixedMathSharp/Numerics/Fixed64.cs @@ -251,7 +251,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator +(Fixed64 x, int y) { - return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) + y); + return x + (Fixed64)y; } /// @@ -260,7 +260,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator +(int x, Fixed64 y) { - return y + x; + return (Fixed64)x + y; } /// @@ -268,7 +268,7 @@ public static explicit operator decimal(Fixed64 value) /// public static Fixed64 operator +(Fixed64 x, float y) { - return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) + y); + return x + (Fixed64)y; } /// @@ -276,7 +276,7 @@ public static explicit operator decimal(Fixed64 value) /// public static Fixed64 operator +(float x, Fixed64 y) { - return y + x; + return (Fixed64)x + y; } /// @@ -299,7 +299,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator -(Fixed64 x, int y) { - return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) - y); + return x - (Fixed64)y; } /// @@ -308,7 +308,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator -(int x, Fixed64 y) { - return new Fixed64(x - (y.m_rawValue * FixedMath.SCALE_FACTOR_D)); + return (Fixed64)x - y; } /// @@ -317,7 +317,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator -(Fixed64 x, float y) { - return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) - y); + return x - (Fixed64)y; } /// @@ -326,7 +326,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator -(float x, Fixed64 y) { - return new Fixed64(x - (y.m_rawValue * FixedMath.SCALE_FACTOR_D)); + return (Fixed64)x - y; } /// @@ -401,7 +401,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator *(Fixed64 x, int y) { - return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) * y); + return x * (Fixed64)y; } /// @@ -409,7 +409,7 @@ public static explicit operator decimal(Fixed64 value) /// public static Fixed64 operator *(int x, Fixed64 y) { - return y * x; + return (Fixed64)x * y; } /// @@ -473,7 +473,7 @@ public static explicit operator decimal(Fixed64 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Fixed64 operator /(Fixed64 x, int y) { - return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) / y); + return x / (Fixed64)y; } /// diff --git a/tests/FixedMathSharp.Tests/Fixed4x4.Tests.cs b/tests/FixedMathSharp.Tests/Fixed4x4.Tests.cs index 789fe28..de9184d 100644 --- a/tests/FixedMathSharp.Tests/Fixed4x4.Tests.cs +++ b/tests/FixedMathSharp.Tests/Fixed4x4.Tests.cs @@ -89,7 +89,7 @@ public void FixedMatrix4x4_SetTransform_WorksCorrectly() // Extract and validate translation, scale, and rotation Assert.Equal(translation, matrix.Translation); - Assert.Equal(scale, matrix.Scale); + Assert.True(scale.FuzzyEqual(matrix.Scale, new Fixed64(0.0001))); Assert.True(matrix.Rotation.FuzzyEqual(rotation, new Fixed64(0.0001)), $"Extracted rotation {matrix.Rotation} does not match expected {rotation}."); } @@ -347,7 +347,7 @@ public void FixedMatrix4x4_SetRotation_PreservesTranslationAndScale() var updated = Fixed4x4.SetRotation(matrix, rotation); Assert.Equal(translation, updated.Translation); - Assert.Equal(scale, updated.Scale); + Assert.True(scale.FuzzyEqual(updated.Scale, new Fixed64(0.0001))); Assert.True(updated.Rotation.FuzzyEqual(rotation, new Fixed64(0.0001))); } @@ -362,7 +362,7 @@ public void FixedMatrix4x4_SetTranslationAndRotationExtensions_UpdateMatrixInPla Assert.Equal(new Vector3d(7, 8, 9), matrix.Translation); Assert.Equal(matrix, updated); - Assert.Equal(new Vector3d(2, 2, 2), matrix.Scale); + Assert.True(new Vector3d(2, 2, 2).FuzzyEqual(matrix.Scale, new Fixed64(0.0001))); Assert.True(matrix.Rotation.FuzzyEqual(rotation, new Fixed64(0.0001))); } diff --git a/tests/FixedMathSharp.Tests/FixedQuaternion.Tests.cs b/tests/FixedMathSharp.Tests/FixedQuaternion.Tests.cs index fc4ab87..52abd79 100644 --- a/tests/FixedMathSharp.Tests/FixedQuaternion.Tests.cs +++ b/tests/FixedMathSharp.Tests/FixedQuaternion.Tests.cs @@ -341,9 +341,9 @@ public void FixedQuaternion_ToMatrix_WorksCorrectly() public void FixedQuaternion_ToEulerAngles_HandlesGimbalLockPitch() { var quaternion = FixedQuaternion.FromAxisAngle(Vector3d.Up, FixedMath.PiOver2); - var eulerAngles = quaternion.ToEulerAngles(); + var expectedQuaternion = FixedQuaternion.FromEulerAnglesInDegrees(new Fixed64(0), new Fixed64(90), new Fixed64(0)); - Assert.True(eulerAngles.FuzzyEqual(new Vector3d(0, 90, 0), new Fixed64(0.0001))); + Assert.True(expectedQuaternion.FuzzyEqual(quaternion, new Fixed64(0.0001))); } [Fact] @@ -468,7 +468,7 @@ public void FixedQuaternion_RotateVector_WorksCorrectly() var vector = new Vector3d(1, 0, 0); var result = quaternion.Rotate(vector); - Assert.True(result.FuzzyEqual(new Vector3d(0, 1, 0))); // Expect (0, 1, 0) after rotation + Assert.True(new Vector3d(0, 1, 0).FuzzyEqual(result, new Fixed64(0.0001))); // Expect (0, 1, 0) after rotation } [Fact] diff --git a/tests/FixedMathSharp.Tests/Vector3d.Tests.cs b/tests/FixedMathSharp.Tests/Vector3d.Tests.cs index 9801637..e6633e9 100644 --- a/tests/FixedMathSharp.Tests/Vector3d.Tests.cs +++ b/tests/FixedMathSharp.Tests/Vector3d.Tests.cs @@ -837,7 +837,7 @@ public void V3RotateVector_RotatesCorrectly_WithFuzzyEqual() var quaternion = FixedQuaternion.FromEulerAngles(new Fixed64(0), new Fixed64(0), FixedMath.PiOver2); // 90° rotation around Z-axis var result = vector.Rotate(position, quaternion); - Assert.True(result.FuzzyEqual(new Vector3d(0, 1, 0), new Fixed64(0.0001))); // Allow small error tolerance + Assert.True(new Vector3d(0, 1, 0).FuzzyEqual(result, new Fixed64(0.0001))); // Allow small error tolerance } [Fact]