height-bound samples

This commit is contained in:
Brian Neumann-Fopiano
2026-08-15 13:21:11 -04:00
parent a7baa1c1b9
commit 33638eadd7
2 changed files with 41 additions and 0 deletions
@@ -426,6 +426,10 @@ public class IrisComplex implements DataProvider {
double fz = (z - gz) / grid;
long b00 = cornerBounds(cache, engine, interpolator, interpolatorIndex, generators, gx, gz);
if (fx == 0D && fz == 0D) {
return new NoiseBounds(boundsLow(b00), boundsHigh(b00));
}
long b10 = cornerBounds(cache, engine, interpolator, interpolatorIndex, generators, gx + grid, gz);
long b01 = cornerBounds(cache, engine, interpolator, interpolatorIndex, generators, gx, gz + grid);
long b11 = cornerBounds(cache, engine, interpolator, interpolatorIndex, generators, gx + grid, gz + grid);
@@ -48,6 +48,19 @@ public class IrisComplexGridBoundsCacheTest {
assertEquals(1, interpolator.getInvocations());
}
@Test
public void alignedGridSampleUsesOnlyTheContributingCorner() throws Exception {
IrisComplex complex = createComplex();
Method gridSampleBounds = gridSampleBoundsMethod();
CountingInterpolator interpolator = new CountingInterpolator(3.5D, 7.25D);
NoiseBounds bounds = invokeGridSampleBounds(complex, gridSampleBounds, interpolator, 64D, -32D);
assertEquals(3.5F, bounds.min(), 0D);
assertEquals(7.25F, bounds.max(), 0D);
assertEquals(1, interpolator.getInvocations());
}
private IrisComplex createComplex() throws Exception {
IrisComplex complex = mock(IrisComplex.class, CALLS_REAL_METHODS);
@@ -89,6 +102,20 @@ public class IrisComplexGridBoundsCacheTest {
return method;
}
private Method gridSampleBoundsMethod() throws Exception {
Method method = IrisComplex.class.getDeclaredMethod(
"gridSampleBounds",
Engine.class,
IrisInterpolator.class,
int.class,
IrisGenerator[].class,
double.class,
double.class
);
method.setAccessible(true);
return method;
}
private long invokeCornerBounds(IrisComplex complex, Method method, IrisInterpolator interpolator, int x, int z) throws Exception {
Field gridBoundsCache = IrisComplex.class.getDeclaredField("gridBoundsCache");
gridBoundsCache.setAccessible(true);
@@ -96,6 +123,16 @@ public class IrisComplexGridBoundsCacheTest {
return (long) method.invoke(complex, cache.get(), null, interpolator, 0, new IrisGenerator[0], x, z);
}
private NoiseBounds invokeGridSampleBounds(
IrisComplex complex,
Method method,
IrisInterpolator interpolator,
double x,
double z
) throws Exception {
return (NoiseBounds) method.invoke(complex, null, interpolator, 0, new IrisGenerator[0], x, z);
}
private float unpackLow(long packed) {
return Float.intBitsToFloat((int) (packed >>> 32));
}