mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Outlets keep their width
- Pond outlets skip the junction width flare, so an outlet whose exit node takes a tributary leaves its pond at its own width - Cross-window links into a pond outlet clamp its grade without rebasing its width or depth - The cross-window width blend always measures from the downstream reach's first vertex - Planner and cross-window tests cover narrow and wide tributaries at an outlet's exit node
This commit is contained in:
1 parent
1827ec1cc6
commit
41e38debad
5 files changed
+74
-24
No files matched your search
@@ -317,8 +317,8 @@ final class ChunkFeatures {
|
||||
}
|
||||
|
||||
private Reach link(Reach reach, WindowKey owner) {
|
||||
Reach linked = feederLink(reach, owner);
|
||||
Integer pondLevel = outletLevel(reach, owner);
|
||||
Reach linked = feederLink(reach, owner, pondLevel != null);
|
||||
return settle(reach, pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel), owner);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ final class ChunkFeatures {
|
||||
return found;
|
||||
}
|
||||
|
||||
private Reach feederLink(Reach downstream, WindowKey owner) {
|
||||
private Reach feederLink(Reach downstream, WindowKey owner, boolean outlet) {
|
||||
int junction = junction(downstream);
|
||||
WindowKey link = windowAt(downstream, junction);
|
||||
List<Reach> joining = feeders(link, downstream.id());
|
||||
@@ -375,7 +375,7 @@ final class ChunkFeatures {
|
||||
for (Reach reach : joining) {
|
||||
feeders.add(cornerBlock(reach) == block ? resolve(reach, link) : reach);
|
||||
}
|
||||
return link.equals(owner) ? LinkBlend.clamp(downstream, feeders) : LinkBlend.blend(downstream, feeders, junction);
|
||||
return link.equals(owner) || outlet ? LinkBlend.clamp(downstream, feeders) : LinkBlend.blend(downstream, feeders);
|
||||
}
|
||||
|
||||
private List<Reach> feeders(WindowKey key, long downstreamId) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class LinkBlend {
|
||||
return from + (to - from) * share;
|
||||
}
|
||||
|
||||
static Reach blend(Reach downstream, List<Reach> feeders, int junction) {
|
||||
static Reach blend(Reach downstream, List<Reach> feeders) {
|
||||
float width = 0f;
|
||||
float depth = 0f;
|
||||
for (Reach feeder : feeders) {
|
||||
@@ -34,16 +34,15 @@ public final class LinkBlend {
|
||||
float[] zs = downstream.zs();
|
||||
float[] halfWidth = downstream.halfWidth().clone();
|
||||
float[] depths = downstream.depth().clone();
|
||||
float widthShift = width - halfWidth[junction];
|
||||
float depthShift = depth - depths[junction];
|
||||
float[] along = new float[xs.length];
|
||||
for (int point = 1; point < xs.length; point++) {
|
||||
along[point] = along[point - 1] + (float) Math.hypot(xs[point] - xs[point - 1], zs[point] - zs[point - 1]);
|
||||
}
|
||||
float widthShift = width - halfWidth[0];
|
||||
float depthShift = depth - depths[0];
|
||||
float along = 0f;
|
||||
for (int point = 0; point < xs.length; point++) {
|
||||
float fromJunction = along[point] - along[junction];
|
||||
halfWidth[point] += blend(widthShift, 0f, fromJunction);
|
||||
depths[point] += blend(depthShift, 0f, fromJunction);
|
||||
if (point > 0) {
|
||||
along += (float) Math.hypot(xs[point] - xs[point - 1], zs[point] - zs[point - 1]);
|
||||
}
|
||||
halfWidth[point] += blend(widthShift, 0f, along);
|
||||
depths[point] += blend(depthShift, 0f, along);
|
||||
}
|
||||
return regraded(downstream, clamped(downstream.grade(), lowestEnd(feeders)), halfWidth, depths);
|
||||
}
|
||||
|
||||
@@ -488,7 +488,7 @@ public final class ReachShaper {
|
||||
|
||||
private static void widths(ReachDraft draft, float upstream, float feederEnd) {
|
||||
int count = draft.xs.length;
|
||||
boolean flare = draft.incoming.length > 0;
|
||||
boolean flare = draft.incoming.length > 0 && !draft.outlet;
|
||||
boolean taper = !flare && !draft.outlet;
|
||||
float[] distance = distances(draft.xs, draft.zs);
|
||||
float running = upstream;
|
||||
|
||||
+22
-10
@@ -678,20 +678,23 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ledInOutletWidthBlendsFromItsJunctionAcrossAWindowLine() {
|
||||
public void ledInOutletKeepsItsOwnWidthBelowATributaryAcrossAWindowLine() {
|
||||
HydrologyTier narrow = tier("river", 1f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier medium = tier("river", 4f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier wide = tier("river", 8f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach outlet = ledIn(line(211L, narrow, 0L, 508f, 200f, 600f, 200f, (x, z) -> 66), 494f, 200f);
|
||||
Reach feeder = line(212L, wide, outlet.id(), 508f, 120f, 508f, 200f, (x, z) -> 66);
|
||||
Pond pond = new Pond(210L, PondKind.NATURAL, 66, 58, 496, 200, 67.5f, circle(478, 200, 17, 1), outlet.id(), 0, "water", 478, 200);
|
||||
assertTrue("the lead-in starts in the pond", pond.mask().contains(494, 200));
|
||||
assertFalse("the junction lies off the pond", pond.mask().contains(508, 200));
|
||||
assertEquals(new WindowKey(0, 0), WindowKey.containing(508, 200));
|
||||
assertEquals(new WindowKey(1, 0), WindowKey.containing(600, 200));
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(outlet).reach(feeder).pond(pond);
|
||||
assertTrue("the outlet is half the feeder's width 8 blocks below the junction", scene.water(516, 204));
|
||||
assertTrue("the outlet is still blending 10 blocks below the junction", scene.water(518, 202));
|
||||
assertFalse("the narrow outlet width returns past the blend", scene.water(530, 202));
|
||||
|
||||
Scene spout = outletBelowATributary(medium, narrow);
|
||||
for (int x = 497; x <= 530; x++) {
|
||||
assertTrue("the outlet keeps its half-width 4 below a narrow tributary at x=" + x, spout.water(x, 203) && spout.water(x, 197));
|
||||
assertFalse("the outlet is no wider than its half-width 4 at x=" + x, spout.water(x, 205));
|
||||
}
|
||||
|
||||
Scene flood = outletBelowATributary(narrow, wide);
|
||||
assertFalse("the outlet keeps its half-width 1 below a wide tributary on the lip", flood.water(500, 205));
|
||||
assertFalse("the outlet keeps its half-width 1 below a wide tributary 9 blocks below the junction", flood.water(517, 202));
|
||||
assertTrue("the outlet centre line stays water", flood.water(517, 200));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1183,6 +1186,15 @@ public class ChunkWaterRasterTest {
|
||||
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), xs, zs, grade, halfWidth, depth, style, reach.catchment());
|
||||
}
|
||||
|
||||
private static Scene outletBelowATributary(HydrologyTier outletTier, HydrologyTier tributaryTier) {
|
||||
Reach outlet = ledIn(line(211L, outletTier, 0L, 508f, 200f, 600f, 200f, (x, z) -> 66), 494f, 200f);
|
||||
Reach tributary = line(212L, tributaryTier, outlet.id(), 508f, 120f, 508f, 200f, (x, z) -> 66);
|
||||
Pond pond = new Pond(210L, PondKind.NATURAL, 66, 58, 496, 200, 67.5f, circle(478, 200, 17, 1), outlet.id(), 0, "water", 478, 200);
|
||||
assertTrue("the lead-in starts in the pond", pond.mask().contains(494, 200));
|
||||
assertFalse("the junction lies off the pond", pond.mask().contains(508, 200));
|
||||
return new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(outlet).reach(tributary).pond(pond);
|
||||
}
|
||||
|
||||
private static Reach flared(Reach reach, float width) {
|
||||
int count = reach.xs().length;
|
||||
float[] halfWidth = new float[count];
|
||||
|
||||
@@ -1154,6 +1154,45 @@ public class ReachShaperTest {
|
||||
assertTrue("vertices inside the blend " + blended, blended >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pondOutletTakingATributaryAtItsExitKeepsItsOwnWidth() {
|
||||
HydrologySettings settings = settings(config -> config.setTiers(new KList<>(
|
||||
new IrisHydrologyTier().setHalfWidth(new KList<>(1D, 3D)),
|
||||
new IrisHydrologyTier().setName("river").setMinCatchment(6000D).setHalfWidth(new KList<>(8D, 12D)))));
|
||||
DemGrid flat = outletGrid();
|
||||
int[] receivers = new int[flat.values().length];
|
||||
Arrays.fill(receivers, -1);
|
||||
float[] accumulation = new float[receivers.length];
|
||||
BitSet channels = new BitSet(receivers.length);
|
||||
for (int i = 0; i < flat.width(); i++) {
|
||||
flow(flat, receivers, accumulation, channels, i, 8, i + 1 < flat.width() ? i + 1 : -1, 8, i < 13 ? 1600f + 10f * i : 6400f);
|
||||
}
|
||||
for (int j = flat.depth() - 1; j > 8; j--) {
|
||||
flow(flat, receivers, accumulation, channels, 13, j, 13, j - 1, 1500f + 10f * (flat.depth() - j));
|
||||
}
|
||||
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(flat, receivers, accumulation, channels, 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());
|
||||
Reach tributary = null;
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
if (reach.downstreamId() == outlet.id()) {
|
||||
tributary = reach;
|
||||
}
|
||||
}
|
||||
assertNotNull("a tributary joins the outlet at its exit", tributary);
|
||||
float law = outlet.tier().halfWidth(outlet.catchment());
|
||||
float tributaryEnd = tributary.halfWidth()[tributary.halfWidth().length - 1];
|
||||
assertTrue("the tributary " + tributaryEnd + " is narrower than the outlet " + law, tributaryEnd < 0.5f * law);
|
||||
for (int point = 0; point < outlet.xs().length; point++) {
|
||||
assertEquals("outlet half-width at point " + point + " (" + outlet.xs()[point] + "," + outlet.zs()[point] + ")", law,
|
||||
outlet.halfWidth()[point], 1e-3f);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reachEndingInOceanOrEdgeHasNoDownstream() {
|
||||
HydrologySettings settings = settings(config -> {
|
||||
|
||||
Reference in new issue
Block a user