diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/plan/ConfluenceIncisionTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/plan/ConfluenceIncisionTest.java index 7230ad39e..3a67e2770 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/plan/ConfluenceIncisionTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/plan/ConfluenceIncisionTest.java @@ -26,6 +26,7 @@ public class ConfluenceIncisionTest { private static final double WALL_HEIGHT = 60D; private static final double WALL_FACE_REACH = 24D; private static final double MAX_WALL_CUT = 35D; + private static final double MAX_MEAN_WALL_CUT = 30D; private static final int MAX_COPY_DIFFERENCE = 4; private static PlannedScene valley; @@ -67,6 +68,8 @@ public class ConfluenceIncisionTest { @Test public void majorDownAWallBesideTheValleyRiverFollowsTheWall() { HydrologySettings settings = settings(); + double totalCut = 0D; + int feet = 0; for (double foot = WALL_FOOT - 4D; foot <= WALL_FOOT + 4D; foot += 1D) { SyntheticTerrain terrain = SyntheticTerrain.valleyBelowAWall(foot, WALL_RUN, WALL_HEIGHT); PlannedScene scene = PlannedScene.plan(terrain, settings, 2, 2); @@ -91,7 +94,11 @@ public class ConfluenceIncisionTest { assertTrue("foot " + foot + " " + major + " is cut " + cut + " into the wall", cut <= MAX_WALL_CUT); double tallestFall = WALL_HEIGHT / 2D + major.tier().waterfallMinimumDrop(); assertTrue("foot " + foot + " " + major + " falls " + largest + " blocks at once down a " + WALL_HEIGHT + "-block wall", largest <= tallestFall); + totalCut += cut; + feet++; } + double meanCut = totalCut / feet; + assertTrue("mean cut into the wall over " + feet + " feet is " + meanCut, meanCut <= MAX_MEAN_WALL_CUT); } @Test diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WindowPlannerTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WindowPlannerTest.java index f491a07ac..57256a65a 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WindowPlannerTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/plan/WindowPlannerTest.java @@ -965,20 +965,7 @@ public class WindowPlannerTest { } } assertTrue("reach points crossing the sea sliver at x " + stripX + ": " + crossing, crossing > 0); - Map ponds = new HashMap<>(); - for (Pond pond : scene.ponds()) { - ponds.put(pond.id(), pond); - } - int away = 0; - for (Pond pond : dry.ponds()) { - if (Math.abs(pond.floorX() - stripX) <= SLIVER_REACH || touchedByAChangedReach(pond, dry, scene)) { - continue; - } - away++; - Pond kept = ponds.get(pond.id()); - assertNotNull(pond + " away from the sea sliver at x " + stripX + " is kept", kept); - assertEquals(pond + " level with the sea sliver at x " + stripX, pond.level(), kept.level()); - } + int away = assertPondsOffTheSliverChainAreKept(dry, scene, stripX); assertTrue("ponds away from the sea sliver at x " + stripX + ": " + away, away > 10); int cuts = deepCuts(scene); assertTrue("reach points cut more than " + DEEP_CUT + " below the ground with the sliver at x " + stripX + ": " + cuts + ", without it " @@ -986,19 +973,66 @@ public class WindowPlannerTest { } } - private static boolean touchedByAChangedReach(Pond pond, PlannedScene dry, PlannedScene scene) { - Set unchanged = new HashSet<>(scene.reaches()); - for (Reach reach : dry.reaches()) { - if (unchanged.contains(reach)) { + private static int assertPondsOffTheSliverChainAreKept(PlannedScene dry, PlannedScene scene, double stripX) { + Map ponds = new HashMap<>(); + for (Pond pond : scene.ponds()) { + ponds.put(pond.id(), pond); + } + Set exempt = pondsDownstreamOfTheSliver(dry, stripX); + int away = 0; + for (Pond pond : dry.ponds()) { + if (exempt.contains(pond.id())) { continue; } - for (int point = 0; point < reach.xs().length; point++) { - if (pond.mask().nearest(reach.xs()[point], reach.zs()[point], reach.halfWidth()[point] + 2f) != null) { - return true; + away++; + Pond kept = ponds.get(pond.id()); + assertNotNull(pond + " off the sea sliver's downstream chain at x " + stripX + " is kept", kept); + assertEquals(pond + " level with the sea sliver at x " + stripX, pond.level(), kept.level()); + } + return away; + } + + private static Set pondsDownstreamOfTheSliver(PlannedScene dry, double stripX) { + Map reaches = new HashMap<>(); + for (Reach reach : dry.reaches()) { + reaches.put(reach.id(), reach); + } + Set chain = new HashSet<>(); + List frontier = new ArrayList<>(); + for (Reach reach : dry.reaches()) { + for (float x : reach.xs()) { + if (Math.abs(x - stripX) <= SLIVER_REACH) { + chain.add(reach.id()); + frontier.add(reach); + break; } } } - return false; + Set exempt = new HashSet<>(); + for (Pond pond : dry.ponds()) { + if (Math.abs(pond.floorX() - stripX) <= SLIVER_REACH) { + exempt.add(pond.id()); + follow(reaches.get(pond.outletReachId()), chain, frontier); + } + } + for (int index = 0; index < frontier.size(); index++) { + Reach reach = frontier.get(index); + follow(reaches.get(reach.downstreamId()), chain, frontier); + int last = reach.xs().length - 1; + for (Pond pond : dry.ponds()) { + if (pond.mask().nearest(reach.xs()[last], reach.zs()[last], reach.halfWidth()[last] + 2f) != null) { + exempt.add(pond.id()); + follow(reaches.get(pond.outletReachId()), chain, frontier); + } + } + } + return exempt; + } + + private static void follow(Reach reach, Set chain, List frontier) { + if (reach != null && chain.add(reach.id())) { + frontier.add(reach); + } } private static int deepCuts(PlannedScene scene) {