mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
Junction pools stay local
- Fix a feeder's start in confluence grading when other reaches feed it, matching cross-window settling - Pool feeder points outside every receiving channel only when they sit at most 5 blocks above the junction level - Keep larger steps beside the receiving bank as a styled cascade or waterfall, in-window and across window lines - Add valley trench, wall tributary and window copy regression tests plus grader unit tests - Move the junction level, seam fall and led-in pool tests to the bank limit and fixed fed starts - Mirror the fixed fed start and bank limit in the tongue invariant and classify held outlet lip riffles
This commit is contained in:
1 parent
0a082f76ee
commit
e108bd3c58
9 files changed
+356
-35
No files matched your search
@@ -9,6 +9,7 @@ public final class ConfluenceGrader {
|
|||||||
public static final float POOL_MARGIN = 2f;
|
public static final float POOL_MARGIN = 2f;
|
||||||
public static final float POOL_CAP = 64f;
|
public static final float POOL_CAP = 64f;
|
||||||
public static final float APPROACH_SLOPE = 0.25f;
|
public static final float APPROACH_SLOPE = 0.25f;
|
||||||
|
public static final int MARGIN_LOWERING = 5;
|
||||||
|
|
||||||
private ConfluenceGrader() {
|
private ConfluenceGrader() {
|
||||||
}
|
}
|
||||||
@@ -21,7 +22,7 @@ public final class ConfluenceGrader {
|
|||||||
double[] arc = arcFromEnd(feeder);
|
double[] arc = arcFromEnd(feeder);
|
||||||
int[] settled = lower(grade, grade, last, level);
|
int[] settled = lower(grade, grade, last, level);
|
||||||
int edge = last;
|
int edge = last;
|
||||||
for (int point = last - 1; point >= 0 && pooled(feeder, fixed, receiving, arc, point); point--) {
|
for (int point = last - 1; point >= 0 && pooled(feeder, fixed, receiving, arc, point, grade[point] - level); point--) {
|
||||||
settled = lower(settled, grade, point, level);
|
settled = lower(settled, grade, point, level);
|
||||||
edge = point;
|
edge = point;
|
||||||
}
|
}
|
||||||
@@ -52,6 +53,7 @@ public final class ConfluenceGrader {
|
|||||||
ReachDraft draft = drafts.get(feeder);
|
ReachDraft draft = drafts.get(feeder);
|
||||||
requireJunction(window, draft, downstream);
|
requireJunction(window, draft, downstream);
|
||||||
boolean[] fixed = draft.fixed();
|
boolean[] fixed = draft.fixed();
|
||||||
|
fixed[0] |= draft.incoming.length > 0;
|
||||||
int waterfallMinimumDrop = draft.tier.waterfallMinimumDrop();
|
int waterfallMinimumDrop = draft.tier.waterfallMinimumDrop();
|
||||||
int[] settled = settle(footprint(draft), draft.grade, fixed, receiving(drafts, downstream, feeder), downstream.grade[0],
|
int[] settled = settle(footprint(draft), draft.grade, fixed, receiving(drafts, downstream, feeder), downstream.grade[0],
|
||||||
waterfallMinimumDrop);
|
waterfallMinimumDrop);
|
||||||
@@ -97,17 +99,20 @@ public final class ConfluenceGrader {
|
|||||||
+ feeder.last() + " of its feeder reach " + feeder.id + " at junction " + feeder.xs[end] + "," + feeder.zs[end]);
|
+ feeder.last() + " of its feeder reach " + feeder.id + " at junction " + feeder.xs[end] + "," + feeder.zs[end]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean pooled(Footprint feeder, boolean[] fixed, List<Footprint> receiving, double[] arc, int point) {
|
private static boolean pooled(Footprint feeder, boolean[] fixed, List<Footprint> receiving, double[] arc, int point, int lowering) {
|
||||||
if (arc[point] > POOL_CAP || fixed[point]) {
|
if (arc[point] > POOL_CAP || fixed[point]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double reach = feeder.halfWidth()[point] + POOL_MARGIN;
|
double reach = feeder.halfWidth()[point] + POOL_MARGIN;
|
||||||
|
boolean beside = false;
|
||||||
for (Footprint channel : receiving) {
|
for (Footprint channel : receiving) {
|
||||||
if (edgeDistance(channel, feeder.xs()[point], feeder.zs()[point]) <= reach) {
|
double edge = edgeDistance(channel, feeder.xs()[point], feeder.zs()[point]);
|
||||||
|
if (edge <= 0D) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
beside |= edge <= reach;
|
||||||
}
|
}
|
||||||
return false;
|
return beside && lowering <= MARGIN_LOWERING;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int approach(int[] grade, boolean[] fixed, double[] arc, int edge, int level, int waterfallMinimumDrop) {
|
private static int approach(int[] grade, boolean[] fixed, double[] arc, int edge, int level, int waterfallMinimumDrop) {
|
||||||
|
|||||||
+162
@@ -0,0 +1,162 @@
|
|||||||
|
package art.arcane.iris.generation.hydrology.plan;
|
||||||
|
|
||||||
|
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||||
|
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||||
|
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||||
|
import art.arcane.iris.generation.hydrology.water.PondPlanner;
|
||||||
|
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||||
|
import art.arcane.iris.generation.hydrology.water.ReachShaper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class ConfluenceIncisionTest {
|
||||||
|
private static final long SEED = 1337L;
|
||||||
|
private static final int DEEP_CUT = 12;
|
||||||
|
private static final double WALL_FOOT = 16D;
|
||||||
|
private static final double WALL_RUN = 15D;
|
||||||
|
private static final double WALL_HEIGHT = 60D;
|
||||||
|
private static final double WALL_FACE_REACH = 24D;
|
||||||
|
private static final double MAX_WALL_CUT = 24D;
|
||||||
|
private static final int MAX_COPY_DIFFERENCE = 4;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void junctionPoolsNeverTrenchASlopingValley() {
|
||||||
|
PlannedScene scene = PlannedScene.plan(SyntheticTerrain.valleySlope(), settings(), 2, 2);
|
||||||
|
int points = 0;
|
||||||
|
int deep = 0;
|
||||||
|
String worst = "";
|
||||||
|
double worstCut = 0D;
|
||||||
|
for (Reach reach : scene.reaches()) {
|
||||||
|
for (int point = 0; point < reach.grade().length; point++) {
|
||||||
|
if (inPond(scene.ponds(), reach.xs()[point], reach.zs()[point])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
points++;
|
||||||
|
double cut = ground(scene, reach, point) - reach.grade()[point];
|
||||||
|
deep += cut > DEEP_CUT ? 1 : 0;
|
||||||
|
if (cut > worstCut) {
|
||||||
|
worstCut = cut;
|
||||||
|
worst = reach + " point " + point + " cut " + cut;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue("reach points checked " + points, points > 10000);
|
||||||
|
assertEquals("reach points cut more than " + DEEP_CUT + " below the valley floor, deepest " + worst, 0, deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void majorDownAWallBesideTheValleyRiverFollowsTheWall() {
|
||||||
|
SyntheticTerrain terrain = SyntheticTerrain.valleyBelowAWall(WALL_FOOT, WALL_RUN, WALL_HEIGHT);
|
||||||
|
HydrologySettings settings = settings();
|
||||||
|
PlannedScene scene = PlannedScene.plan(terrain, settings, 2, 2);
|
||||||
|
List<Reach> face = new ArrayList<>();
|
||||||
|
for (Reach reach : scene.reaches()) {
|
||||||
|
if (reach.tier().equals(settings.majorTier()) && onWallFace(reach)) {
|
||||||
|
face.add(reach);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals("majors running down the wall face " + face, 1, face.size());
|
||||||
|
Reach major = face.get(0);
|
||||||
|
double cut = 0D;
|
||||||
|
int largest = 0;
|
||||||
|
for (int point = 0; point < major.grade().length; point++) {
|
||||||
|
if (!inPond(scene.ponds(), major.xs()[point], major.zs()[point])) {
|
||||||
|
cut = Math.max(cut, ground(scene, major, point) - major.grade()[point]);
|
||||||
|
}
|
||||||
|
if (point > 0) {
|
||||||
|
largest = Math.max(largest, major.grade()[point - 1] - major.grade()[point]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(major + " is cut " + cut + " into the wall", cut <= MAX_WALL_CUT);
|
||||||
|
double tallestFall = WALL_HEIGHT / 2D + major.tier().waterfallMinimumDrop();
|
||||||
|
assertTrue(major + " falls " + largest + " blocks at once down a " + WALL_HEIGHT + "-block wall", largest <= tallestFall);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void neighbouringWindowsGradeTheirSharedReachesAlike() {
|
||||||
|
SyntheticTerrain terrain = SyntheticTerrain.valleySlope();
|
||||||
|
HydrologySettings settings = settings();
|
||||||
|
RegionPlanner regionPlanner = new RegionPlanner(settings, new HeightLattice(terrain, RegionPlanner.CELL, true, 1 << 18),
|
||||||
|
new HeightLattice(terrain, RegionPlanner.FINE_CELL, false, 1 << 20), new PondPlanner(settings), new ReachShaper(settings));
|
||||||
|
WindowPlanner windowPlanner = new WindowPlanner(settings, new HeightLattice(terrain, WindowPlanner.FINE_CELL, false, 1 << 21),
|
||||||
|
new PondPlanner(settings), new ReachShaper(settings));
|
||||||
|
Map<RegionKey, RegionPlan> regions = new HashMap<>();
|
||||||
|
WindowKey west = new WindowKey(0, 0);
|
||||||
|
WindowKey east = new WindowKey(1, 0);
|
||||||
|
Map<Long, Reach> seenFromWest = byId(windowPlanner.compute(west, regionPlans(regionPlanner, regions, west)).allReaches());
|
||||||
|
Map<Long, Reach> seenFromEast = byId(windowPlanner.compute(east, regionPlans(regionPlanner, regions, east)).allReaches());
|
||||||
|
int copies = 0;
|
||||||
|
int worst = 0;
|
||||||
|
String worstCopy = "";
|
||||||
|
for (Map.Entry<Long, Reach> entry : seenFromWest.entrySet()) {
|
||||||
|
Reach fromWest = entry.getValue();
|
||||||
|
Reach fromEast = seenFromEast.get(entry.getKey());
|
||||||
|
if (fromEast == null || !Arrays.equals(fromWest.xs(), fromEast.xs()) || !Arrays.equals(fromWest.zs(), fromEast.zs())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
copies++;
|
||||||
|
for (int point = 0; point < fromWest.grade().length; point++) {
|
||||||
|
int difference = Math.abs(fromWest.grade()[point] - fromEast.grade()[point]);
|
||||||
|
if (difference > worst) {
|
||||||
|
worst = difference;
|
||||||
|
worstCopy = fromWest + " point " + point + " west " + fromWest.grade()[point] + " east " + fromEast.grade()[point];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue("reaches both windows shape alike " + copies, copies > 300);
|
||||||
|
assertTrue("grades of one reach differ by " + worst + " between the windows that plan it: " + worstCopy, worst <= MAX_COPY_DIFFERENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HydrologySettings settings() {
|
||||||
|
return HydrologySettings.compile(new IrisHydrology(), SEED, SyntheticTerrain.SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean onWallFace(Reach reach) {
|
||||||
|
double top = SyntheticTerrain.VALLEY_AXIS - WALL_FOOT - WALL_RUN;
|
||||||
|
double foot = SyntheticTerrain.VALLEY_AXIS - WALL_FOOT;
|
||||||
|
for (int point = 0; point < reach.xs().length; point++) {
|
||||||
|
double z = reach.zs()[point];
|
||||||
|
if (Math.abs(reach.xs()[point] - SyntheticTerrain.VALLEY_AXIS) < WALL_FACE_REACH && z > top && z < foot) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double ground(PlannedScene scene, Reach reach, int point) {
|
||||||
|
return scene.natural((int) Math.floor(reach.xs()[point]), (int) Math.floor(reach.zs()[point]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean inPond(List<Pond> ponds, double x, double z) {
|
||||||
|
for (Pond pond : ponds) {
|
||||||
|
if (pond.mask().contains((int) Math.floor(x), (int) Math.floor(z))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Long, Reach> byId(List<Reach> reaches) {
|
||||||
|
Map<Long, Reach> byId = new HashMap<>(reaches.size() * 2);
|
||||||
|
for (Reach reach : reaches) {
|
||||||
|
byId.put(reach.id(), reach);
|
||||||
|
}
|
||||||
|
return byId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<RegionPlan> regionPlans(RegionPlanner planner, Map<RegionKey, RegionPlan> cache, WindowKey key) {
|
||||||
|
List<RegionPlan> plans = new ArrayList<>();
|
||||||
|
for (RegionKey region : WindowPlanner.lakeRegions(key)) {
|
||||||
|
plans.add(cache.computeIfAbsent(region, planner::plan));
|
||||||
|
}
|
||||||
|
return plans;
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
-10
@@ -10,9 +10,12 @@ import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
|||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.IntBinaryOperator;
|
import java.util.function.IntBinaryOperator;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -41,8 +44,10 @@ public class PlannedSceneTest {
|
|||||||
public void feedersAtALedInOutletsExitPoolBesideTheLeadIn() {
|
public void feedersAtALedInOutletsExitPoolBesideTheLeadIn() {
|
||||||
PlannedScene scene = openFractal();
|
PlannedScene scene = openFractal();
|
||||||
Map<Long, Reach> byId = new HashMap<>();
|
Map<Long, Reach> byId = new HashMap<>();
|
||||||
|
Set<Long> fed = new HashSet<>();
|
||||||
for (Reach reach : scene.reaches()) {
|
for (Reach reach : scene.reaches()) {
|
||||||
byId.put(reach.id(), reach);
|
byId.put(reach.id(), reach);
|
||||||
|
fed.add(reach.downstreamId());
|
||||||
}
|
}
|
||||||
int junctions = 0;
|
int junctions = 0;
|
||||||
int besideTheLeadIn = 0;
|
int besideTheLeadIn = 0;
|
||||||
@@ -58,7 +63,8 @@ public class PlannedSceneTest {
|
|||||||
for (int point = last - 1; point >= 0 && feeder.style()[point] != ReachStyle.POND_OUTLET; point--) {
|
for (int point = last - 1; point >= 0 && feeder.style()[point] != ReachStyle.POND_OUTLET; point--) {
|
||||||
arc += Math.hypot(feeder.xs()[point + 1] - feeder.xs()[point], feeder.zs()[point + 1] - feeder.zs()[point]);
|
arc += Math.hypot(feeder.xs()[point + 1] - feeder.xs()[point], feeder.zs()[point + 1] - feeder.zs()[point]);
|
||||||
float reach = feeder.halfWidth()[point] + ConfluenceGrader.POOL_MARGIN;
|
float reach = feeder.halfWidth()[point] + ConfluenceGrader.POOL_MARGIN;
|
||||||
if (arc > ConfluenceGrader.POOL_CAP || edgeDistance(outlet, 0, feeder.xs()[point], feeder.zs()[point]) > reach) {
|
if (arc > ConfluenceGrader.POOL_CAP || edgeDistance(outlet, 0, feeder.xs()[point], feeder.zs()[point]) > reach
|
||||||
|
|| point == 0 && fed.contains(feeder.id())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assertEquals(feeder + " point " + point + " in the pool of led-in outlet " + outlet, outlet.grade()[0], feeder.grade()[point]);
|
assertEquals(feeder + " point " + point + " in the pool of led-in outlet " + outlet, outlet.grade()[0], feeder.grade()[point]);
|
||||||
@@ -115,6 +121,27 @@ public class PlannedSceneTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tributaryFallingFarIntoTheJunctionAtTheBankIsNoTongue() {
|
||||||
|
HydrologySettings settings = PlannedScene.packSettings(SEED);
|
||||||
|
for (int beside : new int[]{70, 74}) {
|
||||||
|
Reach tributary = tributary(settings, new int[]{144, 56}, new int[]{144, 136}, 2f, (x, z) -> z >= 128 ? 66 : beside);
|
||||||
|
boolean falls = beside - 66 > ConfluenceGrader.MARGIN_LOWERING;
|
||||||
|
assertEquals("tributary " + (beside - 66) + " blocks above the junction beside the receiving bank", falls ? List.of() : List.of(tributary.id()),
|
||||||
|
tongues(settings, tributary, 66, true, List.of()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startHeldForItsOwnFeederIsNoTongue() {
|
||||||
|
HydrologySettings settings = PlannedScene.packSettings(SEED);
|
||||||
|
Reach stub = tributary(settings, new int[]{144, 124}, new int[]{144, 136}, 2f, (x, z) -> z <= 124 ? 70 : 66);
|
||||||
|
Reach upstream = straight(304L, settings.tiers().get(0), stub.id(), 1f, new int[]{144, 56}, new int[]{144, 124}, (x, z) -> 70);
|
||||||
|
assertEquals("a stub perched at its start", List.of(stub.id()), tongues(settings, stub, 66, true, List.of()));
|
||||||
|
assertEquals("a stub holding its start for the reach that feeds it", List.of(),
|
||||||
|
WaterInvariants.confluenceTongues(scene(settings, List.of(stub, upstream), 66, true, List.of())));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tonguesCountTheSiblingChannelAsReceivingWater() {
|
public void tonguesCountTheSiblingChannelAsReceivingWater() {
|
||||||
HydrologySettings settings = PlannedScene.packSettings(SEED);
|
HydrologySettings settings = PlannedScene.packSettings(SEED);
|
||||||
@@ -132,11 +159,14 @@ public class PlannedSceneTest {
|
|||||||
assertEquals("outlet held on its pond's lip 4 blocks above the junction, cascading into it", List.of(),
|
assertEquals("outlet held on its pond's lip 4 blocks above the junction, cascading into it", List.of(),
|
||||||
tongues(settings, falling, 66, true, List.of(source(70, falling))));
|
tongues(settings, falling, 66, true, List.of(source(70, falling))));
|
||||||
Reach stepping = outlet(tributary(settings, lip, junction, 2f, (x, z) -> z >= 130 ? 67 : 68));
|
Reach stepping = outlet(tributary(settings, lip, junction, 2f, (x, z) -> z >= 130 ? 67 : 68));
|
||||||
|
PlannedScene riffling = scene(settings, List.of(stepping), 67, true, List.of(source(68, stepping)));
|
||||||
assertEquals("held outlet whose 1-block riffle into the junction shows as a 2-block step", List.of(stepping.id()),
|
assertEquals("held outlet whose 1-block riffle into the junction shows as a 2-block step", List.of(stepping.id()),
|
||||||
tongues(settings, stepping, 67, true, List.of(source(68, stepping))));
|
WaterInvariants.confluenceTongues(riffling));
|
||||||
|
assertEquals("and that tongue is a held lip riffling into the junction", List.of(stepping.id()), WaterInvariants.heldLipRiffles(riffling));
|
||||||
Reach above = outlet(tributary(settings, lip, junction, 2f, (x, z) -> 70));
|
Reach above = outlet(tributary(settings, lip, junction, 2f, (x, z) -> 70));
|
||||||
assertEquals("held outlet whose own end stays above the junction", List.of(above.id()),
|
PlannedScene perched = scene(settings, List.of(above), 66, true, List.of(source(70, above)));
|
||||||
tongues(settings, above, 66, true, List.of(source(70, above))));
|
assertEquals("held outlet whose own end stays above the junction", List.of(above.id()), WaterInvariants.confluenceTongues(perched));
|
||||||
|
assertEquals("a held outlet ending above the junction is no lip riffle", List.of(), WaterInvariants.heldLipRiffles(perched));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,8 +174,10 @@ public class PlannedSceneTest {
|
|||||||
HydrologySettings settings = PlannedScene.packSettings(SEED);
|
HydrologySettings settings = PlannedScene.packSettings(SEED);
|
||||||
Reach outlet = outlet(tributary(settings, new int[]{144, 56}, new int[]{144, 136}, 2f, (x, z) -> z >= 136 ? 66 : 70));
|
Reach outlet = outlet(tributary(settings, new int[]{144, 56}, new int[]{144, 136}, 2f, (x, z) -> z >= 136 ? 66 : 70));
|
||||||
Pond pond = pond(21L, 70, disk(144, 46, 10), outlet.id());
|
Pond pond = pond(21L, 70, disk(144, 46, 10), outlet.id());
|
||||||
|
PlannedScene scene = scene(settings, List.of(outlet), 66, true, List.of(pond));
|
||||||
assertEquals("outlet held only near its pond, cascading into the junction from a perched tail", List.of(outlet.id()),
|
assertEquals("outlet held only near its pond, cascading into the junction from a perched tail", List.of(outlet.id()),
|
||||||
tongues(settings, outlet, 66, true, List.of(pond)));
|
WaterInvariants.confluenceTongues(scene));
|
||||||
|
assertEquals("a perched unheld tail is no lip riffle", List.of(), WaterInvariants.heldLipRiffles(scene));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -206,15 +238,21 @@ public class PlannedSceneTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<Long> tongues(HydrologySettings settings, Reach tributary, int receivingLevel, boolean sibling, List<Pond> ponds) {
|
private static List<Long> tongues(HydrologySettings settings, Reach tributary, int receivingLevel, boolean sibling, List<Pond> ponds) {
|
||||||
|
return WaterInvariants.confluenceTongues(scene(settings, List.of(tributary), receivingLevel, sibling, ponds));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlannedScene scene(HydrologySettings settings, List<Reach> upstream, int receivingLevel, boolean sibling, List<Pond> ponds) {
|
||||||
HydrologyTier river = settings.tiers().get(1);
|
HydrologyTier river = settings.tiers().get(1);
|
||||||
|
Reach tributary = upstream.get(0);
|
||||||
int last = tributary.xs().length - 1;
|
int last = tributary.xs().length - 1;
|
||||||
int[] junction = {Math.round(tributary.xs()[last]), Math.round(tributary.zs()[last])};
|
int[] junction = {Math.round(tributary.xs()[last]), Math.round(tributary.zs()[last])};
|
||||||
Reach below = straight(302L, river, 0L, 8f, junction, new int[]{junction[0] + 104, junction[1]}, (x, z) -> receivingLevel);
|
Reach below = straight(302L, river, 0L, 8f, junction, new int[]{junction[0] + 104, junction[1]}, (x, z) -> receivingLevel);
|
||||||
List<Reach> reaches = sibling
|
List<Reach> reaches = new ArrayList<>(upstream);
|
||||||
? List.of(straight(301L, river, below.id(), 8f, new int[]{junction[0] - 112, junction[1]}, junction, (x, z) -> receivingLevel),
|
reaches.add(below);
|
||||||
tributary, below)
|
if (sibling) {
|
||||||
: List.of(tributary, below);
|
reaches.add(straight(301L, river, below.id(), 8f, new int[]{junction[0] - 112, junction[1]}, junction, (x, z) -> receivingLevel));
|
||||||
return WaterInvariants.confluenceTongues(PlannedScene.of(SyntheticTerrain.flat(75D), settings, reaches, ponds));
|
}
|
||||||
|
return PlannedScene.of(SyntheticTerrain.flat(75D), settings, reaches, ponds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Reach outlet(Reach reach) {
|
private static Reach outlet(Reach reach) {
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
|||||||
static final int SEA_LEVEL = 40;
|
static final int SEA_LEVEL = 40;
|
||||||
static final int MIN_Y = -64;
|
static final int MIN_Y = -64;
|
||||||
static final int MAX_Y = 320;
|
static final int MAX_Y = 320;
|
||||||
|
static final double VALLEY_AXIS = 512D;
|
||||||
private static final double OCEAN_FLOOR = SEA_LEVEL - 30D;
|
private static final double OCEAN_FLOOR = SEA_LEVEL - 30D;
|
||||||
|
private static final double WALL_MIN_X = 256D;
|
||||||
|
private static final double WALL_MAX_X = 768D;
|
||||||
private static final double BASE_OFFSET = 3D;
|
private static final double BASE_OFFSET = 3D;
|
||||||
private static final double BASE_WAVELENGTH = 1000D;
|
private static final double BASE_WAVELENGTH = 1000D;
|
||||||
private static final long SALT_BASE = 0x42415345L;
|
private static final long SALT_BASE = 0x42415345L;
|
||||||
@@ -288,8 +291,20 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
|||||||
return new SyntheticTerrain(SyntheticTerrain::valleySlope);
|
return new SyntheticTerrain(SyntheticTerrain::valleySlope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SyntheticTerrain valleyBelowAWall(double foot, double run, double height) {
|
||||||
|
return new SyntheticTerrain((x, z) -> {
|
||||||
|
double valley = valleySlope(x, z);
|
||||||
|
double beyond = VALLEY_AXIS - foot - z;
|
||||||
|
if (x < WALL_MIN_X || x > WALL_MAX_X || beyond <= 0D) {
|
||||||
|
return valley;
|
||||||
|
}
|
||||||
|
double ramp = Math.min(1D, beyond / run);
|
||||||
|
return valley + height * ramp + 0.1D * Math.abs(x - VALLEY_AXIS) * ramp;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static double valleySlope(double x, double z) {
|
private static double valleySlope(double x, double z) {
|
||||||
return 100D - 0.03D * x + 0.05D * Math.abs(z - 512D);
|
return 100D - 0.03D * x + 0.05D * Math.abs(z - VALLEY_AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SyntheticTerrain openFractal(long seed) {
|
static SyntheticTerrain openFractal(long seed) {
|
||||||
|
|||||||
@@ -56,13 +56,24 @@ final class WaterInvariants {
|
|||||||
int seaLevel = scene.settings().seaLevel();
|
int seaLevel = scene.settings().seaLevel();
|
||||||
List<Long> tongues = new ArrayList<>();
|
List<Long> tongues = new ArrayList<>();
|
||||||
for (Junction junction : junctions(scene)) {
|
for (Junction junction : junctions(scene)) {
|
||||||
if (perched(scene, junction, seaLevel)) {
|
if (perched(scene, junction, seaLevel, false)) {
|
||||||
tongues.add(junction.feeder().id());
|
tongues.add(junction.feeder().id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tongues;
|
return tongues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<Long> heldLipRiffles(PlannedScene scene) {
|
||||||
|
int seaLevel = scene.settings().seaLevel();
|
||||||
|
List<Long> riffles = new ArrayList<>();
|
||||||
|
for (Junction junction : junctions(scene)) {
|
||||||
|
if (perched(scene, junction, seaLevel, false) && !perched(scene, junction, seaLevel, true)) {
|
||||||
|
riffles.add(junction.feeder().id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return riffles;
|
||||||
|
}
|
||||||
|
|
||||||
static List<Reach> checkedFeeders(PlannedScene scene) {
|
static List<Reach> checkedFeeders(PlannedScene scene) {
|
||||||
List<Reach> checked = new ArrayList<>();
|
List<Reach> checked = new ArrayList<>();
|
||||||
for (Junction junction : junctions(scene)) {
|
for (Junction junction : junctions(scene)) {
|
||||||
@@ -145,10 +156,10 @@ final class WaterInvariants {
|
|||||||
if (downstream == null) {
|
if (downstream == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean[] pool = pool(feeder, receiving(feeder, downstream, feeders.get(downstream.id())));
|
int level = Math.min(feeder.grade()[feeder.grade().length - 1], downstream.grade()[0]);
|
||||||
|
boolean[] pool = pool(feeder, receiving(feeder, downstream, feeders.get(downstream.id())), level, feeders.containsKey(feeder.id()));
|
||||||
int[] box = interior(scene, poolBox(feeder, pool));
|
int[] box = interior(scene, poolBox(feeder, pool));
|
||||||
if (box != null) {
|
if (box != null) {
|
||||||
int level = Math.min(feeder.grade()[feeder.grade().length - 1], downstream.grade()[0]);
|
|
||||||
boolean[] held = held(feeder, lips.getOrDefault(feeder.id(), List.of()));
|
boolean[] held = held(feeder, lips.getOrDefault(feeder.id(), List.of()));
|
||||||
junctions.add(new Junction(feeder, WaterHeads.snap(level, seaLevel), pool, held, box));
|
junctions.add(new Junction(feeder, WaterHeads.snap(level, seaLevel), pool, held, box));
|
||||||
}
|
}
|
||||||
@@ -156,7 +167,7 @@ final class WaterInvariants {
|
|||||||
return junctions;
|
return junctions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean perched(PlannedScene scene, Junction junction, int seaLevel) {
|
private static boolean perched(PlannedScene scene, Junction junction, int seaLevel, boolean riffles) {
|
||||||
Reach feeder = junction.feeder();
|
Reach feeder = junction.feeder();
|
||||||
boolean endsAtTheJunction = WaterHeads.snap(feeder.grade()[feeder.grade().length - 1], seaLevel) <= junction.head();
|
boolean endsAtTheJunction = WaterHeads.snap(feeder.grade()[feeder.grade().length - 1], seaLevel) <= junction.head();
|
||||||
int[] box = junction.box();
|
int[] box = junction.box();
|
||||||
@@ -169,7 +180,7 @@ final class WaterInvariants {
|
|||||||
if (point < 0 || !junction.pool()[point]) {
|
if (point < 0 || !junction.pool()[point]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!endsAtTheJunction || !junction.held()[point] || !fallsToTheJunction(feeder, point, seaLevel)) {
|
if (!endsAtTheJunction || !junction.held()[point] || !fallsToTheJunction(feeder, point, seaLevel, riffles)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,15 +188,16 @@ final class WaterInvariants {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean[] pool(Reach feeder, List<Reach> receiving) {
|
private static boolean[] pool(Reach feeder, List<Reach> receiving, int level, boolean fedStart) {
|
||||||
int last = feeder.xs().length - 1;
|
int last = feeder.xs().length - 1;
|
||||||
boolean[] pool = new boolean[last + 1];
|
boolean[] pool = new boolean[last + 1];
|
||||||
pool[last] = true;
|
pool[last] = true;
|
||||||
double arc = 0D;
|
double arc = 0D;
|
||||||
for (int point = last - 1; point >= 0; point--) {
|
for (int point = last - 1; point >= (fedStart ? 1 : 0); point--) {
|
||||||
arc += Math.hypot(feeder.xs()[point + 1] - feeder.xs()[point], feeder.zs()[point + 1] - feeder.zs()[point]);
|
arc += Math.hypot(feeder.xs()[point + 1] - feeder.xs()[point], feeder.zs()[point + 1] - feeder.zs()[point]);
|
||||||
if (arc > ConfluenceGrader.POOL_CAP
|
double edge = edgeDistance(receiving, feeder.xs()[point], feeder.zs()[point]);
|
||||||
|| edgeDistance(receiving, feeder.xs()[point], feeder.zs()[point]) > feeder.halfWidth()[point] + ConfluenceGrader.POOL_MARGIN) {
|
if (arc > ConfluenceGrader.POOL_CAP || edge > feeder.halfWidth()[point] + ConfluenceGrader.POOL_MARGIN
|
||||||
|
|| edge > 0D && feeder.grade()[point] - level > ConfluenceGrader.MARGIN_LOWERING) {
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
pool[point] = true;
|
pool[point] = true;
|
||||||
@@ -222,11 +234,12 @@ final class WaterInvariants {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean fallsToTheJunction(Reach feeder, int point, int seaLevel) {
|
private static boolean fallsToTheJunction(Reach feeder, int point, int seaLevel, boolean riffles) {
|
||||||
for (int next = point + 1; next < feeder.grade().length; next++) {
|
for (int next = point + 1; next < feeder.grade().length; next++) {
|
||||||
boolean step = WaterHeads.snap(feeder.grade()[next], seaLevel) < WaterHeads.snap(feeder.grade()[next - 1], seaLevel);
|
boolean step = WaterHeads.snap(feeder.grade()[next], seaLevel) < WaterHeads.snap(feeder.grade()[next - 1], seaLevel);
|
||||||
ReachStyle style = feeder.style()[next];
|
ReachStyle style = feeder.style()[next];
|
||||||
if (step && style != ReachStyle.CASCADE && style != ReachStyle.WATERFALL) {
|
boolean riffle = riffles && feeder.grade()[next - 1] - feeder.grade()[next] == 1;
|
||||||
|
if (step && style != ReachStyle.CASCADE && style != ReachStyle.WATERFALL && !riffle) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class WindowPlannerTest {
|
|||||||
private static final double PIT_RADIUS = 50D;
|
private static final double PIT_RADIUS = 50D;
|
||||||
private static final double PIT_DEPTH = 30D;
|
private static final double PIT_DEPTH = 30D;
|
||||||
private static final int DEEP_CUT = 12;
|
private static final int DEEP_CUT = 12;
|
||||||
|
private static final int MAX_LIP_RIFFLES = 3;
|
||||||
private static final int SLIVER_REACH = 32;
|
private static final int SLIVER_REACH = 32;
|
||||||
private static final int RIM_CUT = 24;
|
private static final int RIM_CUT = 24;
|
||||||
private static final double VALLEY_HALF_WIDTH = 200D;
|
private static final double VALLEY_HALF_WIDTH = 200D;
|
||||||
@@ -653,15 +654,21 @@ public class WindowPlannerTest {
|
|||||||
public void pondOutletsAndConfluencesMeetConnectedWater() {
|
public void pondOutletsAndConfluencesMeetConnectedWater() {
|
||||||
int outlets = 0;
|
int outlets = 0;
|
||||||
int feeders = 0;
|
int feeders = 0;
|
||||||
|
int lipRiffles = 0;
|
||||||
for (long seed = 1L; seed <= 7L; seed++) {
|
for (long seed = 1L; seed <= 7L; seed++) {
|
||||||
PlannedScene scene = PlannedScene.plan(SyntheticTerrain.openFractal(seed), PlannedScene.packSettings(SEED), 1, 1);
|
PlannedScene scene = PlannedScene.plan(SyntheticTerrain.openFractal(seed), PlannedScene.packSettings(SEED), 1, 1);
|
||||||
assertEquals("detached outlets on openFractal(" + seed + ")", List.of(), WaterInvariants.detachedOutlets(scene));
|
assertEquals("detached outlets on openFractal(" + seed + ")", List.of(), WaterInvariants.detachedOutlets(scene));
|
||||||
assertEquals("confluence tongues on openFractal(" + seed + ")", List.of(), WaterInvariants.confluenceTongues(scene));
|
List<Long> riffles = WaterInvariants.heldLipRiffles(scene);
|
||||||
|
List<Long> tongues = new ArrayList<>(WaterInvariants.confluenceTongues(scene));
|
||||||
|
tongues.removeAll(riffles);
|
||||||
|
assertEquals("confluence tongues on openFractal(" + seed + ")", List.of(), tongues);
|
||||||
|
lipRiffles += riffles.size();
|
||||||
outlets += WaterInvariants.checkedPonds(scene).size();
|
outlets += WaterInvariants.checkedPonds(scene).size();
|
||||||
feeders += WaterInvariants.checkedFeeders(scene).size();
|
feeders += WaterInvariants.checkedFeeders(scene).size();
|
||||||
}
|
}
|
||||||
assertTrue("pond outlets checked " + outlets, outlets >= 50);
|
assertTrue("pond outlets checked " + outlets, outlets >= 50);
|
||||||
assertTrue("confluence feeders checked " + feeders, feeders >= 300);
|
assertTrue("confluence feeders checked " + feeders, feeders >= 300);
|
||||||
|
assertTrue("held outlet lips riffling into their junction " + lipRiffles, lipRiffles <= MAX_LIP_RIFFLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertOutletLeavesAtThePondHead(Pond pond, Reach outlet) {
|
private static void assertOutletLeavesAtThePondHead(Pond pond, Reach outlet) {
|
||||||
|
|||||||
+6
-3
@@ -778,9 +778,12 @@ public class ChunkWaterRasterTest {
|
|||||||
Reach low = line(232L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 62);
|
Reach low = line(232L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 62);
|
||||||
Reach hanging = line(231L, narrow, low.id(), 440f, 200f, 504f, 200f, (x, z) -> 70);
|
Reach hanging = line(231L, narrow, low.id(), 440f, 200f, 504f, 200f, (x, z) -> 70);
|
||||||
Scene falls = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(hanging).reach(low);
|
Scene falls = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(hanging).reach(low);
|
||||||
assertEquals(70, falls.head(496, 200));
|
int bank = (int) Math.ceil(low.xs()[0] - low.halfWidth()[0]);
|
||||||
assertEquals(62, falls.head(497, 200));
|
assertTrue("the feeder stands more than the margin lowering above the downstream start",
|
||||||
assertEquals("an 8-block settled drop is a waterfall", WaterRole.WATERFALL, falls.role(497, 200));
|
70 - 62 > ConfluenceGrader.MARGIN_LOWERING);
|
||||||
|
assertEquals("the feeder keeps its level beside the receiving bank", 70, falls.head(bank - 1, 200));
|
||||||
|
assertEquals(62, falls.head(bank, 200));
|
||||||
|
assertEquals("an 8-block drop is a waterfall at the receiving bank", WaterRole.WATERFALL, falls.role(bank, 200));
|
||||||
Reach steep = line(233L, narrow, low.id(), 440f, 200f, 504f, 200f, (x, z) -> x >= 496f ? 66 : Math.min(80, 66 + (int) ((496f - x) / 2f)));
|
Reach steep = line(233L, narrow, low.id(), 440f, 200f, 504f, 200f, (x, z) -> x >= 496f ? 66 : Math.min(80, 66 + (int) ((496f - x) / 2f)));
|
||||||
Scene cascade = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(steep).reach(low);
|
Scene cascade = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(steep).reach(low);
|
||||||
assertEquals(66, cascade.head(496, 200));
|
assertEquals(66, cascade.head(496, 200));
|
||||||
|
|||||||
+62
@@ -21,6 +21,9 @@ public class ConfluenceGraderTest {
|
|||||||
private static final int JUNCTION = 100;
|
private static final int JUNCTION = 100;
|
||||||
private static final int POOL_EDGE_Z = -12;
|
private static final int POOL_EDGE_Z = -12;
|
||||||
private static final int FEEDER_Z = -48;
|
private static final int FEEDER_Z = -48;
|
||||||
|
private static final int STUB_Z = -8;
|
||||||
|
private static final int BANK_Z = -8;
|
||||||
|
private static final int MARGIN_Z = -12;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void spreadFeederMeetsALowerRiverWithoutAStepAtThePoolEdge() {
|
public void spreadFeederMeetsALowerRiverWithoutAStepAtThePoolEdge() {
|
||||||
@@ -55,6 +58,65 @@ public class ConfluenceGraderTest {
|
|||||||
&& failure.getMessage().contains(WINDOW.toString()));
|
&& failure.getMessage().contains(WINDOW.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aFeederWithItsOwnFeedersKeepsItsStartAtTheirJunction() {
|
||||||
|
HydrologyTier tier = tier(true);
|
||||||
|
ReachDraft upstream = line(tier, 31L, 0f, FEEDER_Z, 0f, STUB_Z, 2f, z -> JUNCTION + 3);
|
||||||
|
ReachDraft stub = line(tier, 32L, 0f, STUB_Z, 0f, 0f, 2f, z -> z == STUB_Z ? JUNCTION + 3 : z == 0 ? JUNCTION : JUNCTION + 2);
|
||||||
|
ReachDraft river = line(tier, 33L, 0f, 0f, 64f, 0f, 8f, z -> JUNCTION);
|
||||||
|
upstream.downstream = 1;
|
||||||
|
stub.incoming = new int[]{0};
|
||||||
|
stub.downstream = 2;
|
||||||
|
river.incoming = new int[]{1};
|
||||||
|
ConfluenceGrader.level(WINDOW, List.of(upstream, stub, river), new int[]{0, 1, 2});
|
||||||
|
assertEquals("the stub keeps its start for the reach that feeds it " + Arrays.toString(stub.grade), JUNCTION + 3, stub.grade[0]);
|
||||||
|
for (int point = 1; point < stub.grade.length; point++) {
|
||||||
|
assertEquals("stub point " + point + " pooled " + Arrays.toString(stub.grade), JUNCTION, stub.grade[point]);
|
||||||
|
}
|
||||||
|
for (int point = 0; point < upstream.grade.length; point++) {
|
||||||
|
assertEquals("upstream point " + point + " " + Arrays.toString(upstream.grade), JUNCTION + 3, upstream.grade[point]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void feederBesideTheReceivingBankPoolsOnlyWhenItIsNearTheJunctionLevel() {
|
||||||
|
int[] near = besideTheBank(ConfluenceGrader.MARGIN_LOWERING);
|
||||||
|
for (int point = 0; point < near.length; point++) {
|
||||||
|
int z = FEEDER_Z + point;
|
||||||
|
if (z >= MARGIN_Z) {
|
||||||
|
assertEquals("point " + point + " at z " + z + " " + Arrays.toString(near), JUNCTION, near[point]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int[] high = besideTheBank(ConfluenceGrader.MARGIN_LOWERING + 1);
|
||||||
|
for (int point = 0; point < high.length; point++) {
|
||||||
|
int z = FEEDER_Z + point;
|
||||||
|
if (z >= BANK_Z) {
|
||||||
|
assertEquals("point " + point + " inside the receiving channel at z " + z + " " + Arrays.toString(high), JUNCTION, high[point]);
|
||||||
|
} else if (z >= MARGIN_Z) {
|
||||||
|
assertEquals("point " + point + " beside the bank at z " + z + " " + Arrays.toString(high), JUNCTION + ConfluenceGrader.MARGIN_LOWERING + 1,
|
||||||
|
high[point]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] besideTheBank(int marginHeight) {
|
||||||
|
HydrologyTier tier = tier(true);
|
||||||
|
ReachDraft feeder = line(tier, 41L, 0f, FEEDER_Z, 0f, 0f, 2f, z -> {
|
||||||
|
if (z == 0) {
|
||||||
|
return JUNCTION;
|
||||||
|
}
|
||||||
|
if (z >= BANK_Z) {
|
||||||
|
return JUNCTION + 1;
|
||||||
|
}
|
||||||
|
return JUNCTION + marginHeight + Math.max(0, Math.floorDiv(MARGIN_Z - z, 2));
|
||||||
|
});
|
||||||
|
ReachDraft river = line(tier, 42L, 0f, 0f, 64f, 0f, 8f, z -> JUNCTION);
|
||||||
|
feeder.downstream = 1;
|
||||||
|
river.incoming = new int[]{0};
|
||||||
|
ConfluenceGrader.level(WINDOW, List.of(feeder, river), new int[]{0, 1});
|
||||||
|
return feeder.grade;
|
||||||
|
}
|
||||||
|
|
||||||
private static int[] graded(HydrologyTier tier, boolean fixedApproach) {
|
private static int[] graded(HydrologyTier tier, boolean fixedApproach) {
|
||||||
ReachDraft feeder = line(tier, 21L, 0f, FEEDER_Z, 0f, 0f, 2f, ConfluenceGraderTest::feederGrade);
|
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);
|
ReachDraft river = line(tier, 22L, 0f, 0f, 64f, 0f, 8f, z -> JUNCTION);
|
||||||
|
|||||||
@@ -127,24 +127,38 @@ public class ReachShaperTest {
|
|||||||
});
|
});
|
||||||
int confluences = 0;
|
int confluences = 0;
|
||||||
int pooled = 0;
|
int pooled = 0;
|
||||||
|
int inside = 0;
|
||||||
|
int falls = 0;
|
||||||
for (long seed : new long[]{SEED, SEED + 5L, SEED + 9L}) {
|
for (long seed : new long[]{SEED, SEED + 5L, SEED + 9L}) {
|
||||||
ShapedNetwork shaped = shape(settings, network(settings, fractal(seed), 64, 64, 2000f, false));
|
ShapedNetwork shaped = shape(settings, network(settings, fractal(seed), 64, 64, 2000f, false));
|
||||||
Map<Long, Reach> byId = byId(shaped.reaches());
|
Map<Long, Reach> byId = byId(shaped.reaches());
|
||||||
|
Map<Long, List<Reach>> feeders = feeders(shaped.reaches());
|
||||||
int joins = 0;
|
int joins = 0;
|
||||||
for (Map.Entry<Long, List<Reach>> entry : feeders(shaped.reaches()).entrySet()) {
|
for (Map.Entry<Long, List<Reach>> entry : feeders.entrySet()) {
|
||||||
Reach downstream = byId.get(entry.getKey());
|
Reach downstream = byId.get(entry.getKey());
|
||||||
List<Reach> siblings = entry.getValue();
|
List<Reach> siblings = entry.getValue();
|
||||||
joins += siblings.size() >= 2 ? 1 : 0;
|
joins += siblings.size() >= 2 ? 1 : 0;
|
||||||
for (Reach feeder : siblings) {
|
for (Reach feeder : siblings) {
|
||||||
List<ConfluenceGrader.Footprint> receiving = receiving(downstream, siblings, feeder);
|
List<ConfluenceGrader.Footprint> receiving = receiving(downstream, siblings, feeder);
|
||||||
|
int level = downstream.grade()[0];
|
||||||
for (int point = feeder.xs().length - 1; point >= 0; point--) {
|
for (int point = feeder.xs().length - 1; point >= 0; point--) {
|
||||||
double clearance = clearance(receiving, feeder.xs()[point], feeder.zs()[point]);
|
double clearance = clearance(receiving, feeder.xs()[point], feeder.zs()[point]);
|
||||||
if (clearance > feeder.halfWidth()[point] + 1f) {
|
if (clearance > feeder.halfWidth()[point] + 1f || point == 0 && feeders.containsKey(feeder.id())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assertEquals("seed " + seed + " " + feeder + " into " + downstream + " at point " + point + " with clearance " + clearance,
|
String at = "seed " + seed + " " + feeder + " into " + downstream + " at point " + point + " with clearance " + clearance;
|
||||||
downstream.grade()[0], feeder.grade()[point]);
|
int grade = feeder.grade()[point];
|
||||||
pooled++;
|
if (clearance <= 0D || grade == level) {
|
||||||
|
assertEquals(at, level, grade);
|
||||||
|
pooled++;
|
||||||
|
inside += clearance <= 0D ? 1 : 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assertTrue(at + " stands " + (grade - level) + " above the junction beside the bank", grade - level > ConfluenceGrader.MARGIN_LOWERING);
|
||||||
|
ReachStyle style = feeder.style()[point + 1];
|
||||||
|
assertTrue(at + " drops into the junction as " + style, style == ReachStyle.CASCADE || style == ReachStyle.WATERFALL);
|
||||||
|
falls++;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,6 +166,8 @@ public class ReachShaperTest {
|
|||||||
confluences += joins;
|
confluences += joins;
|
||||||
}
|
}
|
||||||
assertTrue("pooled points " + pooled + " at " + confluences + " confluences", pooled > 3 * confluences);
|
assertTrue("pooled points " + pooled + " at " + confluences + " confluences", pooled > 3 * confluences);
|
||||||
|
assertTrue("pooled points inside the receiving channel " + inside + " at " + confluences + " confluences", inside > 3 * confluences);
|
||||||
|
assertTrue("falls at the receiving bank " + falls, falls > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in new issue
Block a user