This repository has been archived on 2026-10-29. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
CultMath/tests/CultMath.Tests/PlanetaryPatchTests.cs
2026-07-13 02:14:11 +01:00

40 lines
1.3 KiB
C#

using Xunit;
namespace CultMath.Tests;
public sealed class PlanetaryPatchTests
{
[Fact]
public void CubeSpherePatchMeshUsesCanonicalTopology()
{
var meshes = PlanetaryPatch.CreateCubeSphere(8);
Assert.Equal(6, meshes.Length);
foreach (var mesh in meshes)
{
Assert.Equal(81, mesh.Vertices.Length);
Assert.Equal(8 * 8 * 6, mesh.Indices.Length);
Assert.All(mesh.Vertices, vertex => Assert.Equal(1, math.length(vertex.UnitDirection), 5));
foreach (var index in mesh.Indices) Assert.InRange(index, 0, mesh.Vertices.Length - 1);
}
}
[Fact]
public void NeighborFaceCornersAreSingleValued()
{
var directions = PlanetaryPatch.CreateCubeSphere(1)
.SelectMany(mesh => mesh.Vertices.Select(vertex => vertex.UnitDirection))
.ToArray();
var groups = directions.GroupBy(direction => new
{
X = Math.Sign(direction.x),
Y = Math.Sign(direction.y),
Z = Math.Sign(direction.z),
});
Assert.Equal(8, groups.Count());
Assert.All(groups, group =>
{
var first = group.First();
Assert.All(group, direction => Assert.InRange(math.distance(first, direction), 0, 1.0e-6f));
});
}
}