Make spherical erosion diagnostics finite

This commit is contained in:
Meta Vens 2026-07-13 00:41:25 +01:00
commit e870663fe0
2 changed files with 8 additions and 1 deletions

View file

@ -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);

View file

@ -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);