Junction width flare

- Blend a downstream reach's half-width over its first 16 blocks from the widest feeder end to the width law in ReachShaper.widths
- Move the blend math into the shared LinkBlend.blend(from, to, along) used by both the planner flare and cross-window links
- Measure the cross-window width blend from the junction vertex, so led-in pond outlets blend from their real junction
- Add ReachShaperTest.junctionWidthBlendsOverSixteenBlocks and ChunkWaterRasterTest.ledInOutletWidthBlendsFromItsJunctionAcrossAWindowLine
- Skip reaches whose end lies inside the junction flare in widthFollowsSqrtCatchment
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 18:34:34 -05:00
1 parent 52761e1784
commit b6166bc6fa
5 files changed
+100 -18

No files matched your search

@@ -347,7 +347,7 @@ final class ChunkFeatures {
for (Reach reach : owned) {
feeders.add(cornerBlock(reach) == block ? resolve(reach, link) : reach);
}
return link.equals(owner) ? LinkBlend.clamp(downstream, feeders) : LinkBlend.blend(downstream, feeders);
return link.equals(owner) ? LinkBlend.clamp(downstream, feeders) : LinkBlend.blend(downstream, feeders, junction);
}
private List<Reach> feeders(WindowKey key, long downstreamId) {
@@ -4,13 +4,21 @@ import art.arcane.iris.generation.hydrology.water.Reach;
import java.util.List;
final class LinkBlend {
public final class LinkBlend {
private static final float LENGTH = 16f;
private LinkBlend() {
}
static Reach blend(Reach downstream, List<Reach> feeders) {
public static float blend(float from, float to, float along) {
if (along >= LENGTH) {
return to;
}
float share = Math.max(0f, along) / LENGTH;
return from + (to - from) * share;
}
static Reach blend(Reach downstream, List<Reach> feeders, int junction) {
int end = lowestEnd(feeders);
float width = 0f;
float depth = 0f;
@@ -24,16 +32,14 @@ final class LinkBlend {
int[] grade = clamped(downstream.grade(), end);
float[] halfWidth = downstream.halfWidth().clone();
float[] depths = downstream.depth().clone();
float along = 0f;
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]);
}
for (int point = 0; point < xs.length; point++) {
if (point > 0) {
along += (float) Math.hypot(xs[point] - xs[point - 1], zs[point] - zs[point - 1]);
}
if (along <= LENGTH) {
float share = along / LENGTH;
halfWidth[point] = width + (halfWidth[point] - width) * share;
depths[point] = depth + (depths[point] - depth) * share;
}
float fromJunction = along[point] - along[junction];
halfWidth[point] = blend(width, halfWidth[point], fromJunction);
depths[point] = blend(depth, depths[point], fromJunction);
}
return new Reach(downstream.id(), downstream.tier(), downstream.downstreamId(), xs, zs, grade, halfWidth, depths,
downstream.style(), downstream.catchment());
@@ -4,6 +4,7 @@ import art.arcane.iris.generation.hydrology.grid.CellHash;
import art.arcane.iris.generation.hydrology.grid.DemGrid;
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.raster.LinkBlend;
import java.util.ArrayList;
import java.util.Arrays;
@@ -364,10 +365,13 @@ public final class ReachShaper {
}
unfold(draft);
float upstream = 0f;
float feederEnd = 0f;
for (int index : draft.incoming) {
upstream = Math.max(upstream, drafts.get(index).maxHalfWidth);
ReachDraft feeder = drafts.get(index);
upstream = Math.max(upstream, feeder.maxHalfWidth);
feederEnd = Math.max(feederEnd, feeder.halfWidth[feeder.halfWidth.length - 1]);
}
widths(draft, upstream);
widths(draft, upstream, feederEnd);
restyle(draft);
}
@@ -479,16 +483,19 @@ public final class ReachShaper {
}
}
private static void widths(ReachDraft draft, float upstream) {
private static void widths(ReachDraft draft, float upstream, float feederEnd) {
int count = draft.xs.length;
boolean taper = draft.incoming.length == 0 && !draft.outlet;
boolean flare = draft.incoming.length > 0;
boolean taper = !flare && !draft.outlet;
float[] distance = distances(draft.xs, draft.zs);
float running = upstream;
draft.halfWidth = new float[count];
draft.depth = new float[count];
for (int point = 0; point < count; point++) {
float law = draft.tier.halfWidth(draft.catchments[point]);
if (taper) {
if (flare) {
law = LinkBlend.blend(feederEnd, law, distance[point]);
} else if (taper) {
law *= Math.min(1f, distance[point] / TAPER_LENGTH);
}
float lip = draft.held != null && draft.held[point] ? LIP_HALF_WIDTH : 0f;