diff --git a/src/CultMath/float3.cs b/src/CultMath/float3.cs index e9833ae..4a4efeb 100644 --- a/src/CultMath/float3.cs +++ b/src/CultMath/float3.cs @@ -67,6 +67,8 @@ public record struct float3(float x, float y, float z) public static explicit operator System.Numerics.Vector3(float3 value) => new(value.x, value.y, value.z); public static explicit operator float3(System.Numerics.Vector3 value) => new(value.X, value.Y, value.Z); + public override readonly string ToString() => $"float3({x:R}, {y:R}, {z:R})"; + public static float3 operator +(float3 value) => value; public static float3 operator -(float3 value) => new(-value.x, -value.y, -value.z); public static float3 operator +(float3 left, float3 right) => new(left.x + right.x, left.y + right.y, left.z + right.z); diff --git a/tests/CultMath.Tests/SphericalErosionTests.cs b/tests/CultMath.Tests/SphericalErosionTests.cs index 53d37bc..f634ba6 100644 --- a/tests/CultMath.Tests/SphericalErosionTests.cs +++ b/tests/CultMath.Tests/SphericalErosionTests.cs @@ -9,9 +9,14 @@ public sealed class SphericalErosionTests { var parameters = SphericalErosionParameters.Default with { Seed = 42.0f }; var a = SphericalErosion.Sample(new float3(0.31f, -0.74f, 0.59f), 0.2f, new float3(0.4f, -0.1f, 0.2f), parameters); + var repeated = SphericalErosion.Sample(new float3(0.31f, -0.74f, 0.59f), 0.2f, new float3(0.4f, -0.1f, 0.2f), parameters); var b = SphericalErosion.Sample(new float3(3.1f, -7.4f, 5.9f), 0.2f, new float3(0.4f, -0.1f, 0.2f), parameters); - Assert.Equal(a, b); + Assert.Equal(a, repeated); + Assert.InRange(math.abs(a.HeightOffset-b.HeightOffset),0.0f,1.0e-6f); + Assert.InRange(math.abs(a.Ridge-b.Ridge),0.0f,1.0e-6f); + Assert.InRange(math.abs(a.Gully-b.Gully),0.0f,5.0e-5f); + Assert.InRange(math.length(a.Gradient-b.Gradient),0.0f,5.0e-6f); Assert.InRange(a.HeightOffset, -0.08f, 0.08f); Assert.InRange(a.Ridge, 0.0f, 1.0f); Assert.InRange(a.Gully, 0.0f, 1.0f);