From 64049fd96482984776a4dc8f95d0a6f3137df5e3 Mon Sep 17 00:00:00 2001 From: Brian Fopiano Date: Mon, 2 Nov 2026 17:37:41 -0500 Subject: [PATCH] Round two review follow-ups - WaterInvariants.held holds a fed start only above MAX_START_LOWERING, as LinkBlend.fixed does - Test that a lake outlet is not held along its lip across a window line, unlike a pond outlet - Test tailouts across chunk borders with a diagonal and a jogged next step - Share the chunk-border comparison between the plunge and tailout tests - Parity test maps roles to palettes with a switch - Parity test asserts some trials have open water under a fall --- .../hydrology/plan/WaterInvariants.java | 7 +- .../raster/ChunkWaterRasterTest.java | 22 ++++++ .../hydrology/raster/RiffleProfileTest.java | 72 +++++++++++++------ ...TerrainNormalActuatorColumnParityTest.java | 27 +++++-- 4 files changed, 99 insertions(+), 29 deletions(-) diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WaterInvariants.java b/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WaterInvariants.java index 6155ffc36..4ea5fb368 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WaterInvariants.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WaterInvariants.java @@ -149,7 +149,8 @@ final class WaterInvariants { boolean[] pool = pool(feeder, receiving(feeder, downstream, feeders.get(downstream.id())), level); int[] box = interior(scene, poolBox(feeder, pool)); if (box != null) { - boolean[] held = held(feeder, lips.getOrDefault(feeder.id(), List.of()), feeders.containsKey(feeder.id())); + boolean heldStart = feeders.containsKey(feeder.id()) && feeder.grade()[0] - level > ConfluenceGrader.MAX_START_LOWERING; + boolean[] held = held(feeder, lips.getOrDefault(feeder.id(), List.of()), heldStart); junctions.add(new Junction(feeder, WaterHeads.snap(level, seaLevel), pool, held, box)); } } @@ -204,10 +205,10 @@ final class WaterInvariants { return lips; } - private static boolean[] held(Reach outlet, List lips, boolean fed) { + private static boolean[] held(Reach outlet, List lips, boolean heldStart) { boolean[] held = new boolean[outlet.xs().length]; boolean lip = !lips.isEmpty(); - held[0] = lip || fed || outlet.style()[0] == ReachStyle.POND_OUTLET; + held[0] = lip || heldStart || outlet.style()[0] == ReachStyle.POND_OUTLET; for (int point = 1; point < held.length; point++) { lip = lip && nearLip(lips, outlet.xs()[point], outlet.zs()[point], outlet.halfWidth()[point]); held[point] = lip || outlet.style()[point] == ReachStyle.POND_OUTLET || zoneStep(outlet, held, point); diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/raster/ChunkWaterRasterTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/raster/ChunkWaterRasterTest.java index 4fef88d0b..4bc6ee46f 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/raster/ChunkWaterRasterTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/raster/ChunkWaterRasterTest.java @@ -958,6 +958,28 @@ public class ChunkWaterRasterTest { assertEquals("the outlet drops into the lower river past its lip", WaterRole.CASCADE, scene.role(501, 200)); } + @Test + public void crossWindowSettlingHoldsAPondsLipButNotALakes() { + HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH); + HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH); + Reach low = line(342L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 62); + Reach shore = line(341L, narrow, low.id(), 486f, 200f, 504f, 200f, (x, z) -> 66); + ReachStyle[] style = shore.style().clone(); + for (int point = 0; point < style.length; point++) { + style[point] = shore.xs()[point] - shore.xs()[0] <= 8f ? ReachStyle.POND_OUTLET : style[point]; + } + Reach outlet = new Reach(shore.id(), shore.tier(), shore.downstreamId(), shore.xs(), shore.zs(), shore.grade(), shore.halfWidth(), + shore.depth(), style, shore.catchment()); + Pond pond = new Pond(340L, PondKind.NATURAL, 66, 58, 490, 202, 67.5f, circle(490, 210, 8, 1), outlet.id(), 0, "water", 490, 210); + Pond lake = new Pond(340L, PondKind.LAKE, 66, 58, 490, 202, 67.5f, circle(490, 210, 8, 1), outlet.id(), 0, "water", 490, 210); + Scene held = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(outlet).reach(low).pond(pond); + Scene free = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(outlet).reach(low).lake(lake); + for (int x = 497; x <= 500; x++) { + assertEquals("a pond's outlet stays at its level along the lip at x=" + x, pond.level(), held.head(x, 200)); + assertEquals("a lake's outlet settles to the lower river along the lip at x=" + x, low.grade()[0], free.head(x, 200)); + } + } + @Test public void sharedOutletWithoutALeadInClampsToTheLastPondInItsPlan() { HydrologyTier river = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH); diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java index 035726092..0e52eb35d 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java @@ -126,27 +126,35 @@ public class RiffleProfileTest { for (int x = -24; x <= 16; x++) { assertTrue("the foot at " + x + "," + (-7 - x) + " is carved", surface.bed(x, -7 - x, 96) < 96); } - for (int chunkX = -2; chunkX <= 1; chunkX++) { - for (int chunkZ = -2; chunkZ <= 1; chunkZ++) { - RiffleProfile first = new RiffleProfile(chunkX, chunkZ, channel(heads)); - RiffleProfile east = new RiffleProfile(chunkX + 1, chunkZ, channel(heads)); - RiffleProfile south = new RiffleProfile(chunkX, chunkZ + 1, channel(heads)); - for (int edge = 0; edge < 16; edge++) { - for (int original : new int[]{92, 96}) { - int x = (chunkX + 1) << 4; - int z = (chunkZ << 4) + edge; - double variation = BedProfile.variation(1337L, x, z); - assertEquals(first.bed(16, edge, original, heads.applyAsInt(x, z), variation), - east.bed(0, edge, original, heads.applyAsInt(x, z), variation)); - x = (chunkX << 4) + edge; - z = (chunkZ + 1) << 4; - variation = BedProfile.variation(1337L, x, z); - assertEquals(first.bed(edge, 16, original, heads.applyAsInt(x, z), variation), - south.bed(edge, 0, original, heads.applyAsInt(x, z), variation)); - } - } - } + assertChunkBordersMatch(heads); + } + + @Test + public void tailoutsMatchAcrossChunkBordersWithADiagonalNextStep() { + IntBinaryOperator heads = (x, z) -> x + z < -7 ? 110 : x + z < -1 ? 98 : 96; + Surface stepped = new Surface(heads); + Surface pool = new Surface((x, z) -> x + z < -7 ? 110 : 98); + for (int x = -24; x <= 16; x++) { + int z = -2 - x; + assertEquals("1-block water over the brink at " + x + "," + z, 97, stepped.bed(x, z, 92)); + assertTrue("the brink at " + x + "," + z + " would lie in the pool without the next step", pool.bed(x, z, 92) < 97); + assertTrue("the foot at " + x + "," + (-7 - x) + " is carved", stepped.bed(x, -7 - x, 96) < 96); } + assertChunkBordersMatch(heads); + } + + @Test + public void tailoutsMatchAcrossChunkBordersWithAJoggedNextStep() { + IntBinaryOperator heads = (x, z) -> x < -3 ? 110 : x < (z < 0 ? 2 : 0) ? 98 : 96; + Surface stepped = new Surface(heads); + Surface pool = new Surface((x, z) -> x < -3 ? 110 : 98); + for (int z = -8; z <= 8; z++) { + int brink = z < 0 ? 1 : -1; + assertEquals("1-block water over the brink at " + brink + "," + z, 97, stepped.bed(brink, z, 92)); + assertTrue("the brink at " + brink + "," + z + " would lie in the pool without the next step", pool.bed(brink, z, 92) < 97); + assertTrue("the foot at z " + z + " is carved", stepped.bed(-3, z, 96) < 96); + } + assertChunkBordersMatch(heads); } @Test @@ -256,6 +264,30 @@ public class RiffleProfileTest { WaterRole at(int x, int z); } + private static void assertChunkBordersMatch(IntBinaryOperator heads) { + for (int chunkX = -2; chunkX <= 1; chunkX++) { + for (int chunkZ = -2; chunkZ <= 1; chunkZ++) { + RiffleProfile first = new RiffleProfile(chunkX, chunkZ, channel(heads)); + RiffleProfile east = new RiffleProfile(chunkX + 1, chunkZ, channel(heads)); + RiffleProfile south = new RiffleProfile(chunkX, chunkZ + 1, channel(heads)); + for (int edge = 0; edge < 16; edge++) { + for (int original : new int[]{92, 96}) { + int x = (chunkX + 1) << 4; + int z = (chunkZ << 4) + edge; + double variation = BedProfile.variation(1337L, x, z); + assertEquals(first.bed(16, edge, original, heads.applyAsInt(x, z), variation), + east.bed(0, edge, original, heads.applyAsInt(x, z), variation)); + x = (chunkX << 4) + edge; + z = (chunkZ + 1) << 4; + variation = BedProfile.variation(1337L, x, z); + assertEquals(first.bed(edge, 16, original, heads.applyAsInt(x, z), variation), + south.bed(edge, 0, original, heads.applyAsInt(x, z), variation)); + } + } + } + } + } + private static final class Surface { private final IntBinaryOperator heads; private final RiffleProfile.Water water; diff --git a/core/src/test/java/art/arcane/iris/generation/stage/IrisTerrainNormalActuatorColumnParityTest.java b/core/src/test/java/art/arcane/iris/generation/stage/IrisTerrainNormalActuatorColumnParityTest.java index eec131a82..0651e9129 100644 --- a/core/src/test/java/art/arcane/iris/generation/stage/IrisTerrainNormalActuatorColumnParityTest.java +++ b/core/src/test/java/art/arcane/iris/generation/stage/IrisTerrainNormalActuatorColumnParityTest.java @@ -42,6 +42,7 @@ import java.util.Map; import java.util.Random; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.ArgumentMatchers.anyInt; @@ -59,10 +60,6 @@ public class IrisTerrainNormalActuatorColumnParityTest { private static final int HEIGHT = 96; private static final int X = 21; private static final int Z = -7; - private static final Map ROLE_PALETTE = Map.of( - WaterRole.CHANNEL, "bed", WaterRole.POND, "bed", WaterRole.MOUTH, "bed", WaterRole.CASCADE, "bed", - WaterRole.WATERFALL, "bed", WaterRole.SHORE, "shore", WaterRole.POND_SHORE, "shore", - WaterRole.DAM, "shore", WaterRole.BANK, "bank"); @Rule public final PlatformBinding platform = PlatformBinding.of(IrisTerrainNormalActuatorColumnParityTest::distinctBlocks); @@ -70,8 +67,10 @@ public class IrisTerrainNormalActuatorColumnParityTest { @Test public void paintedColumnsMatchThePerBlockAlgorithm() { Random random = new Random(20260928L); + int openUnderFallTrials = 0; for (int trial = 0; trial < 600; trial++) { Fixture fixture = new Fixture(random, trial); + openUnderFallTrials += fixture.openUnderFall() ? 1 : 0; Hunk painted = Hunk.newArrayHunk(1, HEIGHT, 1); new IrisTerrainNormalActuator(fixture.engine).paint(X, Z, painted, fixture.context); Hunk expected = Hunk.newArrayHunk(1, HEIGHT, 1); @@ -81,12 +80,22 @@ public class IrisTerrainNormalActuatorColumnParityTest { key(expected.getRaw(0, y, 0)), key(painted.getRaw(0, y, 0))); } } + assertTrue("trials with open water under a fall " + openUnderFallTrials, openUnderFallTrials > 0); } private static String key(NativeBlockState state) { return state == null ? "null" : state.key(); } + private static String rolePalette(WaterRole role) { + return switch (role) { + case CHANNEL, POND, MOUTH, CASCADE, WATERFALL -> "bed"; + case SHORE, POND_SHORE, DAM -> "shore"; + case BANK -> "bank"; + case NONE, INLET -> null; + }; + } + private static IrisPlatform distinctBlocks() { Map blocks = new HashMap<>(); PlatformRegistries registries = mock(PlatformRegistries.class); @@ -215,6 +224,12 @@ public class IrisTerrainNormalActuatorColumnParityTest { return description; } + private boolean openUnderFall() { + boolean wet = role.wet(); + boolean seaFloor = !wet || role == WaterRole.INLET || role == WaterRole.MOUTH; + return wet && seaFloor && fallRole.wet() && fallHead > surfaceFluid; + } + private void reference(Hunk h) { int chunkHeight = h.getHeight(); int xf = 0; @@ -225,7 +240,7 @@ public class IrisTerrainNormalActuatorColumnParityTest { NativeBlockState airState = B.getState("AIR"); boolean wet = role.wet(); boolean seaFloor = !wet || role == WaterRole.INLET || role == WaterRole.MOUTH; - boolean openUnderFall = wet && seaFloor && fallRole.wet() && fallHead > surfaceFluid; + boolean openUnderFall = openUnderFall(); IrisHydrologyMaterials materials = role == WaterRole.INLET ? null : this.materials; int he = Math.min(chunkHeight, this.he); int surfaceFluidHeight = Math.min(chunkHeight, this.surfaceFluid); @@ -241,7 +256,7 @@ public class IrisTerrainNormalActuatorColumnParityTest { Terrain3DColumn naturalColumn = exposeStrata ? terrainColumn : null; int cut = 0; boolean keepGravityAway = materials != null && !materials.isAllowGravityBlocks(); - String paletteName = materials == null ? null : ROLE_PALETTE.get(role); + String paletteName = materials == null ? null : rolePalette(role); NativeBlockState paletteBlock = paletteName == null ? null : palettes.get(paletteName); int paintDepth = paletteBlock == null ? 0 : paletteName.equals("shore") ? materials.getShoreDepth() : 1; NativeBlockState columnFluid = wet ? waterFluid : fluid;