Merge tidal inlets

- Sea inlets become tidal reaches on the river pipeline
- Recaptures the schema digest for the merged lane
This commit is contained in:
Brian Fopiano committed 2026-11-03 20:46:08 -05:00
commit 5df42fc49e
82 files changed
+3370 -4647

No files matched your search

@@ -227,6 +227,16 @@ final class HydrologyPlanHarness {
HydrologySettings settings() {
return settings;
}
boolean ocean(int x, int z) {
HydrologySampleBuffer sample = new HydrologySampleBuffer(1);
planners.fineLattice().sampleColumns(new int[]{x}, new int[]{z}, sample);
return sample.ocean()[0];
}
HydrologyPlanners planners() {
return planners;
}
}
static final class CountingTerrain implements HydrologyTerrainSource {
@@ -2,6 +2,8 @@ package art.arcane.iris.probe;
import art.arcane.iris.generation.hydrology.plan.WindowKey;
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
import art.arcane.iris.generation.hydrology.water.Reach;
import art.arcane.iris.generation.hydrology.water.ReachStyle;
import art.arcane.iris.generation.runtime.Engine;
import java.util.ArrayList;
@@ -21,21 +23,25 @@ final class HydrologyUnderground {
static final Counts NONE = new Counts(0, 0L, 0, 0L, List.of());
}
private static int tidal(WindowPlan plan) {
int arms = 0;
for (Reach reach : plan.reaches()) {
arms += reach.style()[0] == ReachStyle.TIDAL ? 1 : 0;
}
return arms;
}
static Source generated(Engine engine, ExecutorService workers) {
return (key, plan) -> {
SeaInletProbe.Checks inlets = SeaInletProbe.check(engine, plan.inlets(), workers);
int minChunkX = key.wx() * HydrologyWindows.CHUNKS;
int minChunkZ = key.wz() * HydrologyWindows.CHUNKS;
CavePoolProbe.Counts pools = CavePoolProbe.check(engine, new CavePoolProbe.Area(minChunkX, minChunkX + HydrologyWindows.CHUNKS - 1,
minChunkZ, minChunkZ + HydrologyWindows.CHUNKS - 1), workers);
List<String> examples = new ArrayList<>();
for (String example : inlets.examples()) {
examples.add("inlet " + example);
}
for (String example : pools.examples()) {
examples.add("pool " + example);
}
return new Counts(inlets.inlets(), inlets.failures(), pools.pools(), pools.failures(), examples);
return new Counts(tidal(plan), 0L, pools.pools(), pools.failures(), examples);
};
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,120 @@
package art.arcane.iris.probe;
import java.util.Arrays;
final class TidalReachMetrics {
private static final double STEP = 4D;
private static final double STRAIGHT_DEGREES = 10D;
private TidalReachMetrics() {
}
static double length(float[] xs, float[] zs) {
double length = 0D;
for (int point = 1; point < xs.length; point++) {
length += Math.hypot(xs[point] - xs[point - 1], zs[point] - zs[point - 1]);
}
return length;
}
static double sinuosity(float[] xs, float[] zs) {
int last = xs.length - 1;
double chord = Math.hypot(xs[last] - xs[0], zs[last] - zs[0]);
return chord <= 0D ? 1D : length(xs, zs) / chord;
}
static double[][] resample(float[] xs, float[] zs) {
double total = length(xs, zs);
int steps = Math.max(1, (int) Math.floor(total / STEP));
double[] rx = new double[steps + 1];
double[] rz = new double[steps + 1];
int segment = 0;
double along = 0D;
for (int index = 0; index <= steps; index++) {
double wanted = index * STEP;
while (segment < xs.length - 2 && along + Math.hypot(xs[segment + 1] - xs[segment], zs[segment + 1] - zs[segment]) < wanted) {
along += Math.hypot(xs[segment + 1] - xs[segment], zs[segment + 1] - zs[segment]);
segment++;
}
double span = Math.hypot(xs[segment + 1] - xs[segment], zs[segment + 1] - zs[segment]);
double t = span <= 0D ? 0D : Math.clamp((wanted - along) / span, 0D, 1D);
rx[index] = xs[segment] + t * (xs[segment + 1] - xs[segment]);
rz[index] = zs[segment] + t * (zs[segment + 1] - zs[segment]);
}
return new double[][]{rx, rz};
}
static double straightRun(float[] xs, float[] zs) {
double[][] line = resample(xs, zs);
int segments = line[0].length - 1;
double[] heading = headings(line);
double longest = 0D;
int start = 0;
for (int segment = 0; segment < segments; segment++) {
while (start < segment && turn(heading[start], heading[segment]) > STRAIGHT_DEGREES) {
start++;
}
longest = Math.max(longest, (segment - start + 1) * STEP);
}
return longest;
}
static double sharpestTurn(float[] xs, float[] zs) {
double[][] line = resample(xs, zs);
double[] heading = headings(line);
double sharpest = 0D;
for (int segment = 1; segment < heading.length; segment++) {
sharpest = Math.max(sharpest, turn(heading[segment - 1], heading[segment]));
}
return sharpest;
}
private static double[] headings(double[][] line) {
double[] heading = new double[line[0].length - 1];
for (int segment = 0; segment < heading.length; segment++) {
heading[segment] = Math.toDegrees(Math.atan2(line[1][segment + 1] - line[1][segment], line[0][segment + 1] - line[0][segment]));
}
return heading;
}
private static double turn(double from, double to) {
double difference = Math.abs(to - from) % 360D;
return difference > 180D ? 360D - difference : difference;
}
static double longestSlotRun(double[] left, double[] right, double rise, double step) {
double longest = 0D;
double run = 0D;
for (int station = 0; station < left.length; station++) {
run = left[station] >= rise && right[station] >= rise ? run + step : 0D;
longest = Math.max(longest, run);
}
return longest;
}
static double steepestRise(int[] heights, int span) {
double steepest = 0D;
for (int from = 0; from + span < heights.length; from++) {
steepest = Math.max(steepest, heights[from + span] - heights[from]);
}
return steepest;
}
static boolean adjacentRaysAtLeast(int[] rises, int rise) {
for (int ray = 0; ray + 1 < rises.length; ray++) {
if (rises[ray] >= rise && rises[ray + 1] >= rise) {
return true;
}
}
return false;
}
static double percentile(double[] values, double share) {
if (values.length == 0) {
return 0D;
}
double[] sorted = values.clone();
Arrays.sort(sorted);
return sorted[Math.min(sorted.length - 1, (int) Math.floor(share * sorted.length))];
}
}
File diff suppressed because it is too large. Load diff
@@ -373,7 +373,7 @@ public class HydrologyMetricsTest {
}
private static WindowPlan plan(WindowKey key, List<Reach> reaches, List<Pond> ponds) {
return new WindowPlan(key, reaches, ponds, List.of());
return new WindowPlan(key, reaches, ponds);
}
private static Reach reach(long id, HydrologyTier tier, long downstream, float catchment, int[] grade, float... coordinates) {
@@ -57,7 +57,7 @@ public class RiverTransectProbeTest {
RiverTransectProbe.Section section = RiverTransectProbe.section(reach, 5,
(x, z) -> new RiverTransectProbe.Column(70, 66, Math.abs(z - 100) <= 2 ? 68 : RiverTransectProbe.NO_WATER, WaterRole.CHANNEL));
List<String> summary = RiverTransectProbe.summary(new WindowKey(0, 0),
new WindowPlan(new WindowKey(0, 0), List.of(reach), List.of(), List.of()), List.of(),
new WindowPlan(new WindowKey(0, 0), List.of(reach), List.of()), List.of(),
List.of(section), settings);
assertEquals("window 0,0 reaches=1 ponds=0 lakes=0 sections=1", summary.get(0));
assertTrue(summary.get(1), summary.get(1).startsWith("reach 7 tier=stream length=40 from=0,100@70 to=40,100@60"));
@@ -1,76 +0,0 @@
package art.arcane.iris.probe;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class SeaInletChecksTest {
@Test
public void roofBreachesFailWithTheContainmentSealAndRoofChecks() {
SeaInletProbe.Checks breached = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 1939L, 0L, 0L, 0L, 0L, 0L, List.of());
assertEquals(1939L, breached.failures());
SeaInletProbe.Checks failing = new SeaInletProbe.Checks(3, 1L, 2L, 3L, 4L, 9L, 5L, 6L, 7L, 8L, 0L, List.of());
assertEquals(45L, failing.failures());
}
@Test
public void looseBedsAreReportedButDoNotFail() {
SeaInletProbe.Checks reported = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 952L, List.of());
assertEquals(0L, reported.failures());
}
@Test
public void theGateFailsOnEveryCheckIncludingOrderSeaLevelAndAddedLeaks() {
SeaInletProbe.Checks clean = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 952L, List.of());
SeaInletProbe.Gate passing = new SeaInletProbe.Gate(clean, 0, 0, 0);
assertEquals(0L, passing.failures());
assertTrue(passing.line(), passing.line().startsWith("SEA_INLET_GATE status=PASS failures=0 "));
assertEquals(2L, new SeaInletProbe.Gate(clean, 0, 0, 2).failures());
assertEquals(1L, new SeaInletProbe.Gate(clean, 1, 0, 0).failures());
assertEquals(1L, new SeaInletProbe.Gate(clean, 0, 1, 0).failures());
SeaInletProbe.Checks breached = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, List.of());
SeaInletProbe.Gate failing = new SeaInletProbe.Gate(breached, 0, 0, 0);
assertEquals(4L, failing.failures());
assertTrue(failing.line(), failing.line().startsWith("SEA_INLET_GATE status=FAIL failures=4 "));
}
@Test
public void addedLeaksAreTheLeaksMissingWithoutInlets() {
long kept = SeaInletProbe.cellKey(10, 300, -20);
long removed = SeaInletProbe.cellKey(11, 300, -20);
long added = SeaInletProbe.cellKey(10, 301, -20);
assertEquals(0, SeaInletProbe.addedLeaks(Set.of(kept), Set.of(kept)));
assertEquals("inlets that remove natural leaks do not fail", 0, SeaInletProbe.addedLeaks(Set.of(kept), Set.of(kept, removed)));
assertEquals("a leak the inlets move counts although the totals match", 1, SeaInletProbe.addedLeaks(Set.of(kept, added),
Set.of(kept, removed)));
assertEquals(2, SeaInletProbe.addedLeaks(Set.of(added, removed), Set.of()));
assertNotEquals(SeaInletProbe.cellKey(-1, 300, 0), SeaInletProbe.cellKey(0, 300, -1));
assertNotEquals(SeaInletProbe.cellKey(5, 0, 5), SeaInletProbe.cellKey(5, 4095, 5));
}
@Test
public void inletCellsAreClassifiedAgainstTheDimensionSeaFluid() {
assertEquals(SeaInletProbe.classify(state("minecraft:water"), "minecraft:water"), SeaInletProbe.classify(state("minecraft:lava"),
"minecraft:lava"));
assertEquals(SeaInletProbe.classify(state("minecraft:water[level=8]"), "minecraft:water"),
SeaInletProbe.classify(state("minecraft:lava[level=8]"), "minecraft:lava"));
assertEquals(SeaInletProbe.classify(state("minecraft:lava"), "minecraft:water"), SeaInletProbe.classify(state("minecraft:water"),
"minecraft:lava"));
assertNotEquals(SeaInletProbe.classify(state("minecraft:lava"), "minecraft:lava"), SeaInletProbe.classify(state("minecraft:lava"),
"minecraft:water"));
}
private static NativeBlockState state(String key) {
NativeBlockState state = mock(NativeBlockState.class);
when(state.key()).thenReturn(key);
return state;
}
}
@@ -45,7 +45,7 @@ final class SyntheticHydrology implements AutoCloseable {
}
HydrologyProbe.Inputs inputs(UnaryOperator<HydrologyVoxels.ChunkBlocks> edit) {
return inputs(edit, (key, plan) -> new HydrologyUnderground.Counts(plan.inlets().size(), 0L, 0, 0L, List.of()));
return inputs(edit, (key, plan) -> new HydrologyUnderground.Counts(0, 0L, 0, 0L, List.of()));
}
HydrologyProbe.Inputs inputs(UnaryOperator<HydrologyVoxels.ChunkBlocks> edit, HydrologyUnderground.Source underground) {
@@ -0,0 +1,68 @@
package art.arcane.iris.probe;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TidalReachMetricsTest {
private static float[] line(int points, float step) {
float[] values = new float[points];
for (int point = 0; point < points; point++) {
values[point] = point * step;
}
return values;
}
@Test
public void straightLineRunsItsWholeLengthWithoutTurning() {
float[] xs = line(25, 4f);
float[] zs = new float[25];
assertEquals(1D, TidalReachMetrics.sinuosity(xs, zs), 1e-9D);
assertEquals(96D, TidalReachMetrics.straightRun(xs, zs), 1e-9D);
assertEquals(0D, TidalReachMetrics.sharpestTurn(xs, zs), 1e-9D);
}
@Test
public void rightAngleShowsAsASharpTurn() {
float[] xs = {0f, 40f, 40f};
float[] zs = {0f, 0f, 40f};
assertEquals(80D / Math.hypot(40D, 40D), TidalReachMetrics.sinuosity(xs, zs), 1e-6D);
assertTrue(TidalReachMetrics.sharpestTurn(xs, zs) >= 45D);
assertEquals(40D, TidalReachMetrics.straightRun(xs, zs), 4.01D);
}
@Test
public void wavyLineHasShortStraightRunsAndAboveOneSinuosity() {
int points = 200;
float[] xs = new float[points];
float[] zs = new float[points];
for (int point = 0; point < points; point++) {
xs[point] = point;
zs[point] = (float) (6D * Math.sin(point / 8D));
}
assertTrue(TidalReachMetrics.sinuosity(xs, zs) > 1.1D);
assertTrue(TidalReachMetrics.straightRun(xs, zs) < 24D);
assertEquals(1D, TidalReachMetrics.percentile(new double[]{0D, 1D, 2D}, 0.5D), 0D);
}
@Test
public void slotRunFindsWallsOnBothSidesAtOnce() {
double[] left = {30D, 30D, 30D, 30D, 2D, 30D};
double[] right = {30D, 30D, 30D, 30D, 30D, 2D};
assertEquals(8D, TidalReachMetrics.longestSlotRun(left, right, 16D, 2D), 0D);
assertEquals(0D, TidalReachMetrics.longestSlotRun(new double[]{30D, 2D}, new double[]{2D, 30D}, 16D, 2D), 0D);
}
@Test
public void steepestRiseSeesASheerWallNotAGradedBank() {
assertEquals(30D, TidalReachMetrics.steepestRise(new int[]{0, 0, 30, 30, 30, 30, 30}, 4), 0D);
assertEquals(4D, TidalReachMetrics.steepestRise(new int[]{0, 1, 2, 3, 4, 5, 6}, 4), 0D);
}
@Test
public void headWallNeedsTwoAdjacentRays() {
assertTrue(TidalReachMetrics.adjacentRaysAtLeast(new int[]{0, 16, 20, 0}, 16));
assertTrue(!TidalReachMetrics.adjacentRaysAtLeast(new int[]{16, 0, 20, 0}, 16));
}
}