Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/FixedMathSharp/Numerics/Fixed64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand All @@ -260,23 +260,23 @@ 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;
}

/// <summary>
/// Adds a float to x
/// </summary>
public static Fixed64 operator +(Fixed64 x, float y)
{
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) + y);
return x + (Fixed64)y;
}

/// <summary>
/// Adds a Fixed64 to x
/// </summary>
public static Fixed64 operator +(float x, Fixed64 y)
{
return y + x;
return (Fixed64)x + y;
}

/// <summary>
Expand All @@ -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;
}

/// <summary>
Expand All @@ -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;
}

/// <summary>
Expand All @@ -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;
}

/// <summary>
Expand All @@ -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;
}

/// <summary>
Expand Down Expand Up @@ -401,15 +401,15 @@ 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;
}

/// <summary>
/// Multiplies an integer by a
/// </summary>
public static Fixed64 operator *(int x, Fixed64 y)
{
return y * x;
return (Fixed64)x * y;
}

/// <summary>
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions tests/FixedMathSharp.Tests/Fixed4x4.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}.");
}
Expand Down Expand Up @@ -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)));
}

Expand All @@ -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)));
}

Expand Down
6 changes: 3 additions & 3 deletions tests/FixedMathSharp.Tests/FixedQuaternion.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/FixedMathSharp.Tests/Vector3d.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading