mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Inland hollow review fixes
- Trunks are cut where they cross the natural basin draining into an inland hollow, so the major restarts beyond the rim instead of descending through it at sea level - Lowland channels never climb more than 2 blocks above the lowest ground they crossed or the sea, in a new LowlandChannels helper - Inland hollow ponds skip dams - Hollow planner tests assert no reach is held at the sea under high ground and the valley past the rim matches the hollow-free valley - Pondless inland hollows end streams at their edge - One shared SeaCells test helper replaces the two copies
This commit is contained in:
1 parent
30865031ba
commit
c0f2c10c1d
12 files changed
+306
-89
No files matched your search
@@ -12,6 +12,7 @@ import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BurnedTrunksTest {
|
||||
@@ -48,35 +49,41 @@ public class BurnedTrunksTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trunkNeitherDescendsNorDrainsThroughAnInlandHollow() {
|
||||
public void trunkStopsAtAHollowBasinAndRestartsBeyondIt() {
|
||||
DemGrid raw = new DemGrid(0, 0, CELL, SIZE, SIZE);
|
||||
Arrays.fill(raw.values(), 200f);
|
||||
BitSet hollow = new BitSet(SIZE * SIZE);
|
||||
BitSet basin = new BitSet(SIZE * SIZE);
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
boolean inside = i >= HOLLOW_FROM && i <= HOLLOW_TO;
|
||||
raw.set(i, TRENCH_ROW, inside ? 10f : 100f);
|
||||
if (inside) {
|
||||
hollow.set(raw.index(i, TRENCH_ROW));
|
||||
basin.set(raw.index(i, TRENCH_ROW));
|
||||
}
|
||||
}
|
||||
HydrologyTier major = HydrologySettings.compile(new IrisHydrology(), 1337L, 40, -64, 320).majorTier();
|
||||
BurnedTrunks trunks = BurnedTrunks.burn(raw, List.of(reach(1L, 0L, major, 2, 24)), 3f, 0.001f, hollow);
|
||||
BurnedTrunks trunks = BurnedTrunks.burn(raw, List.of(reach(1L, 0L, major, 2, 24)), 3f, 0.001f, basin);
|
||||
int[] receivers = new int[SIZE * SIZE];
|
||||
Arrays.fill(receivers, -1);
|
||||
trunks.route(receivers);
|
||||
for (int i = 2; i < HOLLOW_FROM; i++) {
|
||||
assertEquals("the trunk above the hollow drains into it at " + i, raw.index(i + 1, TRENCH_ROW), receivers[raw.index(i, TRENCH_ROW)]);
|
||||
for (int i = 2; i < HOLLOW_FROM - 1; i++) {
|
||||
assertEquals("the trunk above the hollow runs on at " + i, raw.index(i + 1, TRENCH_ROW), receivers[raw.index(i, TRENCH_ROW)]);
|
||||
}
|
||||
assertEquals("the trunk ends at the hollow basin", -1, receivers[raw.index(HOLLOW_FROM - 1, TRENCH_ROW)]);
|
||||
for (int i = HOLLOW_FROM; i <= HOLLOW_TO; i++) {
|
||||
assertFalse("the hollow basin holds no trunk at " + i, trunks.contains(raw.index(i, TRENCH_ROW)));
|
||||
assertEquals("the hollow keeps its own drainage at " + i, -1, receivers[raw.index(i, TRENCH_ROW)]);
|
||||
assertEquals("the hollow is not burned at " + i, 10f, raw.values()[raw.index(i, TRENCH_ROW)], 0f);
|
||||
}
|
||||
for (int i = HOLLOW_TO + 1; i <= 24; i++) {
|
||||
float height = raw.values()[raw.index(i, TRENCH_ROW)];
|
||||
assertTrue("the trunk beyond the hollow keeps its burned height at " + i + ": " + height, height > 90f);
|
||||
if (i < 24) {
|
||||
assertEquals("the trunk beyond the hollow drains on at " + i, raw.index(i + 1, TRENCH_ROW), receivers[raw.index(i, TRENCH_ROW)]);
|
||||
assertEquals("the trunk beyond the hollow runs on at " + i, raw.index(i + 1, TRENCH_ROW), receivers[raw.index(i, TRENCH_ROW)]);
|
||||
}
|
||||
}
|
||||
float[] weights = new float[SIZE * SIZE];
|
||||
trunks.inject(weights);
|
||||
assertTrue("the trunk beyond the hollow restarts with the river's catchment", weights[raw.index(HOLLOW_TO + 1, TRENCH_ROW)] > 0f);
|
||||
}
|
||||
|
||||
private static Reach reach(long id, long downstreamId, HydrologyTier tier, int fromI, int toI) {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package art.arcane.iris.generation.hydrology.plan;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class LowlandChannelsTest {
|
||||
private static final int SEA_LEVEL = 40;
|
||||
private static final int CELLS = 12;
|
||||
private static final int RIVER_END = 4;
|
||||
private static final int COAST = 10;
|
||||
private static final byte ALLOW_ALL = HydrologySampleBuffer.ALLOW_STREAMS | HydrologySampleBuffer.ALLOW_PONDS;
|
||||
|
||||
@Test
|
||||
public void riverCrossesLowLandToTheSea() {
|
||||
Row row = new Row(44f, 43f, 41f, 39f, 38f);
|
||||
assertEquals("every lowland cell up to the sea becomes channel", channelsUpTo(COAST), row.extend());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void riverNeverClimbsOutOfTheLowland() {
|
||||
Row ridge = new Row(44f, 43f, 46f, 41f, 38f);
|
||||
assertEquals("the river stops before ground that rises over the lowland it crossed", channelsUpTo(RIVER_END + 3), ridge.extend());
|
||||
Row bump = new Row(44f, 43f, 45f, 41f, 38f);
|
||||
assertEquals("a rise within the bound is crossed", channelsUpTo(COAST), bump.extend());
|
||||
Row belowSea = new Row(39f, 36f, 41.5f, 38f, 37f);
|
||||
assertEquals("ground up to just above the sea is crossed from below it", channelsUpTo(COAST), belowSea.extend());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void riverStopsAtInlandHollowsHighFillsAndBlockedStreams() {
|
||||
Row hollow = new Row(44f, 43f, 41f, 39f, 38f);
|
||||
hollow.inland.set(RIVER_END + 3);
|
||||
assertEquals("an inland hollow is not crossed", channelsUpTo(RIVER_END + 3), hollow.extend());
|
||||
Row high = new Row(44f, 43f, 41f, 39f, 38f);
|
||||
high.filled[RIVER_END + 2] = SEA_LEVEL + 1f;
|
||||
assertEquals("ground that fills above the sea is not lowland", channelsUpTo(RIVER_END + 2), high.extend());
|
||||
Row blocked = new Row(44f, 43f, 41f, 39f, 38f);
|
||||
blocked.samples.permission()[RIVER_END + 4] = HydrologySampleBuffer.ALLOW_PONDS;
|
||||
assertEquals("streams stop where the policy blocks them", channelsUpTo(RIVER_END + 4), blocked.extend());
|
||||
}
|
||||
|
||||
private static BitSet channelsUpTo(int exclusive) {
|
||||
BitSet channels = new BitSet(CELLS);
|
||||
channels.set(0, exclusive);
|
||||
return channels;
|
||||
}
|
||||
|
||||
private static final class Row {
|
||||
private final HydrologySampleBuffer samples = new HydrologySampleBuffer(CELLS);
|
||||
private final float[] filled = new float[CELLS];
|
||||
private final int[] receivers = new int[CELLS];
|
||||
private final BitSet inland = new BitSet(CELLS);
|
||||
|
||||
private Row(float... lowland) {
|
||||
Arrays.fill(samples.permission(), ALLOW_ALL);
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
receivers[cell] = cell + 1 < CELLS ? cell + 1 : -1;
|
||||
float natural = cell <= RIVER_END ? 50f - cell : cell < COAST ? lowland[cell - RIVER_END - 1] : 10f;
|
||||
samples.height()[cell] = natural;
|
||||
samples.ocean()[cell] = cell >= COAST;
|
||||
filled[cell] = cell <= RIVER_END ? natural : Math.min(natural, SEA_LEVEL - 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private BitSet extend() {
|
||||
BitSet channels = channelsUpTo(RIVER_END + 1);
|
||||
LowlandChannels.extend(channels, filled, receivers, samples, inland, SEA_LEVEL);
|
||||
return channels;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
static final int SEA_LEVEL = 40;
|
||||
static final int MIN_Y = -64;
|
||||
static final int MAX_Y = 320;
|
||||
private static final byte ALLOW_ALL = HydrologySampleBuffer.ALLOW_STREAMS | HydrologySampleBuffer.ALLOW_PONDS;
|
||||
private static final double OCEAN_FLOOR = SEA_LEVEL - 30D;
|
||||
private static final double BASE_OFFSET = 3D;
|
||||
private static final double BASE_WAVELENGTH = 1000D;
|
||||
@@ -21,38 +20,44 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
private final DoubleBinaryOperator natural;
|
||||
private final DoubleBinaryOperator rainfall;
|
||||
private final Area streamsBlocked;
|
||||
private final Area pondsBlocked;
|
||||
private final Area land;
|
||||
private final AtomicLong baseSamples;
|
||||
private final AtomicLong naturalSamples;
|
||||
|
||||
private SyntheticTerrain(DoubleBinaryOperator natural) {
|
||||
this(natural, (x, z) -> 1D, (x, z) -> false, (x, z) -> false);
|
||||
this(natural, (x, z) -> 1D, (x, z) -> false, (x, z) -> false, (x, z) -> false);
|
||||
}
|
||||
|
||||
private SyntheticTerrain(DoubleBinaryOperator natural, DoubleBinaryOperator rainfall, Area streamsBlocked, Area land) {
|
||||
private SyntheticTerrain(DoubleBinaryOperator natural, DoubleBinaryOperator rainfall, Area streamsBlocked, Area pondsBlocked, Area land) {
|
||||
this.natural = natural;
|
||||
this.rainfall = rainfall;
|
||||
this.streamsBlocked = streamsBlocked;
|
||||
this.pondsBlocked = pondsBlocked;
|
||||
this.land = land;
|
||||
this.baseSamples = new AtomicLong();
|
||||
this.naturalSamples = new AtomicLong();
|
||||
}
|
||||
|
||||
SyntheticTerrain withRainfall(DoubleBinaryOperator rainfall) {
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, land);
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain withStreamsBlocked(Area area) {
|
||||
return new SyntheticTerrain(natural, rainfall, area, land);
|
||||
return new SyntheticTerrain(natural, rainfall, area, pondsBlocked, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain withLand(Area area) {
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, area);
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, pondsBlocked, area);
|
||||
}
|
||||
|
||||
SyntheticTerrain withPondsBlocked(Area area) {
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, area, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain lowered(double depth) {
|
||||
DoubleBinaryOperator inner = natural;
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) - depth, rainfall, streamsBlocked, land);
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) - depth, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain withPit(double centreX, double centreZ, double radius, double depth) {
|
||||
@@ -61,7 +66,7 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
double ratio = Math.hypot(x - centreX, z - centreZ) / radius;
|
||||
double height = inner.applyAsDouble(x, z);
|
||||
return ratio < 1D ? height - depth * (1D - ratio * ratio) : height;
|
||||
}, rainfall, streamsBlocked, land);
|
||||
}, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
}
|
||||
|
||||
static SyntheticTerrain valleyLake() {
|
||||
@@ -319,7 +324,8 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
out.ocean()[index] = value <= SEA_LEVEL && !land.contains(xs[index], zs[index]);
|
||||
out.rainfall()[index] = (float) rainfall.applyAsDouble(xs[index], zs[index]);
|
||||
out.pondDensity()[index] = 1f;
|
||||
out.permission()[index] = streamsBlocked.contains(xs[index], zs[index]) ? HydrologySampleBuffer.ALLOW_PONDS : ALLOW_ALL;
|
||||
out.permission()[index] = (byte) ((streamsBlocked.contains(xs[index], zs[index]) ? 0 : HydrologySampleBuffer.ALLOW_STREAMS)
|
||||
| (pondsBlocked.contains(xs[index], zs[index]) ? 0 : HydrologySampleBuffer.ALLOW_PONDS));
|
||||
out.fluidProfile()[index] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ public class WindowPlannerTest {
|
||||
private static final int DEEP_CUT = 12;
|
||||
private static final int SLIVER_REACH = 32;
|
||||
private static final int RIM_CUT = 24;
|
||||
private static final double HOLLOW_EDGE = 8D;
|
||||
private static final double CRATER_X = 512D;
|
||||
private static final double CRATER_Z = 512D;
|
||||
private static final int CRATER_SPILL = 75;
|
||||
@@ -1017,6 +1018,12 @@ public class WindowPlannerTest {
|
||||
}
|
||||
assertTrue("streams draining into the hollow end in its pond: " + inflows, inflows > 0);
|
||||
assertEquals("the inland hollow pond has no outlet", 0L, pond.outletReachId());
|
||||
assertNoSeaLevelCanyon(inland, hollow);
|
||||
PlannedScene valley = PlannedScene.plan(SyntheticTerrain.valleySlope().withLand((x, z) -> true), settings, 2, 2);
|
||||
int beyond = deepCutsBeyond(inland, HOLLOW_X + 1.5D * HOLLOW_RADIUS);
|
||||
int open = deepCutsBeyond(valley, HOLLOW_X + 1.5D * HOLLOW_RADIUS);
|
||||
assertTrue("reach points cut more than " + DEEP_CUT + " deep past the hollow rim: " + beyond + ", in the same valley without the hollow "
|
||||
+ open, beyond <= open + open / 50);
|
||||
assertEquals("the hollow centre is pond water", WaterRole.POND, inland.role((int) HOLLOW_X, (int) HOLLOW_Z));
|
||||
assertEquals("the hollow pond surface", SEA_LEVEL, inland.head((int) HOLLOW_X, (int) HOLLOW_Z));
|
||||
for (int z = inland.minZ() + WaterInvariants.EDGE_MARGIN; z <= inland.maxZ() - WaterInvariants.EDGE_MARGIN; z++) {
|
||||
@@ -1036,6 +1043,56 @@ public class WindowPlannerTest {
|
||||
assertTrue("streams entering the sea-intent hollow keep their mouths: " + mouths, mouths > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pondlessInlandHollowsStopStreamsAtTheirEdge() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
SyntheticTerrain hollow = SyntheticTerrain.valleySlope().withPit(HOLLOW_X, HOLLOW_Z, HOLLOW_RADIUS, HOLLOW_DEPTH).withLand((x, z) -> true)
|
||||
.withPondsBlocked((x, z) -> Math.hypot(x - HOLLOW_X, z - HOLLOW_Z) < HOLLOW_RADIUS);
|
||||
PlannedScene scene = PlannedScene.plan(hollow, settings, 2, 2);
|
||||
assertNull("no pond fills a hollow whose policy blocks ponds", pondAt(scene.ponds(), HOLLOW_X, HOLLOW_Z));
|
||||
int edges = 0;
|
||||
for (Reach reach : scene.reaches()) {
|
||||
for (int point = 0; point < reach.grade().length; point++) {
|
||||
double ground = hollow.natural(reach.xs()[point], reach.zs()[point]);
|
||||
assertNotEquals(reach + " point " + point + " is a sea mouth inland", ReachStyle.MOUTH, reach.style()[point]);
|
||||
assertTrue(reach + " point " + point + " runs into the hollow over ground at " + ground, ground >= SEA_LEVEL - HOLLOW_EDGE);
|
||||
}
|
||||
int last = reach.xs().length - 1;
|
||||
if (reach.downstreamId() == 0L && Math.hypot(reach.xs()[last] - HOLLOW_X, reach.zs()[last] - HOLLOW_Z) < HOLLOW_RADIUS) {
|
||||
edges++;
|
||||
assertTrue(reach + " ends at the hollow edge", hollow.natural(reach.xs()[last], reach.zs()[last]) < SEA_LEVEL + HOLLOW_EDGE);
|
||||
}
|
||||
}
|
||||
assertTrue("streams draining into the hollow end at its edge: " + edges, edges > 0);
|
||||
assertNoSeaLevelCanyon(scene, hollow);
|
||||
}
|
||||
|
||||
private static void assertNoSeaLevelCanyon(PlannedScene scene, SyntheticTerrain terrain) {
|
||||
for (Reach reach : scene.reaches()) {
|
||||
for (int point = 0; point < reach.grade().length; point++) {
|
||||
double ground = terrain.natural(reach.xs()[point], reach.zs()[point]);
|
||||
if (pondAt(scene.ponds(), reach.xs()[point], reach.zs()[point]) == null) {
|
||||
assertTrue(reach + " point " + point + " is held at the sea under ground at " + ground,
|
||||
reach.grade()[point] > SEA_LEVEL + 2 || ground < SEA_LEVEL + RIM_CUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int deepCutsBeyond(PlannedScene scene, double minX) {
|
||||
int deep = 0;
|
||||
for (Reach reach : scene.reaches()) {
|
||||
for (int point = 0; point < reach.grade().length; point++) {
|
||||
int x = (int) Math.floor(reach.xs()[point]);
|
||||
int z = (int) Math.floor(reach.zs()[point]);
|
||||
if (x > minX && pondAt(scene.ponds(), x, z) == null && scene.natural(x, z) - reach.grade()[point] > DEEP_CUT) {
|
||||
deep++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return deep;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepInlandHollowsKeepTheirRim() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
|
||||
+38
-28
@@ -17,6 +17,7 @@ import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.raster.PondChannelSettlement;
|
||||
import art.arcane.iris.testsupport.DeltaCoast;
|
||||
import art.arcane.iris.testsupport.SeaCells;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -294,7 +295,7 @@ public class ReachShaperTest {
|
||||
quadrupled[cell] *= 4f;
|
||||
}
|
||||
ShapedNetwork wider = new ReachShaper(settings).shape(WINDOW, network.grid(), network.receivers(), quadrupled, network.channels(),
|
||||
sea(network.grid()), network.ponds(), network.fine(), SEED);
|
||||
SeaCells.atOrBelow(network.grid(), SEA_LEVEL), network.ponds(), network.fine(), SEED);
|
||||
Map<Long, Reach> widerById = byId(wider.reaches());
|
||||
Map<Long, Integer> incoming = incoming(shaped.reaches());
|
||||
int compared = 0;
|
||||
@@ -402,7 +403,8 @@ public class ReachShaperTest {
|
||||
Pond pond = new Pond(31L, PondKind.NATURAL, 99, 94, 104, 64, 100f, disk(96, 64, 5), 0L, 0, "water", 96, 64);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> Math.hypot(x - 96D, z - 64D) <= 5D ? 94D
|
||||
: x <= 104D ? 100D : 100D - 0.5D * (x - 104D)), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Pond shapedPond = shaped.ponds().get(0);
|
||||
assertEquals(99, shapedPond.level());
|
||||
assertOutletLeavesAtThePondLevel("lip outlet", shapedPond, byId(shaped.reaches()).get(shapedPond.outletReachId()));
|
||||
@@ -434,7 +436,8 @@ public class ReachShaperTest {
|
||||
PondPlanner planner = new PondPlanner(settings);
|
||||
ReachShaper shaper = new ReachShaper(settings);
|
||||
List<Pond> water = List.of(new Pond(41L, PondKind.NATURAL, 99, 93, 104, 64, 100f, disk(96, 64, 5), 0L, 0, "water", 96, 64));
|
||||
ShapedNetwork network = PondChannelSettlement.settle(WINDOW, shaper.shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), water, fine, SEED), SEA_LEVEL);
|
||||
ShapedNetwork network = PondChannelSettlement.settle(WINDOW, shaper.shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), water, fine, SEED), SEA_LEVEL);
|
||||
int lowerings = 0;
|
||||
while (network.ponds().get(0).level() < water.get(0).level()) {
|
||||
lowerings++;
|
||||
@@ -442,7 +445,8 @@ public class ReachShaperTest {
|
||||
Pond reflooded = planner.reflood(flat, fine, CupSet.EMPTY, network.ponds().get(0));
|
||||
assertNotNull("reflooded pond at " + network.ponds().get(0).level(), reflooded);
|
||||
water = List.of(reflooded.withOutletReachId(0L));
|
||||
network = PondChannelSettlement.settle(WINDOW, shaper.shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), water, fine, SEED), SEA_LEVEL);
|
||||
network = PondChannelSettlement.settle(WINDOW, shaper.shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), water, fine, SEED), SEA_LEVEL);
|
||||
}
|
||||
Pond settled = network.ponds().get(0);
|
||||
Map<Long, Reach> byId = byId(network.reaches());
|
||||
@@ -479,7 +483,8 @@ public class ReachShaperTest {
|
||||
assertFalse("no DEM node inside the pond", mask.contains(32, 40) || mask.contains(32, 48));
|
||||
Pond pond = new Pond(51L, PondKind.NATURAL, 99, 94, 32, 34, 100f, mask, 0L, 0, "water", 32, 43);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Pond shapedPond = shaped.ponds().get(0);
|
||||
Reach outlet = byId(shaped.reaches()).get(shapedPond.outletReachId());
|
||||
assertNotNull(outlet);
|
||||
@@ -508,7 +513,8 @@ public class ReachShaperTest {
|
||||
PondMask shore = rectangle(72, 52, 18, 3);
|
||||
Pond pond = new Pond(81L, PondKind.NATURAL, 99, 94, 72, 64, 100f, shore, 0L, 0, "water", 104, 56);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> shore.contains((int) x, (int) z) ? 94D : 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Reach outlet = byId(shaped.reaches()).get(shaped.ponds().get(0).outletReachId());
|
||||
assertNotNull("the pond drains through an outlet along its shore", outlet);
|
||||
float farthestHeld = 0f;
|
||||
@@ -539,7 +545,8 @@ public class ReachShaperTest {
|
||||
Pond side = new Pond(62L, PondKind.NATURAL, 99, 94, 104, 60, 100f, disk(104, 56, 3), 0L, 0, "water", 104, 56);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> fed.mask().contains((int) x, (int) z)
|
||||
|| side.mask().contains((int) x, (int) z) ? 94D : 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(fed, side), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(fed, side), fine, SEED);
|
||||
assertEquals("both ponds drain through the same exit", shaped.ponds().get(0).outletReachId(), shaped.ponds().get(1).outletReachId());
|
||||
Reach outlet = byId(shaped.reaches()).get(shaped.ponds().get(1).outletReachId());
|
||||
assertNotNull(outlet);
|
||||
@@ -567,7 +574,8 @@ public class ReachShaperTest {
|
||||
surface.set(19, 1, 30f);
|
||||
Pond pond = new Pond(71L, PondKind.NATURAL, 59, 54, 136, 8, 60f, disk(128, 8, 7), 0L, 0, "water", 128, 8);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> x < 138D ? 60D : 35D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(surface, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Pond shapedPond = shaped.ponds().get(0);
|
||||
Reach outlet = byId(shaped.reaches()).get(shapedPond.outletReachId());
|
||||
assertNotNull(outlet);
|
||||
@@ -599,7 +607,8 @@ public class ReachShaperTest {
|
||||
}
|
||||
Pond pond = new Pond(73L, PondKind.NATURAL, 59, 54, 136, 8, 60f, disk(128, 8, 7), 0L, 0, "water", 128, 8);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> x >= SLIVER_X && x < SLIVER_X + 8D ? 35D : 60D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), List.of(pond), fine,
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(surface, SEA_LEVEL), List.of(pond), fine,
|
||||
SEED);
|
||||
Pond shapedPond = shaped.ponds().get(0);
|
||||
Reach outlet = byId(shaped.reaches()).get(shapedPond.outletReachId());
|
||||
@@ -859,7 +868,8 @@ public class ReachShaperTest {
|
||||
accumulation[flat.index(12, 10)] = 300f;
|
||||
Pond pond = new Pond(21L, PondKind.NATURAL, 101, 98, 0, 0, 102f, rectangle(80, 48, 9, 9), 0L, 0, "water", 96, 64);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Reach outlet = byId(shaped.reaches()).get(shaped.ponds().get(0).outletReachId());
|
||||
assertNotNull(outlet);
|
||||
assertTrue(pond.mask().contains(Math.round(outlet.xs()[0]), Math.round(outlet.zs()[0])));
|
||||
@@ -888,7 +898,8 @@ public class ReachShaperTest {
|
||||
}
|
||||
surface.set(width - 1, 1, 30f);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 45D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), List.of(), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(surface, SEA_LEVEL), List.of(), fine, SEED);
|
||||
int mouths = 0;
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
int last = reach.xs().length - 1;
|
||||
@@ -925,7 +936,8 @@ public class ReachShaperTest {
|
||||
Pond sunken = new Pond(77L, PondKind.NATURAL, SEA_LEVEL - 1, SEA_LEVEL - 6, CELL, CELL, SEA_LEVEL + 0.5f,
|
||||
new PondMask(0, CELL, CELL, 2, 1, new long[]{0b11L}), 0L, 0, "water", 0, CELL);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 45D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), List.of(sunken), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(surface, SEA_LEVEL), List.of(sunken), fine, SEED);
|
||||
int mouths = 0;
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
for (int grade : reach.grade()) {
|
||||
@@ -1234,7 +1246,8 @@ public class ReachShaperTest {
|
||||
Pond fed = new Pond(32L, PondKind.NATURAL, 100 + maxFill + 4, 98, 192, 128, 100 + maxFill + 5f, rectangle(160, 112, 9, 9), 0L, 0,
|
||||
"water", 176, 128);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(looped, fed), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(looped, fed), fine, SEED);
|
||||
int inflows = 0;
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
if (reach.downstreamId() == 0L && endsIn(reach, fed)) {
|
||||
@@ -1306,7 +1319,8 @@ public class ReachShaperTest {
|
||||
channels.set(cell);
|
||||
}
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(), fine, SEED);
|
||||
Map<Long, Reach> byId = byId(shaped.reaches());
|
||||
int links = 0;
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
@@ -1418,7 +1432,8 @@ public class ReachShaperTest {
|
||||
flow(flat, receivers, accumulation, channels, i, 8, i + 1 < flat.width() ? i + 1 : -1, 8, 6400f);
|
||||
}
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 100D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(), fine, SEED);
|
||||
Map<Long, List<Reach>> feeders = feeders(shaped.reaches());
|
||||
assertEquals("one confluence " + feeders.keySet(), 1, feeders.size());
|
||||
Map.Entry<Long, List<Reach>> confluence = feeders.entrySet().iterator().next();
|
||||
@@ -1469,7 +1484,8 @@ public class ReachShaperTest {
|
||||
Pond pond = new Pond(71L, PondKind.NATURAL, 99, 94, 104, 64, 100f, disk(96, 64, 5), 0L, 0, "water", 96, 64);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> Math.hypot(x - 96D, z - 64D) <= 5D ? 94D
|
||||
: x <= 104D ? 100D : 100D - 0.5D * (x - 104D)), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels, sea(flat), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, flat, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(flat, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Reach outlet = byId(shaped.reaches()).get(shaped.ponds().get(0).outletReachId());
|
||||
assertNotNull("the pond drains through an outlet", outlet);
|
||||
assertEquals("the outlet is a river", "river", outlet.tier().name());
|
||||
@@ -1586,7 +1602,7 @@ public class ReachShaperTest {
|
||||
BitSet channels = ChannelHeads.keep(network.grid(), network.grid().values(), network.receivers(), candidates,
|
||||
settings.drainage().headRelief(), index -> false, index -> true);
|
||||
List<Reach> paths = new ReachShaper(settings).coarsePaths(network.grid(), network.receivers(), network.accumulation(), channels,
|
||||
sea(network.grid()), SEED);
|
||||
SeaCells.atOrBelow(network.grid(), SEA_LEVEL), SEED);
|
||||
assertFalse(paths.isEmpty());
|
||||
Map<Long, Reach> byId = byId(paths);
|
||||
int mouths = 0;
|
||||
@@ -2044,7 +2060,8 @@ public class ReachShaperTest {
|
||||
Pond pond = new Pond(73L, kind, OUTLET_POND_LEVEL, OUTLET_POND_LEVEL - 4, 136, 8, OUTLET_POND_LEVEL + 0.5f, disk(128, 8, 7), 0L, 0,
|
||||
"water", 128, 8);
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> x < 160D ? SEA_LEVEL + 4D : SEA_LEVEL - 5D), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), List.of(pond), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(surface, SEA_LEVEL), List.of(pond), fine, SEED);
|
||||
Pond shapedPond = shaped.ponds().get(0);
|
||||
assertEquals(kind + " level", OUTLET_POND_LEVEL, shapedPond.level());
|
||||
Reach outlet = byId(shaped.reaches()).get(shapedPond.outletReachId());
|
||||
@@ -2089,7 +2106,8 @@ public class ReachShaperTest {
|
||||
}
|
||||
float mouthX = (width - 1) * CELL;
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> SEA_LEVEL + 1D + rise * Math.max(0D, mouthX - x)), FINE, false, 1 << 16);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), List.of(), fine, SEED);
|
||||
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels,
|
||||
SeaCells.atOrBelow(surface, SEA_LEVEL), List.of(), fine, SEED);
|
||||
assertEquals(1, shaped.reaches().size());
|
||||
return shaped.reaches().get(0);
|
||||
}
|
||||
@@ -2301,15 +2319,7 @@ public class ReachShaperTest {
|
||||
|
||||
private static ShapedNetwork shape(HydrologySettings settings, Network network) {
|
||||
return new ReachShaper(settings).shape(WINDOW, network.grid(), network.receivers(), network.accumulation(), network.channels(),
|
||||
sea(network.grid()), network.ponds(), network.fine(), SEED);
|
||||
}
|
||||
|
||||
private static boolean[] sea(DemGrid filled) {
|
||||
boolean[] sea = new boolean[filled.values().length];
|
||||
for (int cell = 0; cell < sea.length; cell++) {
|
||||
sea[cell] = filled.values()[cell] <= SEA_LEVEL;
|
||||
}
|
||||
return sea;
|
||||
SeaCells.atOrBelow(network.grid(), SEA_LEVEL), network.ponds(), network.fine(), SEED);
|
||||
}
|
||||
|
||||
private static Network network(HydrologySettings settings, DoubleBinaryOperator height, int width, int depth, float threshold,
|
||||
|
||||
@@ -72,7 +72,8 @@ public final class DeltaCoast {
|
||||
row(surface, receivers, accumulation, channels, neighbourZ);
|
||||
}
|
||||
HeightLattice fine = new HeightLattice(new Terrain(ground), FINE, false, 1 << 16);
|
||||
return new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, sea(surface), ponds, fine, seed);
|
||||
return new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, SeaCells.atOrBelow(surface, SEA_LEVEL), ponds,
|
||||
fine, seed);
|
||||
}
|
||||
|
||||
public static double ground(double x, double z) {
|
||||
@@ -106,14 +107,6 @@ public final class DeltaCoast {
|
||||
return fan;
|
||||
}
|
||||
|
||||
private static boolean[] sea(DemGrid filled) {
|
||||
boolean[] sea = new boolean[filled.values().length];
|
||||
for (int cell = 0; cell < sea.length; cell++) {
|
||||
sea[cell] = filled.values()[cell] <= SEA_LEVEL;
|
||||
}
|
||||
return sea;
|
||||
}
|
||||
|
||||
private static void row(DemGrid grid, int[] receivers, float[] accumulation, BitSet channels, int z) {
|
||||
int j = (z - grid.originZ()) / CELL;
|
||||
for (int x = 0; x < SEA_X; x += CELL) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package art.arcane.iris.testsupport;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
|
||||
public final class SeaCells {
|
||||
private SeaCells() {
|
||||
}
|
||||
|
||||
public static boolean[] atOrBelow(DemGrid filled, int seaLevel) {
|
||||
boolean[] sea = new boolean[filled.values().length];
|
||||
for (int cell = 0; cell < sea.length; cell++) {
|
||||
sea[cell] = filled.values()[cell] <= seaLevel;
|
||||
}
|
||||
return sea;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user