mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 11:41:37 +00:00
Sea head review fixes
- The mouth sea-level check covers only the trailing mouth run of reaches that end in the ocean - Ocean-flagged points inside a reach no longer fail planning closed - Reach checks are split into a below-sea pass and a trailing-mouth pass with one failure message builder - Reflooded ponds stop lowering at the sea surface and drop instead of standing below it - A sea-strip slope fixture reproduces mid-reach mouth points above sea
This commit is contained in:
1 parent
d341e114b5
commit
de62c76807
5 files changed
+84
-12
No files matched your search
@@ -330,12 +330,16 @@ public final class WindowPlanner {
|
|||||||
}
|
}
|
||||||
for (Reach reach : plan.reaches()) {
|
for (Reach reach : plan.reaches()) {
|
||||||
for (int point = 0; point < reach.grade().length; point++) {
|
for (int point = 0; point < reach.grade().length; point++) {
|
||||||
int grade = reach.grade()[point];
|
if (reach.grade()[point] < seaLevel) {
|
||||||
boolean mouth = reach.style()[point] == ReachStyle.MOUTH;
|
throw offSea(plan.key(), reach, point, ", below sea level " + seaLevel);
|
||||||
if (grade < seaLevel || mouth && grade != seaLevel) {
|
}
|
||||||
throw new IllegalStateException("Window " + plan.key() + " reach " + reach.id() + " " + reach.style()[point] + " point "
|
}
|
||||||
+ point + " at " + reach.xs()[point] + "," + reach.zs()[point] + " is graded " + grade
|
if (reach.downstreamId() != 0L) {
|
||||||
+ (mouth ? ", not at sea level " : ", below sea level ") + seaLevel);
|
continue;
|
||||||
|
}
|
||||||
|
for (int point = reach.grade().length - 1; point >= 0 && reach.style()[point] == ReachStyle.MOUTH; point--) {
|
||||||
|
if (reach.grade()[point] != seaLevel) {
|
||||||
|
throw offSea(plan.key(), reach, point, ", but the mouth must meet the sea at sea level " + seaLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,6 +351,11 @@ public final class WindowPlanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IllegalStateException offSea(WindowKey key, Reach reach, int point, String rule) {
|
||||||
|
return new IllegalStateException("Window " + key + " reach " + reach.id() + " " + reach.style()[point] + " point " + point + " at "
|
||||||
|
+ reach.xs()[point] + "," + reach.zs()[point] + " is graded " + reach.grade()[point] + rule);
|
||||||
|
}
|
||||||
|
|
||||||
private record Drainage(float[] filled, List<Basin> basins, DemGrid surface, int[] receivers, float[] accumulation, BitSet channels) {
|
private record Drainage(float[] filled, List<Basin> basins, DemGrid surface, int[] receivers, float[] accumulation, BitSet channels) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,8 @@ public final class PondPlanner {
|
|||||||
floor = node;
|
floor = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int level = pond.level(); floor >= 0 && ground[floor] < level; level--) {
|
int seaFloor = Math.max(settings.minY() + 1, settings.seaLevel());
|
||||||
|
for (int level = pond.level(); level >= seaFloor && floor >= 0 && ground[floor] < level; level--) {
|
||||||
boolean[] wet = floodWithin(box, ground, inside, floor, level);
|
boolean[] wet = floodWithin(box, ground, inside, floor, level);
|
||||||
if (pond.damRaise() > 0 || contained(box, ground, wet, level)) {
|
if (pond.damRaise() > 0 || contained(box, ground, wet, level)) {
|
||||||
float lowest = Float.POSITIVE_INFINITY;
|
float lowest = Float.POSITIVE_INFINITY;
|
||||||
|
|||||||
@@ -260,6 +260,11 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
|||||||
return new SyntheticTerrain((x, z) -> x < coastX ? OCEAN_FLOOR : SEA_LEVEL + 30D + 0.05D * (x - coastX) + 3D * Math.sin(z / 40D));
|
return new SyntheticTerrain((x, z) -> x < coastX ? OCEAN_FLOOR : SEA_LEVEL + 30D + 0.05D * (x - coastX) + 3D * Math.sin(z / 40D));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SyntheticTerrain seaStrip(double stripMinX, double stripWidth) {
|
||||||
|
return new SyntheticTerrain((x, z) -> x >= stripMinX && x < stripMinX + stripWidth ? SEA_LEVEL - 2D
|
||||||
|
: 100D - 0.03D * x + 0.05D * Math.abs(z - 512D));
|
||||||
|
}
|
||||||
|
|
||||||
static SyntheticTerrain openFractal(long seed) {
|
static SyntheticTerrain openFractal(long seed) {
|
||||||
return new SyntheticTerrain((x, z) -> fractalHeight(seed, x, z));
|
return new SyntheticTerrain((x, z) -> fractalHeight(seed, x, z));
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-5
@@ -826,6 +826,30 @@ public class WindowPlannerTest {
|
|||||||
assertFailsClosed(settings, List.of(mouth), List.of(), "reach 4711");
|
assertFailsClosed(settings, List.of(mouth), List.of(), "reach 4711");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void oceanFlagsInsideAReachDoNotFailClosed() {
|
||||||
|
HydrologySettings settings = settings(new IrisHydrology());
|
||||||
|
for (double stripX : new double[]{817D, 841D}) {
|
||||||
|
SyntheticTerrain terrain = SyntheticTerrain.seaStrip(stripX, 4D).withPit(900D, 512D, 50D, 30D);
|
||||||
|
PlannedScene scene = PlannedScene.plan(terrain, settings, 2, 2);
|
||||||
|
int inner = 0;
|
||||||
|
for (Reach reach : scene.reaches()) {
|
||||||
|
int trailing = reach.grade().length;
|
||||||
|
while (trailing > 0 && reach.style()[trailing - 1] == ReachStyle.MOUTH) {
|
||||||
|
trailing--;
|
||||||
|
}
|
||||||
|
for (int point = 0; point < trailing; point++) {
|
||||||
|
inner += reach.style()[point] == ReachStyle.MOUTH && reach.grade()[point] > SEA_LEVEL ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue("mouth points above sea inside reaches crossing the sea strip at x " + stripX + ": " + inner, inner > 0);
|
||||||
|
}
|
||||||
|
Reach crossing = new Reach(4715L, settings.tiers().get(0), 0L, new float[]{64f, 80f, 96f}, new float[]{64f, 64f, 64f},
|
||||||
|
new int[]{SEA_LEVEL + 6, SEA_LEVEL + 4, SEA_LEVEL + 2}, new float[]{2f, 2f, 2f}, new float[]{1f, 1f, 1f},
|
||||||
|
new ReachStyle[]{ReachStyle.RUN, ReachStyle.MOUTH, ReachStyle.RUN}, 1000f);
|
||||||
|
assertEquals(List.of(crossing), plannerReturning(settings, List.of(crossing), List.of()).plan(ORIGIN, noRegions(ORIGIN)).reaches());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void planWithWaterOffTheSeaSurfaceFailsClosed() {
|
public void planWithWaterOffTheSeaSurfaceFailsClosed() {
|
||||||
HydrologySettings settings = settings(new IrisHydrology());
|
HydrologySettings settings = settings(new IrisHydrology());
|
||||||
@@ -849,16 +873,19 @@ public class WindowPlannerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void assertFailsClosed(HydrologySettings settings, List<Reach> reaches, List<Pond> water, String feature) {
|
private static void assertFailsClosed(HydrologySettings settings, List<Reach> reaches, List<Pond> water, String feature) {
|
||||||
|
WindowPlanner planner = plannerReturning(settings, reaches, water);
|
||||||
|
IllegalStateException failure = assertThrows(feature + " off the sea surface", IllegalStateException.class,
|
||||||
|
() -> planner.compute(ORIGIN, noRegions(ORIGIN)));
|
||||||
|
assertTrue(failure.getMessage(), failure.getMessage().contains(feature) && failure.getMessage().contains("Window " + ORIGIN));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WindowPlanner plannerReturning(HydrologySettings settings, List<Reach> reaches, List<Pond> water) {
|
||||||
PondPlanner ponds = spy(new PondPlanner(settings));
|
PondPlanner ponds = spy(new PondPlanner(settings));
|
||||||
doReturn(CupSet.EMPTY).when(ponds).subtractCups(any(), any(), any(), any());
|
doReturn(CupSet.EMPTY).when(ponds).subtractCups(any(), any(), any(), any());
|
||||||
doReturn(water).when(ponds).ponds(any(), any(), any(), any(), any(), any());
|
doReturn(water).when(ponds).ponds(any(), any(), any(), any(), any(), any());
|
||||||
ReachShaper shaper = mock(ReachShaper.class);
|
ReachShaper shaper = mock(ReachShaper.class);
|
||||||
doReturn(new ShapedNetwork(reaches, water)).when(shaper).shape(any(), any(), any(), any(), any(), any(), anyLong());
|
doReturn(new ShapedNetwork(reaches, water)).when(shaper).shape(any(), any(), any(), any(), any(), any(), anyLong());
|
||||||
WindowPlanner planner = new WindowPlanner(settings,
|
return new WindowPlanner(settings, new HeightLattice(SyntheticTerrain.flat(100D), WindowPlanner.FINE_CELL, false, 1 << 18), ponds, shaper);
|
||||||
new HeightLattice(SyntheticTerrain.flat(100D), WindowPlanner.FINE_CELL, false, 1 << 18), ponds, shaper);
|
|
||||||
IllegalStateException failure = assertThrows(feature + " off the sea surface", IllegalStateException.class,
|
|
||||||
() -> planner.compute(ORIGIN, noRegions(ORIGIN)));
|
|
||||||
assertTrue(failure.getMessage(), failure.getMessage().contains(feature) && failure.getMessage().contains("Window " + ORIGIN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SeaColumns assertSeaConnectedHeads(String name, PlannedScene scene) {
|
private static SeaColumns assertSeaConnectedHeads(String name, PlannedScene scene) {
|
||||||
|
|||||||
@@ -208,6 +208,36 @@ public class PondPlannerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refloodingNeverDropsAPondBelowTheSeaSurface() {
|
||||||
|
HydrologySettings settings = settings(config -> config.getPonds().getShore().setRoundness(0D), MIN_Y, MAX_Y);
|
||||||
|
BitSet wet = new BitSet(81);
|
||||||
|
wet.set(0, 81);
|
||||||
|
PondMask mask = new PondMask(0, 0, 4, 9, 9, wet.toLongArray());
|
||||||
|
for (int rise : new int[]{0, 4}) {
|
||||||
|
DoubleBinaryOperator pit = (x, z) -> {
|
||||||
|
if (x >= 0 && x <= 32 && z >= 0 && z <= 32) {
|
||||||
|
return SEA_LEVEL - 10D + rise + 0.5D * Math.max(Math.abs(x - 16D), Math.abs(z - 16D));
|
||||||
|
}
|
||||||
|
return x == 36D && z == 16D ? SEA_LEVEL - 3D + rise : 112D;
|
||||||
|
};
|
||||||
|
Terrain terrain = new Terrain(pit, 1f, ALLOW_ALL, null, MIN_Y, MAX_Y);
|
||||||
|
Pond pond = new Pond(1L, PondKind.NATURAL, SEA_LEVEL + 1 + rise, SEA_LEVEL - 10 + rise, 36, 16, SEA_LEVEL - 3f + rise, mask,
|
||||||
|
7L, 0, "water", 16, 16);
|
||||||
|
|
||||||
|
Pond reflooded = new PondPlanner(settings).reflood(new DemGrid(-8, -8, 8, 7, 7), new HeightLattice(terrain, 4, false, 4096),
|
||||||
|
CupSet.EMPTY, pond);
|
||||||
|
|
||||||
|
if (rise == 0) {
|
||||||
|
assertNull("a pond that holds only below the sea surface is dropped", reflooded);
|
||||||
|
} else {
|
||||||
|
assertNotNull("a pond that holds above the sea surface is kept", reflooded);
|
||||||
|
assertEquals(SEA_LEVEL - 2 + rise, reflooded.level());
|
||||||
|
assertContained(reflooded, pit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refloodingRejectsWetRimsClippedByThePlanningGrid() {
|
public void refloodingRejectsWetRimsClippedByThePlanningGrid() {
|
||||||
HydrologySettings settings = settings(config -> config.getPonds().getShore().setRoundness(0D), MIN_Y, MAX_Y);
|
HydrologySettings settings = settings(config -> config.getPonds().getShore().setRoundness(0D), MIN_Y, MAX_Y);
|
||||||
|
|||||||
Reference in new issue
Block a user