Outlet review fixes

- Treat an outlet as led in only when its first vertex lies inside its source pond mask, so links and corner blocks keep the first vertex as the junction when the lead-in was skipped
- Hold and lead in each outlet draft once, from the pond the grader uses as its source, through the new ReachGrader.outletPonds
- Let ocean points keep the sea cap on held outlet stretches
- Add tests for a skipped lead-in junction, two ponds sharing an exit, and a held outlet running into the sea
- Plan the openFractal outlet scenes inline and count only the outlets that detachedOutlets checks, through the new WaterInvariants.checkedPonds
- Reuse the WaterInvariants segment geometry helpers in WindowPlannerTest
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 17:29:53 -05:00
1 parent 0dabc54e88
commit 50839c4833
7 files changed
+154 -82

No files matched your search

@@ -295,6 +295,7 @@ final class ChunkFeatures {
private static final class Links {
private final Map<WindowKey, IndexedWindow> windows;
private final Map<Long, Integer> outletLevels = new HashMap<>();
private final Map<Long, List<PondMask>> outletMasks = new HashMap<>();
private final Map<Long, Reach> resolved = new HashMap<>();
private final Set<Long> resolving = new HashSet<>();
@@ -304,6 +305,7 @@ final class ChunkFeatures {
for (Pond pond : window.plan().ponds()) {
if (pond.outletReachId() != 0L) {
outletLevels.merge(pond.outletReachId(), pond.level(), Math::min);
outletMasks.computeIfAbsent(pond.outletReachId(), ignored -> new ArrayList<>()).add(pond.mask());
}
}
}
@@ -354,7 +356,18 @@ final class ChunkFeatures {
}
private int junction(Reach reach) {
return reach.xs().length > 1 && outletLevels.containsKey(reach.id()) ? 1 : 0;
List<PondMask> masks = outletMasks.get(reach.id());
if (masks == null || reach.xs().length < 2) {
return 0;
}
int x = Math.round(reach.xs()[0]);
int z = Math.round(reach.zs()[0]);
for (PondMask mask : masks) {
if (mask.contains(x, z)) {
return 1;
}
}
return 0;
}
private long cornerBlock(Reach reach) {
@@ -29,13 +29,7 @@ final class ReachGrader {
|| draft.downstream >= 0 && lakeFloor[draft.downstream] && downstreamFloor >= draft.endLevel;
}
int[] levels = ponds.levels().clone();
int[] outletPond = new int[drafts.size()];
Arrays.fill(outletPond, -1);
for (int pond = 0; pond < levels.length; pond++) {
if (ponds.outletDrafts()[pond] >= 0) {
outletPond[ponds.outletDrafts()[pond]] = pond;
}
}
int[] outletPond = outletPonds(ponds.outletDrafts(), drafts.size());
int[][] inflows = inflows(ponds, levels.length);
int[] fed = new int[drafts.size()];
Arrays.fill(fed, Integer.MAX_VALUE);
@@ -58,7 +52,7 @@ final class ReachGrader {
}
int[] grade = profile(drafts, draft);
for (int point = 0; point < grade.length; point++) {
if (draft.held != null && draft.held[point]) {
if (draft.held != null && draft.held[point] && !draft.ocean[point]) {
grade[point] = level;
continue;
}
@@ -84,6 +78,17 @@ final class ReachGrader {
return levels;
}
static int[] outletPonds(int[] outletDrafts, int drafts) {
int[] outletPond = new int[drafts];
Arrays.fill(outletPond, -1);
for (int pond = 0; pond < outletDrafts.length; pond++) {
if (outletDrafts[pond] >= 0) {
outletPond[outletDrafts[pond]] = pond;
}
}
return outletPond;
}
private static int[][] inflows(PondChain ponds, int count) {
int[] sizes = new int[count];
for (int pond : ponds.inflowPond()) {
@@ -61,9 +61,10 @@ public final class ReachShaper {
drafts.get(outlet).outlet = true;
}
}
for (int pond = 0; pond < outletDrafts.length; pond++) {
if (leavesThroughALip(ponds.get(pond), outletDrafts[pond])) {
hold(drafts.get(outletDrafts[pond]), ponds.get(pond).mask());
int[] sources = ReachGrader.outletPonds(outletDrafts, drafts.size());
for (int index = 0; index < sources.length; index++) {
if (leavesThroughALip(ponds, sources[index])) {
hold(drafts.get(index), ponds.get(sources[index]).mask());
}
}
ReachGrader.PondChain chain = pondChain(drafts, ponds, outletDrafts);
@@ -72,9 +73,9 @@ public final class ReachShaper {
for (int index : order) {
finish(drafts, drafts.get(index));
}
for (int pond = 0; pond < outletDrafts.length; pond++) {
if (leavesThroughALip(ponds.get(pond), outletDrafts[pond])) {
leadIn(drafts.get(outletDrafts[pond]), ponds.get(pond).mask());
for (int index = 0; index < sources.length; index++) {
if (leavesThroughALip(ponds, sources[index])) {
leadIn(drafts.get(index), ponds.get(sources[index]).mask());
}
}
List<Pond> linked = new ArrayList<>(ponds.size());
@@ -273,8 +274,8 @@ public final class ReachShaper {
throw new IllegalStateException("Reach and pond links loop through " + (count - size) + " of " + count + " reaches");
}
private static boolean leavesThroughALip(Pond pond, int outletDraft) {
return outletDraft >= 0 && pond.kind() != PondKind.LAKE;
private static boolean leavesThroughALip(List<Pond> ponds, int source) {
return source >= 0 && ponds.get(source).kind() != PondKind.LAKE;
}
private static void hold(ReachDraft draft, PondMask mask) {