mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Report unlinked reach water
- Add unlinkedWater to the hydrology raster metrics: wet cells along a reach polyline that the stream link radius cannot join - Print it per window from hydrologyProbe, without failing the run
This commit is contained in:
3 files changed
+89
No files matched your search
@@ -167,6 +167,7 @@ public final class HydrologyProbe {
|
||||
HydrologyBlockMetrics.Counts blocks = blockMetrics.count(key);
|
||||
generationErrors += blocks.errors();
|
||||
HydrologyUnderground.Counts underground = underground(key, plan);
|
||||
System.out.println("IRIS_HYDROLOGY_LINK wx=" + key.wx() + " wz=" + key.wz() + " unlinkedWater=" + rasterMetrics.unlinkedWater(plan));
|
||||
HydrologyColdRuns.ColdRun cold = colds.get(key);
|
||||
measured.add(new HydrologyReport.WindowMetrics(key, cold.millis(), cold.naturalSamples(), cold.baseSamples(),
|
||||
plans.windowCpu(key), plans.regionCpu(key.region()), cold.depth(), plans.landTiles(key), planMetrics.rivers(key),
|
||||
|
||||
@@ -11,7 +11,11 @@ import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.raster.NaturalHeights;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStreamLowering;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
final class HydrologyRasterMetrics {
|
||||
@@ -22,6 +26,7 @@ final class HydrologyRasterMetrics {
|
||||
private final Rasters rasters;
|
||||
private final NaturalHeights naturalHeight;
|
||||
private final HydrologyWindows.WindowRange range;
|
||||
private static final int LINK_SEARCH = 32;
|
||||
private final Consumer<String> examples;
|
||||
|
||||
@FunctionalInterface
|
||||
@@ -89,6 +94,66 @@ final class HydrologyRasterMetrics {
|
||||
return rising;
|
||||
}
|
||||
|
||||
long unlinkedWater(WindowPlan plan) {
|
||||
long unlinked = 0L;
|
||||
for (Reach reach : plan.reaches()) {
|
||||
int lastX = 0;
|
||||
int lastZ = 0;
|
||||
boolean wet = false;
|
||||
for (int point = 0; point + 1 < reach.xs().length; point++) {
|
||||
float fromX = reach.xs()[point];
|
||||
float fromZ = reach.zs()[point];
|
||||
float toX = reach.xs()[point + 1];
|
||||
float toZ = reach.zs()[point + 1];
|
||||
int steps = Math.max(1, (int) Math.ceil(Math.max(Math.abs(toX - fromX), Math.abs(toZ - fromZ))));
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
int x = (int) Math.floor(fromX + (toX - fromX) * step / steps);
|
||||
int z = (int) Math.floor(fromZ + (toZ - fromZ) * step / steps);
|
||||
if (!wetInRange(x, z)) {
|
||||
continue;
|
||||
}
|
||||
if (wet && !linkedByWater(lastX, lastZ, x, z)) {
|
||||
unlinked++;
|
||||
examples.accept("water gap along reach " + reach.id() + " from " + lastX + "," + lastZ + " to " + x + "," + z);
|
||||
}
|
||||
lastX = x;
|
||||
lastZ = z;
|
||||
wet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return unlinked;
|
||||
}
|
||||
|
||||
private boolean wetInRange(int x, int z) {
|
||||
return range.containsBlock(x, z) && rasters.get(x >> 4, z >> 4).role(x & 15, z & 15).wet();
|
||||
}
|
||||
|
||||
private boolean linkedByWater(int fromX, int fromZ, int toX, int toZ) {
|
||||
Set<Long> seen = new HashSet<>();
|
||||
ArrayDeque<int[]> open = new ArrayDeque<>();
|
||||
open.add(new int[]{fromX, fromZ});
|
||||
seen.add(HydrologyVoxels.columnKey(fromX, fromZ));
|
||||
int limit = StructureStreamLowering.LINK + LINK_SEARCH + Math.max(Math.abs(toX - fromX), Math.abs(toZ - fromZ));
|
||||
while (!open.isEmpty()) {
|
||||
int[] cell = open.poll();
|
||||
if (Math.max(Math.abs(cell[0] - toX), Math.abs(cell[1] - toZ)) <= StructureStreamLowering.LINK) {
|
||||
return true;
|
||||
}
|
||||
for (int dz = -StructureStreamLowering.LINK; dz <= StructureStreamLowering.LINK; dz++) {
|
||||
for (int dx = -StructureStreamLowering.LINK; dx <= StructureStreamLowering.LINK; dx++) {
|
||||
int x = cell[0] + dx;
|
||||
int z = cell[1] + dz;
|
||||
if (Math.max(Math.abs(x - fromX), Math.abs(z - fromZ)) <= limit && wetInRange(x, z)
|
||||
&& seen.add(HydrologyVoxels.columnKey(x, z))) {
|
||||
open.add(new int[]{x, z});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
long chunkSeams(WindowKey key) {
|
||||
long mismatches = 0L;
|
||||
int minX = key.wx() * WindowKey.SIZE;
|
||||
|
||||
@@ -156,6 +156,29 @@ public class HydrologyMetricsTest {
|
||||
assertRises(0L, null, List.of(mouth), List.of(), level);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterAlongAReachMustStayWithinTheStreamLinkRadius() {
|
||||
Reach reach = reach(1L, STREAM, 0L, 1000f, new int[]{60, 60}, 10f, 10f, 30f, 10f);
|
||||
Map<Long, Column> linked = new HashMap<>();
|
||||
for (int x = 10; x <= 30; x += 2) {
|
||||
linked.put(HydrologyVoxels.columnKey(x, 10), new Column(WaterRole.CHANNEL, 60, 58, 1L));
|
||||
}
|
||||
assertEquals(0L, unlinked(reach, linked));
|
||||
|
||||
Map<Long, Column> gapped = new HashMap<>(linked);
|
||||
gapped.remove(HydrologyVoxels.columnKey(20, 10));
|
||||
assertEquals(1L, unlinked(reach, gapped));
|
||||
}
|
||||
|
||||
private static long unlinked(Reach reach, Map<Long, Column> columns) {
|
||||
WindowPlan plan = plan(WEST, List.of(reach), List.of());
|
||||
HydrologyPlanMetrics plans = new HydrologyPlanMetrics(SETTINGS, windows(plan, plan(EAST, List.of(), List.of())), List.of(), BOTH, ignored -> {
|
||||
});
|
||||
HydrologyRasterMetrics metrics = new HydrologyRasterMetrics(SETTINGS, plans, rasters(columns), (x, z) -> NATURAL, BOTH, ignored -> {
|
||||
});
|
||||
return metrics.unlinkedWater(plan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aReachEndingInItsPondAtThePondsSnappedHeadDoesNotRise() {
|
||||
Pond odd = pond(10L, 51, square(96, 96, 3), 0L, 100, 100);
|
||||
|
||||
Reference in new issue
Block a user