Plunge pools below falls

- RiffleProfile carves a plunge pool at the foot of every head step of 6 or more blocks in channel water: depth round(0.5 x drop x (0.85 + 0.15 x variation)) clamped to 2..8, radius clamp(0.75 x drop, 3, 12), one distance field per foot and top head pair that spreads only through the foot level, LIMIT kept at 160
- Riffle crests at least 5 blocks above a cell's sill no longer raise its bed, so the foot of a large fall stays deep while the brink keeps its head-1 sill
- Plunge pools never seed in or carve pond, lake, sea inlet or mouth columns
- The riffle raise below a step between two different channel reaches leaves the lower channel's bed alone (spec 11 design D); fields are keyed by crest level, feature and flowing role
- RiffleProfile samples head, feature and role per column through a Water sampler; WaterRole.flowing names the channel, cascade and waterfall roles
- RasterComposer styles a channel column below another channel reach's water 2 or more blocks higher as CASCADE, or WATERFALL from the higher reach's waterfallMinimumDrop
- ReachShaper.styles takes the sea level and styles a one-block drop out of an outlet zone or held lip as CASCADE when the head snap shows it as a two-block step; LinkBlend restyles with the same rule
- LinkBlend.settleInto holds a cross-window feeder's start only for a pond lip, a pond outlet or a fed start more than one block above the junction, the in-window p0cap1 rule
- Tests: plunge pool, chunk-border and standing-water RiffleProfile cases, receiving bed below a joining cascade, styled lower-channel edges, falls into ponds and mouths keep their floors, cross-window fed start, held-lip step styles, and no confluence tongues on the cached 2x2 openFractal and sloping valley scenes
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 06:02:09 -05:00
1 parent 2edf610e8b
commit 6aafec196b
11 files changed
+485 -76

No files matched your search

@@ -6,6 +6,7 @@ import art.arcane.iris.generation.hydrology.water.Pond;
import art.arcane.iris.generation.hydrology.water.PondPlanner;
import art.arcane.iris.generation.hydrology.water.Reach;
import art.arcane.iris.generation.hydrology.water.ReachShaper;
import org.junit.AfterClass;
import org.junit.Test;
import java.util.ArrayList;
@@ -26,10 +27,16 @@ public class ConfluenceIncisionTest {
private static final double WALL_FACE_REACH = 24D;
private static final double MAX_WALL_CUT = 24D;
private static final int MAX_COPY_DIFFERENCE = 4;
private static PlannedScene valley;
@AfterClass
public static void dropScene() {
valley = null;
}
@Test
public void junctionPoolsNeverTrenchASlopingValley() {
PlannedScene scene = PlannedScene.plan(SyntheticTerrain.valleySlope(), settings(), 2, 2);
PlannedScene scene = valley();
int points = 0;
int deep = 0;
String worst = "";
@@ -52,6 +59,11 @@ public class ConfluenceIncisionTest {
assertEquals("reach points cut more than " + DEEP_CUT + " below the valley floor, deepest " + worst, 0, deep);
}
@Test
public void slopingValleyConfluencesHaveNoTongues() {
assertEquals("confluence tongues on the sloping valley over 2x2 windows", List.of(), WaterInvariants.confluenceTongues(valley()));
}
@Test
public void majorDownAWallBesideTheValleyRiverFollowsTheWall() {
SyntheticTerrain terrain = SyntheticTerrain.valleyBelowAWall(WALL_FOOT, WALL_RUN, WALL_HEIGHT);
@@ -115,6 +127,13 @@ public class ConfluenceIncisionTest {
assertTrue("grades of one reach differ by " + worst + " between the windows that plan it: " + worstCopy, worst <= MAX_COPY_DIFFERENCE);
}
private static synchronized PlannedScene valley() {
if (valley == null) {
valley = PlannedScene.plan(SyntheticTerrain.valleySlope(), settings(), 2, 2);
}
return valley;
}
private static HydrologySettings settings() {
return HydrologySettings.compile(new IrisHydrology(), SEED, SyntheticTerrain.SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
}
@@ -40,6 +40,12 @@ public class PlannedSceneTest {
WaterInvariants.detachedOutlets(openFractal()));
}
@Test
public void confluencesHaveNoTongues() {
assertEquals("confluence tongues on openFractal(1) with rainfall " + RAINFALL + " over 2x2 windows", List.of(),
WaterInvariants.confluenceTongues(openFractal()));
}
@Test
public void feedersAtALedInOutletsExitPoolBesideTheLeadIn() {
PlannedScene scene = openFractal();
@@ -275,6 +275,28 @@ public class ChunkWaterRasterTest {
}
}
@Test
public void fallsIntoAPondLeaveItsFloor() {
IntBinaryOperator natural = (x, z) -> 70 + ((x - 16) * (x - 16) + (z - 16) * (z - 16)) / 20;
Pond pond = pond(21L, PondKind.NATURAL, 75, circle(16, 16, 14, 4), 16, 16, 0);
HydrologyTier stream = tier("stream", 1.5f, 0.5f, 4, IrisBankStyle.SMOOTH);
Scene level = new Scene(settings(new IrisHydrology()), natural).pond(pond).reach(line(23L, stream, 0L, 16f, -48f, 16f, 6f, (x, z) -> 75));
Scene falling = new Scene(settings(new IrisHydrology()), natural).pond(pond).reach(line(23L, stream, 0L, 16f, -48f, 16f, 6f, (x, z) -> 86));
int checked = 0;
for (int x = -8; x < 40; x++) {
for (int z = -8; z < 40; z++) {
if (falling.role(x, z) != WaterRole.POND) {
continue;
}
checked++;
assertEquals("pond floor under the fall at " + x + "," + z, level.terrain(x, z), falling.terrain(x, z));
}
}
assertTrue("pond columns " + checked, checked > 400);
assertEquals("the stream falls into the pond", 86, falling.head(16, -2));
assertEquals(74, falling.head(16, 6));
}
@Test
public void pondColumnsShareOneLevel() {
IntBinaryOperator natural = (x, z) -> 70 + ((x - 16) * (x - 16) + (z - 16) * (z - 16)) / 20;
@@ -615,6 +637,26 @@ public class ChunkWaterRasterTest {
}
}
@Test
public void stepsAtTheEdgeOfALowerChannelAreStyledAsFalls() {
HydrologyTier river = tier("river", 8f, 1f, 16, IrisBankStyle.SMOOTH);
HydrologyTier stream = tier("stream", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
Reach lower = line(302L, river, 0L, -96f, 8f, 120f, 8f, (x, z) -> 66);
Map<Integer, WaterRole> styles = Map.of(68, WaterRole.CASCADE, 70, WaterRole.CASCADE, 72, WaterRole.WATERFALL);
for (int level : new int[]{68, 70, 72}) {
Reach perched = line(303L, stream, 0L, 16f, -72f, 16f, 8f, (x, z) -> level);
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 80).reach(lower).reach(perched);
for (int x = 15; x <= 17; x++) {
assertEquals(level, scene.head(x, -1));
assertEquals(66, scene.head(x, 0));
assertEquals("the " + (level - 66) + "-block step onto the lower channel's edge at x " + x, styles.get(level), scene.role(x, 0));
assertEquals("the perched channel above the step at x " + x, WaterRole.CHANNEL, scene.role(x, -1));
}
assertEquals("the lower channel away from the step", WaterRole.CHANNEL, scene.role(40, 0));
assertEquals("the lower channel inside the perched channel's footprint", WaterRole.CHANNEL, scene.role(16, 6));
}
}
@Test
public void crossWindowLinkNeverRaisesWaterDownstream() {
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
@@ -845,6 +887,30 @@ public class ChunkWaterRasterTest {
}
}
@Test
public void crossWindowFedStartOneBlockAboveTheJunctionJoinsIt() {
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) -> 61);
Reach stub = line(341L, narrow, low.id(), 498f, 200f, 504f, 200f, (x, z) -> 62);
Reach upstream = line(340L, narrow, stub.id(), 440f, 200f, 498f, 200f, (x, z) -> 62);
assertEquals(new WindowKey(0, 0), WindowKey.containing(504, 200));
assertEquals(new WindowKey(1, 0), WindowKey.containing(600, 200));
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(upstream).reach(stub).reach(low);
assertEquals("the stub's start one block above the junction joins it", 60, scene.head(498, 200));
int previous = Integer.MAX_VALUE;
for (int x = 440; x <= 600; x++) {
int head = scene.head(x, 200);
assertNotEquals("centre line is water at x=" + x, Integer.MIN_VALUE, head);
assertTrue("water rises from " + previous + " to " + head + " at x=" + x, head <= previous);
if (head < previous && previous != Integer.MAX_VALUE) {
assertEquals("the step at x=" + x + " is styled", WaterRole.CASCADE, scene.role(x, 200));
}
previous = head;
}
assertWindowOrderFree(scene, 27, 37, 12);
}
@Test
public void crossWindowSettlingKeepsAnOutletsHeldLipAtThePondLevel() {
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
@@ -1119,6 +1185,9 @@ public class ChunkWaterRasterTest {
if (scene.role(x, z) == WaterRole.MOUTH) {
mouths++;
assertEquals(banks + "mouth at sea level at " + x + "," + z, SEA_LEVEL, scene.head(x, z));
if (x >= 40) {
assertEquals(banks + "the fall leaves the sea floor under the mouth at " + x + "," + z, coast.applyAsInt(x, z), scene.terrain(x, z));
}
}
if (scene.water(x, z)) {
continue;
@@ -67,6 +67,99 @@ public class RiffleProfileTest {
}
}
@Test
public void fallsKeepADeepPlungePoolBelowTheCurtain() {
Surface surface = new Surface((x, z) -> x < 0 ? 110 : 98);
for (int z = -8; z <= 8; z++) {
for (int original : new int[]{92, 96}) {
String bed = original + " bed at z " + z;
assertEquals("lip sill for the " + bed, 109, surface.bed(-1, z, original));
assertTrue("plunge pool at the foot for the " + bed, surface.bed(0, z, original) <= 95);
assertTrue("deepest at the foot for the " + bed, surface.bed(0, z, original) <= surface.bed(6, z, original));
for (int x = 0; x <= 20; x++) {
int here = surface.bed(x, z, original);
assertTrue("pool at " + x + " stays below the " + bed, here <= original);
assertTrue("downstream face at " + x + " in the " + bed, Math.abs(here - surface.bed(x + 1, z, original)) <= 2);
}
assertEquals(original, surface.bed(17, z, original));
}
assertTrue("the bowl cuts below a shallow bed at z " + z, surface.bed(0, z, 96) <= 94);
}
}
@Test
public void plungeFieldsMatchAcrossChunkBorders() {
IntBinaryOperator heads = (x, z) -> x + z < -7 ? 110 : 98;
Surface surface = new Surface(heads);
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));
}
}
}
}
}
@Test
public void plungeSkipsStandingWaterAndMouths() {
IntBinaryOperator heads = (x, z) -> x < 0 ? 110 : 98;
IntBinaryOperator features = (x, z) -> x < 0 ? 1 : 2;
for (WaterRole standing : new WaterRole[]{WaterRole.POND, WaterRole.MOUTH, WaterRole.INLET}) {
Surface surface = new Surface(heads, water(heads, features, (x, z) -> x < 0 ? WaterRole.CHANNEL : standing));
for (int z = -8; z <= 8; z++) {
assertEquals(standing + " lip sill at z " + z, 109, surface.bed(-1, z, 92));
for (int x = 0; x <= 20; x++) {
assertEquals(standing + " floor at " + x + "," + z, 92, surface.bed(x, z, 92));
assertEquals(standing + " shallow floor at " + x + "," + z, 96, surface.bed(x, z, 96));
}
}
}
Surface beside = new Surface(heads, water(heads, (x, z) -> x < 0 ? 1 : z < 0 ? 2 : 3,
(x, z) -> x >= 0 && z >= 0 ? WaterRole.POND : WaterRole.CHANNEL));
for (int z = -8; z <= 8; z++) {
for (int x = 0; x <= 20; x++) {
if (z >= 0) {
assertEquals("pond floor beside a carved channel foot at " + x + "," + z, 96, beside.bed(x, z, 96));
}
}
if (z < 0) {
assertTrue("channel foot beside the pond at z " + z, beside.bed(0, z, 96) < 96);
}
}
}
@Test
public void receivingChannelKeepsItsBedBelowAJoiningCascade() {
IntBinaryOperator heads = (x, z) -> x < 0 ? 104 : 100;
Surface joining = new Surface(heads, water(heads, (x, z) -> x < 0 ? 2 : 1, (x, z) -> WaterRole.CHANNEL));
for (int z = -8; z <= 8; z++) {
assertEquals("the joining channel keeps its lip sill at z " + z, 103, joining.bed(-1, z, 96));
assertTrue("the joining channel's approach rises toward its lip at z " + z, joining.bed(-6, z, 96) > 96);
for (int x = 0; x <= 20; x++) {
assertEquals("receiving bed at " + x + "," + z, 96, joining.bed(x, z, 96));
}
}
Surface outlet = new Surface(heads, water(heads, (x, z) -> x < 0 ? 2 : 1, (x, z) -> x < 0 ? WaterRole.POND : WaterRole.CHANNEL));
assertEquals("a channel below a pond's shore still rises toward the lip", 99, outlet.bed(0, 0, 96));
}
@Test
public void nearbyDisconnectedPoolsKeepTheirDepth() {
Surface surface = new Surface((x, z) -> z == 0 ? DRY : z > 0 ? 100 : x < 0 ? 100 : 98);
@@ -97,9 +190,9 @@ public class RiffleProfileTest {
IntBinaryOperator heads = (x, z) -> x + z < -7 ? 100 : 98;
for (int chunkX = -2; chunkX <= 1; chunkX++) {
for (int chunkZ = -2; chunkZ <= 1; chunkZ++) {
RiffleProfile first = new RiffleProfile(chunkX, chunkZ, heads);
RiffleProfile east = new RiffleProfile(chunkX + 1, chunkZ, heads);
RiffleProfile south = new RiffleProfile(chunkX, chunkZ + 1, heads);
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++) {
int x = (chunkX + 1) << 4;
int z = (chunkZ << 4) + edge;
@@ -116,19 +209,40 @@ public class RiffleProfileTest {
}
}
private static RiffleProfile.Water channel(IntBinaryOperator heads) {
return water(heads, (x, z) -> 1, (x, z) -> WaterRole.CHANNEL);
}
private static RiffleProfile.Water water(IntBinaryOperator heads, IntBinaryOperator features, Roles roles) {
return (x, z, sample) -> {
int head = heads.applyAsInt(x, z);
sample.set(head, features.applyAsInt(x, z), head == DRY ? WaterRole.NONE : roles.at(x, z));
};
}
private interface Roles {
WaterRole at(int x, int z);
}
private static final class Surface {
private final IntBinaryOperator heads;
private final RiffleProfile.Water water;
private final Map<Long, RiffleProfile> chunks = new HashMap<>();
private Surface(IntBinaryOperator heads) {
this(heads, channel(heads));
}
private Surface(IntBinaryOperator heads, RiffleProfile.Water water) {
this.heads = heads;
this.water = water;
}
private int bed(int x, int z, int original) {
int cx = x >> 4;
int cz = z >> 4;
long key = ((long) cx << 32) | (cz & 0xFFFFFFFFL);
RiffleProfile profile = chunks.computeIfAbsent(key, ignored -> new RiffleProfile(cx, cz, heads));
RiffleProfile profile = chunks.computeIfAbsent(key, ignored -> new RiffleProfile(cx, cz, water));
return profile.bed(x & 15, z & 15, original, heads.applyAsInt(x, z), BedProfile.variation(1337L, x, z));
}
}
@@ -1581,10 +1581,30 @@ public class ReachShaperTest {
int[] grade = {62, 62, 62, 40, 40};
boolean[] ocean = {false, false, false, true, true};
ReachStyle[] styles = ReachShaper.styles(grade, ocean, new boolean[grade.length], 6);
ReachStyle[] styles = ReachShaper.styles(grade, ocean, new boolean[grade.length], 6, SEA_LEVEL);
assertEquals(List.of(ReachStyle.RUN, ReachStyle.RUN, ReachStyle.WATERFALL, ReachStyle.MOUTH, ReachStyle.MOUTH), List.of(styles));
}
@Test
public void heldLipStepThatShowsAsTwoBlocksIsACascade() {
int[] grade = {76, 76, 76, 75, 75};
boolean[] ocean = new boolean[grade.length];
boolean[] held = {true, true, true, false, false};
assertEquals("a one-block step off a held lip that the even head snap shows as two blocks",
List.of(ReachStyle.POND_OUTLET, ReachStyle.POND_OUTLET, ReachStyle.POND_OUTLET, ReachStyle.CASCADE, ReachStyle.RUN),
List.of(ReachShaper.styles(grade, ocean, held, 6, SEA_LEVEL)));
assertEquals("the same step hidden by the head snap", ReachStyle.RIFFLE, ReachShaper.styles(grade, ocean, held, 6, SEA_LEVEL + 1)[3]);
assertEquals("a one-block step that leaves no held lip", ReachStyle.RIFFLE,
ReachShaper.styles(grade, ocean, new boolean[grade.length], 6, SEA_LEVEL)[3]);
int[] zoned = {78, 78, 77, 77, 77};
boolean[] zone = {true, true, true, true, false};
assertEquals("a one-block step inside an outlet zone that the head snap shows as two blocks",
List.of(ReachStyle.POND_OUTLET, ReachStyle.POND_OUTLET, ReachStyle.CASCADE, ReachStyle.POND_OUTLET, ReachStyle.RUN),
List.of(ReachShaper.styles(zoned, ocean, zone, 6, SEA_LEVEL)));
assertEquals("the same step inside the zone hidden by the head snap", ReachStyle.POND_OUTLET,
ReachShaper.styles(zoned, ocean, zone, 6, SEA_LEVEL + 1)[2]);
}
@Test
public void channelWaterStaysBelowNaturalGroundOnSmoothValleys() {
HydrologySettings settings = settings(config -> {