Lowest water owns confluences

- Add ReachCursor.Waters, which keeps the nearest covering segment per reach and resolves the channel owner by planned head, then wider half-width, distance, id and segment
- Offer covering segments to Waters in ReachSegments.evaluate and resolve the owner at the end of every nearest lookup
- Prune channel candidates by segment radius once the scope is CHANNEL or any water covers the column
- Cut channel and trench beds to the deepest bed among covering reaches whose snapped head equals the owner's head
- Add ChunkWaterRasterTest.receivingRiverOwnsItsFootprintAtAConfluence
- Flip the PlannedSceneTest confluence tongue cases to expect no tongue
- Expect the wider equal-level channel in ReachIndexTest and the lowest covering channel in PondChannelSettlementTest
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 16:41:40 -05:00
1 parent a06f487279
commit 06bd50d1a0
7 files changed
+168 -38

No files matched your search

@@ -50,19 +50,19 @@ public class PlannedSceneTest {
}
@Test
public void reproducesTodaysConfluenceTongue() {
public void confluenceHasNoTongueAtEitherTributaryLevel() {
HydrologySettings settings = PlannedScene.packSettings(SEED);
for (int tributaryLevel : new int[]{70, 66}) {
List<Long> tongues = tongues(settings, new int[]{144, 136}, new int[]{144, 56}, (x, z) -> z >= 136 ? 66 : tributaryLevel, true);
assertEquals("tributary at " + tributaryLevel, tributaryLevel == 70 ? List.of(303L) : List.of(), tongues);
assertEquals("tributary at " + tributaryLevel, List.of(), tongues);
}
}
@Test
public void confluenceTonguesCoverSiblingFootprintsOutsideTheDownstreamCap() {
public void confluenceHasNoTongueInsideTheSiblingChannel() {
HydrologySettings settings = PlannedScene.packSettings(SEED);
IntBinaryOperator perchedUpstream = (x, z) -> x >= 128 ? 66 : 70;
assertEquals("perched tributary inside the sibling channel", List.of(303L),
assertEquals("perched tributary inside the sibling channel", List.of(),
tongues(settings, new int[]{144, 136}, new int[]{48, 112}, perchedUpstream, true));
assertEquals("without the sibling the perched stretch lies outside the downstream cap", List.of(),
tongues(settings, new int[]{144, 136}, new int[]{48, 112}, perchedUpstream, false));
@@ -588,6 +588,27 @@ public class ChunkWaterRasterTest {
}
}
@Test
public void receivingRiverOwnsItsFootprintAtAConfluence() {
HydrologyTier river = tier("river", 8f, 1f, 16, IrisBankStyle.SMOOTH);
HydrologyTier stream = tier("stream", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
Reach below = line(302L, river, 0L, 16f, 8f, 120f, 8f, (x, z) -> 66);
Reach main = line(301L, river, below.id(), -96f, 8f, 16f, 8f, (x, z) -> 66);
for (int tributaryLevel : new int[]{70, 66}) {
Reach tributary = line(303L, stream, below.id(), 16f, -72f, 16f, 8f, (x, z) -> z >= 8f ? 66 : tributaryLevel);
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(main).reach(tributary).reach(below);
for (int x = -16; x <= 48; x++) {
for (int z = 0; z <= 16; z++) {
assertEquals("river head at " + x + "," + z, 66, scene.head(x, z));
if (tributaryLevel == 66 && Math.abs(z - 8) <= 2) {
assertTrue("river bed under the tributary mouth at " + x + "," + z, scene.terrain(x, z) <= 63);
}
}
}
assertEquals("the tributary keeps its own water upstream", tributaryLevel, scene.head(16, -24));
}
}
@Test
public void crossWindowLinkNeverRaisesWaterDownstream() {
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
@@ -60,16 +60,17 @@ public class PondChannelSettlementTest {
}
@Test
public void nearerChannelsAndIdentityTiesMatchTheRasterWinner() {
public void theLowestCoveringChannelSettlesThePondLikeTheRasterOwner() {
Pond pond = pond(1L, PondKind.CHAINED, 100, circle(0, 0, 4));
Reach lower = line(4L, 2, -20, 2, 20, 8f, 94, 94);
Reach nearer = line(3L, 0, -20, 0, 20, 8f, 100, 100);
Pond single = pond(2L, PondKind.NATURAL, 100, circle(0, 0, 0));
Reach tied = line(3L, 2, -20, 2, 20, 8f, 100, 100);
Reach alongside = line(3L, 2, -20, 2, 20, 8f, 100, 100);
assertEquals(100, settle(List.of(lower, nearer), single));
assertEquals(100, settle(List.of(lower, tied), pond));
assertEquals(100, settle(List.of(tied, lower), pond));
assertEquals(94, settle(List.of(lower, nearer), single));
assertEquals(94, settle(List.of(nearer, lower), single));
assertEquals(94, settle(List.of(lower, alongside), pond));
assertEquals(94, settle(List.of(alongside, lower), pond));
}
@Test
@@ -117,10 +117,12 @@ public class ReachIndexTest {
assertEquals(0.85f, hit.t(), 1e-6f);
assertEquals(8f, hit.distance(), 1e-5f);
}
ReachHit both = ReachIndex.nearest(List.of(trunk, tributary), 20.5D, 6D);
assertSame("inside both channels the nearer covering centre wins", tributary, both.reach());
assertEquals(ReachHit.Coverage.CHANNEL, both.coverage());
assertEquals(0.5f, both.distance(), 1e-5f);
for (List<Reach> candidates : List.of(List.of(tributary, trunk), List.of(trunk, tributary))) {
ReachHit both = ReachIndex.nearest(candidates, 20.5D, 6D);
assertSame("inside both channels at one level the wider channel owns the column", trunk, both.reach());
assertEquals(ReachHit.Coverage.CHANNEL, both.coverage());
assertEquals(6f, both.distance(), 1e-5f);
}
}
@Test