fix: reject non-finite isoValue and origin in Extract
samples and cellSize were validated but isoValue and origin were not: iso = NaN or +inf silently returned an empty mesh, and origin = NaN gave NaN positions. Extend Extract's existing top-of-method validation authority to reject non-finite isoValue and non-finite origin components with ArgumentException, matching the existing style, with tests for each component. Overflow at extreme magnitudes (cellSize ~3e38, or finite samples whose interpolation overflows to inf) is a separate, float-domain limit rather than a validated-input error; documented in the XML doc and provenance notes, deliberately not range-checked. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
bef3d3eba3
commit
d64de1b69d
3 changed files with 56 additions and 0 deletions
|
|
@ -29,6 +29,18 @@ namespace GameCult.Geometry
|
|||
/// Extracts the <paramref name="isoValue"/> surface with surface nets.
|
||||
/// Values less than or equal to the isovalue are treated as inside.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="samples"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// <paramref name="samples"/> is too small or has a non-finite sample, or
|
||||
/// <paramref name="isoValue"/> or a component of <paramref name="origin"/> is non-finite.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="cellSize"/> is non-positive or infinite.</exception>
|
||||
/// <remarks>
|
||||
/// Non-finite results from otherwise-finite inputs (for example an extreme
|
||||
/// <paramref name="cellSize"/> or samples near float's magnitude limit producing an
|
||||
/// infinite vertex position) are a float-domain overflow, not a validated input error;
|
||||
/// this method does not range-check magnitudes for that case.
|
||||
/// </remarks>
|
||||
public static CultGeometryQuadMesh Extract(
|
||||
float[,,] samples,
|
||||
float isoValue = 0f,
|
||||
|
|
@ -49,6 +61,16 @@ namespace GameCult.Geometry
|
|||
}
|
||||
}
|
||||
|
||||
if (!float.IsFinite(isoValue))
|
||||
{
|
||||
throw new ArgumentException("The isovalue must be finite.", nameof(isoValue));
|
||||
}
|
||||
|
||||
if (!float.IsFinite(origin.X) || !float.IsFinite(origin.Y) || !float.IsFinite(origin.Z))
|
||||
{
|
||||
throw new ArgumentException("The origin must be finite.", nameof(origin));
|
||||
}
|
||||
|
||||
if (!(cellSize > 0f) || float.IsInfinity(cellSize))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(cellSize), "Cell size must be finite and positive.");
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ Deliberate behavior:
|
|||
rule never looks at its geometry;
|
||||
- non-finite `isoValue` or `origin` components are rejected, matching the
|
||||
existing rejection of non-finite samples and cell size;
|
||||
- an extreme but finite input (a `cellSize` near float's magnitude limit, or
|
||||
finite samples whose interpolated position overflows to infinity) is a
|
||||
float-domain overflow, not a validated input error, and is deliberately not
|
||||
range-checked;
|
||||
- vertices are welded: one vertex per active cell, shared by every quad
|
||||
touching that cell;
|
||||
- face-weighted normals sum each quad's diagonal cross product (unnormalized,
|
||||
|
|
|
|||
|
|
@ -626,6 +626,36 @@ namespace GameCult.Geometry.Tests
|
|||
act.Should().Throw<ArgumentOutOfRangeException>();
|
||||
}
|
||||
|
||||
[TestCase(float.NegativeInfinity)]
|
||||
[TestCase(float.PositiveInfinity)]
|
||||
[TestCase(float.NaN)]
|
||||
public void A_non_finite_isoValue_is_rejected(float nonFiniteValue)
|
||||
{
|
||||
var samples = new float[2, 2, 2];
|
||||
|
||||
Action act = () => CultGeometrySurfaceNets.Extract(samples, isoValue: nonFiniteValue);
|
||||
|
||||
act.Should().Throw<ArgumentException>();
|
||||
}
|
||||
|
||||
[TestCase(float.NegativeInfinity, 0f, 0f)]
|
||||
[TestCase(float.PositiveInfinity, 0f, 0f)]
|
||||
[TestCase(float.NaN, 0f, 0f)]
|
||||
[TestCase(0f, float.NegativeInfinity, 0f)]
|
||||
[TestCase(0f, float.PositiveInfinity, 0f)]
|
||||
[TestCase(0f, float.NaN, 0f)]
|
||||
[TestCase(0f, 0f, float.NegativeInfinity)]
|
||||
[TestCase(0f, 0f, float.PositiveInfinity)]
|
||||
[TestCase(0f, 0f, float.NaN)]
|
||||
public void A_non_finite_origin_component_is_rejected(float x, float y, float z)
|
||||
{
|
||||
var samples = new float[2, 2, 2];
|
||||
|
||||
Action act = () => CultGeometrySurfaceNets.Extract(samples, origin: new CultVec3(x, y, z));
|
||||
|
||||
act.Should().Throw<ArgumentException>();
|
||||
}
|
||||
|
||||
[TestCase(float.NegativeInfinity)]
|
||||
[TestCase(float.PositiveInfinity)]
|
||||
[TestCase(float.NaN)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue