mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Confluence review fixes
- Spread the junction step of feeders on tiers without cascades through the grader's spread rule, never moving outlet zone or held points - Extract ReachGrader.spreadPoint from the spread pass and clamp it so it only lowers - Throw when a downstream reach starts above its feeder's end, naming both reach ids and the junction - Restore the per-reach waterfall check in gradeNeverRisesDownstream, excluding drops that land at or below the stepped twin's junction level - Add ConfluenceGraderTest for spread junction steps, the fixed-point exception and the fail-closed junction - Describe junction spreading in the cascades setting and recapture the schema digest
This commit is contained in:
1 parent
4cf141b97b
commit
52761e1784
6 files changed
+169
-24
No files matched your search
+110
@@ -0,0 +1,110 @@
|
||||
package art.arcane.iris.generation.hydrology.water;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfluenceGraderTest {
|
||||
private static final long SEED = 1337L;
|
||||
private static final int SEA_LEVEL = 40;
|
||||
private static final int JUNCTION = 100;
|
||||
private static final int POOL_EDGE_Z = -12;
|
||||
private static final int FEEDER_Z = -48;
|
||||
|
||||
@Test
|
||||
public void spreadFeederMeetsALowerRiverWithoutAStepAtThePoolEdge() {
|
||||
int[] cascading = graded(tier(true), false);
|
||||
assertEquals("cascading feeder keeps its junction step " + Arrays.toString(cascading), 3,
|
||||
cascading[poolEdge() - 1] - cascading[poolEdge()]);
|
||||
|
||||
int[] spread = graded(tier(false), false);
|
||||
for (int point = poolEdge(); point < spread.length; point++) {
|
||||
assertEquals("pooled point " + point + " " + Arrays.toString(spread), JUNCTION, spread[point]);
|
||||
}
|
||||
for (int point = 1; point < spread.length; point++) {
|
||||
int drop = spread[point - 1] - spread[point];
|
||||
assertTrue("drop " + drop + " at point " + point + " " + Arrays.toString(spread), drop >= 0 && drop <= 1);
|
||||
}
|
||||
assertEquals("spreading stays near the junction " + Arrays.toString(spread), feederGrade(FEEDER_Z), spread[0]);
|
||||
|
||||
int[] blocked = graded(tier(false), true);
|
||||
assertEquals("fixed points keep the junction step " + Arrays.toString(blocked), 3, blocked[poolEdge() - 1] - blocked[poolEdge()]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downstreamStartAboveTheFeederEndFailsClosed() {
|
||||
HydrologyTier tier = tier(true);
|
||||
ReachDraft feeder = line(tier, 11L, 0f, FEEDER_Z, 0f, 0f, 2f, z -> JUNCTION);
|
||||
ReachDraft river = line(tier, 12L, 0f, 0f, 64f, 0f, 8f, z -> JUNCTION + 1);
|
||||
feeder.downstream = 1;
|
||||
river.incoming = new int[]{0};
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> ConfluenceGrader.level(List.of(feeder, river), new int[]{0, 1}));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("11") && failure.getMessage().contains("12"));
|
||||
}
|
||||
|
||||
private static int[] graded(HydrologyTier tier, boolean fixedApproach) {
|
||||
ReachDraft feeder = line(tier, 21L, 0f, FEEDER_Z, 0f, 0f, 2f, ConfluenceGraderTest::feederGrade);
|
||||
ReachDraft river = line(tier, 22L, 0f, 0f, 64f, 0f, 8f, z -> JUNCTION);
|
||||
if (fixedApproach) {
|
||||
Arrays.fill(feeder.outletZone, 0, poolEdge(), true);
|
||||
}
|
||||
feeder.downstream = 1;
|
||||
river.incoming = new int[]{0};
|
||||
ConfluenceGrader.level(List.of(feeder, river), new int[]{0, 1});
|
||||
return feeder.grade;
|
||||
}
|
||||
|
||||
private static int feederGrade(int z) {
|
||||
if (z == 0) {
|
||||
return JUNCTION;
|
||||
}
|
||||
if (z >= POOL_EDGE_Z) {
|
||||
return JUNCTION + 2;
|
||||
}
|
||||
return JUNCTION + 3 + Math.floorDiv(POOL_EDGE_Z - 1 - z, 2);
|
||||
}
|
||||
|
||||
private static int poolEdge() {
|
||||
return POOL_EDGE_Z - FEEDER_Z;
|
||||
}
|
||||
|
||||
private static ReachDraft line(HydrologyTier tier, long id, float fromX, float fromZ, float toX, float toZ, float halfWidth,
|
||||
IntUnaryOperator grade) {
|
||||
int points = Math.round((float) Math.hypot(toX - fromX, toZ - fromZ)) + 1;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
float t = point / (points - 1f);
|
||||
xs[point] = fromX + t * (toX - fromX);
|
||||
zs[point] = fromZ + t * (toZ - fromZ);
|
||||
}
|
||||
ReachFitter.Fitted fitted = new ReachFitter.Fitted(xs, zs, new float[points], new float[points], new boolean[points], new float[points]);
|
||||
ReachDraft draft = new ReachDraft(new ReachTracer.Chain(new int[]{0, 1}, ReachTracer.End.EDGE, -1), id, tier, 0f, Integer.MIN_VALUE, fitted);
|
||||
draft.grade = new int[points];
|
||||
draft.halfWidth = new float[points];
|
||||
draft.outletZone = new boolean[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
draft.grade[point] = grade.applyAsInt(Math.round(zs[point]));
|
||||
draft.halfWidth[point] = halfWidth;
|
||||
}
|
||||
return draft;
|
||||
}
|
||||
|
||||
private static HydrologyTier tier(boolean cascades) {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
for (IrisHydrologyTier tier : config.getTiers()) {
|
||||
tier.setCascades(cascades);
|
||||
}
|
||||
return HydrologySettings.compile(config, SEED, SEA_LEVEL, -64, 320).tiers().get(0);
|
||||
}
|
||||
}
|
||||
+10
-11
@@ -58,8 +58,6 @@ public class ReachShaperTest {
|
||||
int[] totals = new int[6];
|
||||
int cascadingSteps = 0;
|
||||
int spreadSteps = 0;
|
||||
int cascadingFalls = 0;
|
||||
int spreadFalls = 0;
|
||||
for (int trial = 0; trial < 200; trial++) {
|
||||
Network network = network(cascading, randomTerrain(random), 40, 40, 2000f, trial % 4 == 0);
|
||||
ShapedNetwork stepped = shape(cascading, network);
|
||||
@@ -71,10 +69,11 @@ public class ReachShaperTest {
|
||||
Reach twin = steppedById.get(reach.id());
|
||||
assertNotNull(twin);
|
||||
int fall = reach.tier().waterfallMinimumDrop();
|
||||
spreadSteps += dropsBetween(reach, 2, fall);
|
||||
cascadingSteps += dropsBetween(twin, 2, fall);
|
||||
spreadFalls += dropsBetween(reach, fall, Integer.MAX_VALUE);
|
||||
cascadingFalls += dropsBetween(twin, fall, Integer.MAX_VALUE);
|
||||
int junction = twin.downstreamId() == 0L ? Integer.MIN_VALUE : twin.grade()[twin.grade().length - 1];
|
||||
assertTrue("trial " + trial + " " + reach + " gained a waterfall",
|
||||
dropsAbove(reach, junction, fall, Integer.MAX_VALUE) <= dropsAbove(twin, junction, fall, Integer.MAX_VALUE));
|
||||
spreadSteps += dropsAbove(reach, junction, 2, fall);
|
||||
cascadingSteps += dropsAbove(twin, junction, 2, fall);
|
||||
}
|
||||
}
|
||||
assertTrue("reaches " + totals[0], totals[0] > 4000);
|
||||
@@ -82,7 +81,6 @@ public class ReachShaperTest {
|
||||
assertTrue("links " + totals[2], totals[2] > 1000);
|
||||
assertTrue("mouth points " + totals[3], totals[3] > 100);
|
||||
assertTrue("pond outlets " + totals[4], totals[4] > 40);
|
||||
assertTrue("waterfall drops spread " + spreadFalls + " kept " + cascadingFalls, spreadFalls <= cascadingFalls);
|
||||
assertTrue("cascade drops spread " + spreadSteps + " kept " + cascadingSteps, 2 * spreadSteps < cascadingSteps);
|
||||
}
|
||||
|
||||
@@ -1293,11 +1291,12 @@ public class ReachShaperTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static int dropsBetween(Reach reach, int minimum, int limit) {
|
||||
private static int dropsAbove(Reach reach, int floor, int minimum, int limit) {
|
||||
int[] grade = reach.grade();
|
||||
int count = 0;
|
||||
for (int index = 1; index < reach.grade().length; index++) {
|
||||
int drop = reach.grade()[index - 1] - reach.grade()[index];
|
||||
count += drop >= minimum && drop < limit ? 1 : 0;
|
||||
for (int index = 1; index < grade.length; index++) {
|
||||
int drop = grade[index - 1] - grade[index];
|
||||
count += drop >= minimum && drop < limit && grade[index] > floor ? 1 : 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "0b7bc58cb81a7e630d13662b2157868bd306f3afef571942dc5b8e667323a250";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "e592219e3205fc63395c5f85f3630a9f018670370a56614e5571252fb21fb9d5";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
Reference in new issue
Block a user