mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Cross-window confluence settling
- Track every reach owned by the nine loaded windows in ChunkFeatures.Links.owned - Settle a feeder whose downstream reach has another owner window into L = min(raw downstream start, raw feeder ends, downstream outlet pond level) through LinkBlend.settleInto - Delegate LinkBlend.settleInto to ConfluenceGrader.settle with vertex 0 and outlet-zone vertices fixed, spreading the junction on tiers without cascades - Restyle every grade change made by link clamping or settling with ReachShaper.styles, so seam drops become cascades and waterfalls - Rebase the cross-window width and depth blend on the junction width so an already flared downstream reach is unchanged - Clamp a led-in pond outlet to the pond it leads out of instead of the lowest pond sharing it - Make ConfluenceGrader.spreadJunction and ReachShaper.styles public - Add ChunkWaterRasterTest cases for cross-window settling in both window orders, styled seam drops, spread junctions, flare rebasing and shared outlets
This commit is contained in:
1 parent
b6166bc6fa
commit
e62585b450
5 files changed
+271
-44
No files matched your search
@@ -7,6 +7,7 @@ import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.ConfluenceGrader;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -294,18 +295,24 @@ 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> owned = new HashMap<>();
|
||||
private final Map<Long, List<Pond>> outletPonds = new HashMap<>();
|
||||
private final Map<Long, Reach> resolved = new HashMap<>();
|
||||
private final Set<Long> resolving = new HashSet<>();
|
||||
|
||||
private Links(Map<WindowKey, IndexedWindow> windows) {
|
||||
this.windows = windows;
|
||||
for (IndexedWindow window : windows.values()) {
|
||||
for (Reach reach : window.plan().reaches()) {
|
||||
Reach other = owned.putIfAbsent(reach.id(), reach);
|
||||
if (other != null) {
|
||||
throw new IllegalStateException("Reach " + reach.id() + " is owned by window " + window.plan().key()
|
||||
+ " and by window " + windowAt(other, other.xs().length - 1));
|
||||
}
|
||||
}
|
||||
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());
|
||||
outletPonds.computeIfAbsent(pond.outletReachId(), ignored -> new ArrayList<>()).add(pond);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,10 +332,31 @@ final class ChunkFeatures {
|
||||
return linked;
|
||||
}
|
||||
|
||||
private Reach link(Reach downstream, WindowKey owner) {
|
||||
Reach linked = feederLink(downstream, owner);
|
||||
Integer pondLevel = outletLevels.get(linked.id());
|
||||
return pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel);
|
||||
private Reach link(Reach reach, WindowKey owner) {
|
||||
Reach linked = feederLink(reach, owner);
|
||||
Integer pondLevel = outletLevel(reach);
|
||||
return settle(reach, pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel), owner);
|
||||
}
|
||||
|
||||
private Reach settle(Reach feeder, Reach linked, WindowKey owner) {
|
||||
Reach downstream = owned.get(feeder.downstreamId());
|
||||
if (downstream == null || owner.equals(windowAt(downstream, downstream.xs().length - 1))) {
|
||||
return linked;
|
||||
}
|
||||
int level = downstream.grade()[0];
|
||||
Integer pondLevel = outletLevel(downstream);
|
||||
if (pondLevel != null) {
|
||||
level = Math.min(level, pondLevel);
|
||||
}
|
||||
List<ConfluenceGrader.Footprint> receiving = new ArrayList<>();
|
||||
receiving.add(LinkBlend.footprint(downstream));
|
||||
for (Reach sibling : feeders(owner, downstream.id())) {
|
||||
level = Math.min(level, sibling.grade()[sibling.grade().length - 1]);
|
||||
if (sibling.id() != feeder.id()) {
|
||||
receiving.add(LinkBlend.footprint(sibling));
|
||||
}
|
||||
}
|
||||
return LinkBlend.settleInto(linked, level, receiving);
|
||||
}
|
||||
|
||||
private Reach feederLink(Reach downstream, WindowKey owner) {
|
||||
@@ -356,18 +384,39 @@ final class ChunkFeatures {
|
||||
}
|
||||
|
||||
private int junction(Reach reach) {
|
||||
List<PondMask> masks = outletMasks.get(reach.id());
|
||||
if (masks == null || reach.xs().length < 2) {
|
||||
return 0;
|
||||
return source(reach) == null ? 0 : 1;
|
||||
}
|
||||
|
||||
private Integer outletLevel(Reach reach) {
|
||||
List<Pond> ponds = outletPonds.get(reach.id());
|
||||
if (ponds == null) {
|
||||
return null;
|
||||
}
|
||||
Pond source = source(reach);
|
||||
if (source != null) {
|
||||
return source.level();
|
||||
}
|
||||
int level = Integer.MAX_VALUE;
|
||||
for (Pond pond : ponds) {
|
||||
level = Math.min(level, pond.level());
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
private Pond source(Reach reach) {
|
||||
List<Pond> ponds = outletPonds.get(reach.id());
|
||||
if (ponds == null) {
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
Pond source = null;
|
||||
for (Pond pond : ponds) {
|
||||
if (pond.mask().contains(x, z) && (source == null || lower(pond, source))) {
|
||||
source = pond;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return source;
|
||||
}
|
||||
|
||||
private long cornerBlock(Reach reach) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.water.ConfluenceGrader;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachShaper;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,7 +22,6 @@ public final class LinkBlend {
|
||||
}
|
||||
|
||||
static Reach blend(Reach downstream, List<Reach> feeders, int junction) {
|
||||
int end = lowestEnd(feeders);
|
||||
float width = 0f;
|
||||
float depth = 0f;
|
||||
for (Reach feeder : feeders) {
|
||||
@@ -29,20 +31,20 @@ public final class LinkBlend {
|
||||
}
|
||||
float[] xs = downstream.xs();
|
||||
float[] zs = downstream.zs();
|
||||
int[] grade = clamped(downstream.grade(), end);
|
||||
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]);
|
||||
}
|
||||
for (int point = 0; point < xs.length; point++) {
|
||||
float fromJunction = along[point] - along[junction];
|
||||
halfWidth[point] = blend(width, halfWidth[point], fromJunction);
|
||||
depths[point] = blend(depth, depths[point], fromJunction);
|
||||
halfWidth[point] += blend(widthShift, 0f, fromJunction);
|
||||
depths[point] += blend(depthShift, 0f, fromJunction);
|
||||
}
|
||||
return new Reach(downstream.id(), downstream.tier(), downstream.downstreamId(), xs, zs, grade, halfWidth, depths,
|
||||
downstream.style(), downstream.catchment());
|
||||
return regraded(downstream, clamped(downstream.grade(), lowestEnd(feeders)), halfWidth, depths);
|
||||
}
|
||||
|
||||
static Reach clamp(Reach downstream, List<Reach> feeders) {
|
||||
@@ -50,15 +52,52 @@ public final class LinkBlend {
|
||||
}
|
||||
|
||||
static Reach clamp(Reach downstream, int end) {
|
||||
boolean above = false;
|
||||
for (int grade : downstream.grade()) {
|
||||
above |= grade > end;
|
||||
int[] grade = clamped(downstream.grade(), end);
|
||||
return grade == downstream.grade() ? downstream : regraded(downstream, grade, downstream.halfWidth(), downstream.depth());
|
||||
}
|
||||
|
||||
static Reach settleInto(Reach feeder, int level, List<ConfluenceGrader.Footprint> receiving) {
|
||||
int[] grade = feeder.grade();
|
||||
boolean[] fixed = fixed(feeder);
|
||||
int waterfallMinimumDrop = feeder.tier().waterfallMinimumDrop();
|
||||
int[] settled = ConfluenceGrader.settle(footprint(feeder), grade, fixed, receiving, level, waterfallMinimumDrop);
|
||||
if (settled == grade) {
|
||||
return feeder;
|
||||
}
|
||||
if (!above) {
|
||||
return downstream;
|
||||
if (!feeder.tier().cascades()) {
|
||||
ConfluenceGrader.spreadJunction(settled, grade, fixed, waterfallMinimumDrop, Integer.MIN_VALUE);
|
||||
}
|
||||
return new Reach(downstream.id(), downstream.tier(), downstream.downstreamId(), downstream.xs(), downstream.zs(),
|
||||
clamped(downstream.grade(), end), downstream.halfWidth(), downstream.depth(), downstream.style(), downstream.catchment());
|
||||
return regraded(feeder, settled, feeder.halfWidth(), feeder.depth());
|
||||
}
|
||||
|
||||
static ConfluenceGrader.Footprint footprint(Reach reach) {
|
||||
return new ConfluenceGrader.Footprint(reach.xs(), reach.zs(), reach.halfWidth());
|
||||
}
|
||||
|
||||
private static boolean[] fixed(Reach feeder) {
|
||||
ReachStyle[] style = feeder.style();
|
||||
boolean[] fixed = new boolean[style.length];
|
||||
fixed[0] = true;
|
||||
for (int point = 1; point < style.length; point++) {
|
||||
fixed[point] = style[point] == ReachStyle.POND_OUTLET;
|
||||
}
|
||||
return fixed;
|
||||
}
|
||||
|
||||
private static Reach regraded(Reach reach, int[] grade, float[] halfWidth, float[] depth) {
|
||||
ReachStyle[] style = grade == reach.grade() ? reach.style() : restyled(reach.style(), grade, reach.tier().waterfallMinimumDrop());
|
||||
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), reach.xs(), reach.zs(), grade, halfWidth, depth, style,
|
||||
reach.catchment());
|
||||
}
|
||||
|
||||
private static ReachStyle[] restyled(ReachStyle[] style, int[] grade, int waterfallMinimumDrop) {
|
||||
boolean[] mouth = new boolean[style.length];
|
||||
boolean[] outlet = new boolean[style.length];
|
||||
for (int point = 0; point < style.length; point++) {
|
||||
mouth[point] = style[point] == ReachStyle.MOUTH;
|
||||
outlet[point] = style[point] == ReachStyle.POND_OUTLET;
|
||||
}
|
||||
return ReachShaper.styles(grade, mouth, outlet, waterfallMinimumDrop);
|
||||
}
|
||||
|
||||
private static int lowestEnd(List<Reach> feeders) {
|
||||
@@ -70,9 +109,14 @@ public final class LinkBlend {
|
||||
}
|
||||
|
||||
private static int[] clamped(int[] grade, int end) {
|
||||
int[] result = grade.clone();
|
||||
for (int point = 0; point < result.length; point++) {
|
||||
result[point] = Math.min(result[point], end);
|
||||
int[] result = grade;
|
||||
for (int point = 0; point < grade.length; point++) {
|
||||
if (grade[point] > end) {
|
||||
if (result == grade) {
|
||||
result = grade.clone();
|
||||
}
|
||||
result[point] = end;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+12
-12
@@ -30,6 +30,18 @@ public final class ConfluenceGrader {
|
||||
return settled;
|
||||
}
|
||||
|
||||
public static void spreadJunction(int[] settled, int[] grade, boolean[] fixed, int waterfallMinimumDrop, int startLimit) {
|
||||
int lowered = 0;
|
||||
while (settled[lowered] == grade[lowered]) {
|
||||
lowered++;
|
||||
}
|
||||
for (int point = settled.length - 2; point >= 0; point--) {
|
||||
if (!ReachGrader.spreadPoint(settled, point, waterfallMinimumDrop, startLimit, fixed) && point < lowered) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean[] level(List<ReachDraft> drafts, int[] upstreamFirst) {
|
||||
boolean[] touched = new boolean[drafts.size()];
|
||||
for (int position = upstreamFirst.length - 1; position >= 0; position--) {
|
||||
@@ -83,18 +95,6 @@ public final class ConfluenceGrader {
|
||||
+ " of its feeder reach " + feeder.id + " at junction " + feeder.xs[end] + "," + feeder.zs[end]);
|
||||
}
|
||||
|
||||
private static void spreadJunction(int[] settled, int[] grade, boolean[] fixed, int waterfallMinimumDrop, int startLimit) {
|
||||
int lowered = 0;
|
||||
while (settled[lowered] == grade[lowered]) {
|
||||
lowered++;
|
||||
}
|
||||
for (int point = settled.length - 2; point >= 0; point--) {
|
||||
if (!ReachGrader.spreadPoint(settled, point, waterfallMinimumDrop, startLimit, fixed) && point < lowered) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pooled(Footprint feeder, boolean[] fixed, List<Footprint> receiving, double[] arc, int point) {
|
||||
if (arc[point] > POOL_CAP || fixed[point]) {
|
||||
return false;
|
||||
|
||||
@@ -506,7 +506,7 @@ public final class ReachShaper {
|
||||
draft.maxHalfWidth = running;
|
||||
}
|
||||
|
||||
static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop) {
|
||||
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop) {
|
||||
ReachStyle[] styles = new ReachStyle[grade.length];
|
||||
for (int point = 0; point < grade.length; point++) {
|
||||
int drop = point == 0 ? 0 : grade[point - 1] - grade[point];
|
||||
|
||||
+134
@@ -12,6 +12,7 @@ import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.ConfluenceGrader;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
@@ -712,6 +713,106 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowFeederSettlesIntoALowerDownstreamStart() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach downstream = line(222L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> Math.max(56, 62 - (int) ((x - 504f) / 8f)));
|
||||
Reach feeder = line(221L, narrow, downstream.id(), 440f, 200f, 504f, 200f, (x, z) -> x < 460f ? 68 : 66);
|
||||
int start = downstream.grade()[0];
|
||||
int last = feeder.xs().length - 1;
|
||||
assertEquals(new WindowKey(0, 0), WindowKey.containing(504, 200));
|
||||
assertEquals(new WindowKey(1, 0), WindowKey.containing(600, 200));
|
||||
assertTrue("the downstream owner starts below the feeder's end", start < feeder.grade()[last]);
|
||||
float pool = downstream.halfWidth()[0] + feeder.halfWidth()[last] + ConfluenceGrader.POOL_MARGIN;
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(feeder).reach(downstream);
|
||||
int previous = Integer.MAX_VALUE;
|
||||
for (int x = 440; x <= 600; x++) {
|
||||
int head = scene.head(x, 200);
|
||||
assertNotEquals("centre line is water at x=" + x, Integer.MIN_VALUE, head);
|
||||
assertTrue("water rises from " + previous + " to " + head + " at x=" + x, head <= previous);
|
||||
if (x >= 504f - pool && x <= 504) {
|
||||
assertTrue("feeder water at " + head + " above the downstream start " + start + " at x=" + x, head <= start);
|
||||
}
|
||||
previous = head;
|
||||
}
|
||||
assertEquals("the feeder keeps its own water upstream", 68, scene.head(450, 200));
|
||||
assertWindowOrderFree(scene, 27, 37, 12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clampedSeamDropsAreStyledAsFalls() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
assertEquals(6, narrow.waterfallMinimumDrop());
|
||||
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);
|
||||
Scene falls = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(hanging).reach(low);
|
||||
assertEquals(70, falls.head(496, 200));
|
||||
assertEquals(62, falls.head(497, 200));
|
||||
assertEquals("an 8-block settled drop is a waterfall", WaterRole.WATERFALL, falls.role(497, 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)));
|
||||
Scene cascade = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(steep).reach(low);
|
||||
assertEquals(66, cascade.head(496, 200));
|
||||
assertEquals(62, cascade.head(497, 200));
|
||||
assertEquals("a 4-block settled drop is a cascade", WaterRole.CASCADE, cascade.role(497, 200));
|
||||
Reach stepped = line(235L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> x < 520f ? 70 : 63);
|
||||
Reach level = line(234L, narrow, stepped.id(), 440f, 200f, 504f, 200f, (x, z) -> 66);
|
||||
assertEquals(ReachStyle.WATERFALL, stepped.style()[8]);
|
||||
Scene clamped = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(level).reach(stepped);
|
||||
assertEquals(66, clamped.head(518, 200));
|
||||
assertEquals(62, clamped.head(519, 200));
|
||||
assertEquals("a waterfall clamped to a 3-block drop is a cascade", WaterRole.CASCADE, clamped.role(519, 200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowJunctionDropsSpreadOnTiersWithoutCascades() {
|
||||
HydrologyTier gentle = new HydrologyTier("stream", 0f, 2f, 2f, 0f, 0.5f, 1, false, 6, 4, IrisBankStyle.SMOOTH, false,
|
||||
new IrisHydrologyMaterials(), "water", List.of());
|
||||
HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach low = line(262L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 62);
|
||||
Reach steep = line(261L, gentle, low.id(), 440f, 200f, 504f, 200f, (x, z) -> x >= 496f ? 66 : Math.min(80, 66 + (int) ((496f - x) / 2f)));
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(steep).reach(low);
|
||||
for (int x = 441; x <= 504; x++) {
|
||||
int drop = scene.head(x - 1, 200) - scene.head(x, 200);
|
||||
assertTrue("a " + drop + "-block step at x=" + x, drop >= 0 && drop <= 2);
|
||||
assertEquals("channel role at x=" + x, WaterRole.CHANNEL, scene.role(x, 200));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowWidthBlendKeepsAnAlreadyFlaredDownstream() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier wide = tier("river", 8f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach plain = line(241L, narrow, 0L, 504f, 200f, 600f, 200f, (x, z) -> 66);
|
||||
Reach feeder = line(242L, wide, plain.id(), 440f, 200f, 504f, 200f, (x, z) -> 66);
|
||||
Reach flared = flared(plain, feeder.halfWidth()[feeder.xs().length - 1]);
|
||||
Scene unflared = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(feeder).reach(plain);
|
||||
Scene preflared = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(feeder).reach(flared);
|
||||
assertTrue("half the feeder's width remains 8 blocks below the junction", unflared.water(512, 204));
|
||||
assertFalse("the flare is linear 8 blocks below the junction", unflared.water(512, 206));
|
||||
for (int x = 504; x <= 530; x++) {
|
||||
for (int z = 188; z <= 212; z++) {
|
||||
assertEquals("water head at " + x + "," + z, unflared.head(x, z), preflared.head(x, z));
|
||||
assertEquals("terrain at " + x + "," + z, unflared.terrain(x, z), preflared.terrain(x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sharedOutletClampsToThePondItLeadsOutOf() {
|
||||
HydrologyTier river = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach outlet = ledIn(line(251L, river, 0L, 516f, 200f, 600f, 200f, (x, z) -> Math.max(60, 68 - (int) ((x - 516f) / 10f))), 503f, 200f);
|
||||
Pond source = new Pond(250L, PondKind.NATURAL, 68, 60, 504, 200, 69.5f, circle(488, 200, 16, 1), outlet.id(), 0, "water", 488, 200);
|
||||
Pond shared = new Pond(252L, PondKind.NATURAL, 64, 58, 540, 234, 65.5f, circle(540, 240, 6, 1), outlet.id(), 0, "water", 540, 240);
|
||||
assertTrue("the lead-in starts in the source pond", source.mask().contains(503, 200));
|
||||
assertFalse("the lead-in starts off the shared pond", shared.mask().contains(503, 200));
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(outlet).pond(source).pond(shared);
|
||||
for (int x = 517; x <= 524; x++) {
|
||||
assertEquals("outlet water at the level of the pond it leads out of at x=" + x, 68, scene.head(x, 200));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyBankStyleRasterizes() {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
@@ -953,6 +1054,39 @@ public class ChunkWaterRasterTest {
|
||||
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), xs, zs, grade, halfWidth, depth, style, reach.catchment());
|
||||
}
|
||||
|
||||
private static Reach flared(Reach reach, float width) {
|
||||
int count = reach.xs().length;
|
||||
float[] halfWidth = new float[count];
|
||||
float[] depth = new float[count];
|
||||
float along = 0f;
|
||||
for (int point = 0; point < count; point++) {
|
||||
if (point > 0) {
|
||||
along += (float) Math.hypot(reach.xs()[point] - reach.xs()[point - 1], reach.zs()[point] - reach.zs()[point - 1]);
|
||||
}
|
||||
halfWidth[point] = LinkBlend.blend(width, reach.halfWidth()[point], along);
|
||||
depth[point] = reach.tier().depth(halfWidth[point]);
|
||||
}
|
||||
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), reach.xs(), reach.zs(), reach.grade(), halfWidth, depth,
|
||||
reach.style(), reach.catchment());
|
||||
}
|
||||
|
||||
private static void assertWindowOrderFree(Scene scene, int fromChunkX, int toChunkX, int chunkZ) {
|
||||
for (int chunkX = fromChunkX; chunkX <= toChunkX; chunkX++) {
|
||||
List<IndexedWindow> reversed = new ArrayList<>(scene.windows(chunkX, chunkZ));
|
||||
Collections.reverse(reversed);
|
||||
ChunkWaterRaster backward = new ChunkRasterizer(scene.settings, ChannelFluids.TIER).rasterize(chunkX, chunkZ,
|
||||
scene.natural::applyAsInt, reversed, scene.regions(chunkX, chunkZ));
|
||||
ChunkWaterRaster forward = scene.raster(chunkX, chunkZ);
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
assertEquals("head in chunk " + chunkX + "," + chunkZ, forward.waterHead(lx, lz), backward.waterHead(lx, lz));
|
||||
assertEquals("terrain in chunk " + chunkX + "," + chunkZ, forward.terrainHeight(lx, lz), backward.terrainHeight(lx, lz));
|
||||
assertEquals("role in chunk " + chunkX + "," + chunkZ, forward.role(lx, lz), backward.role(lx, lz));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Pond pond(long id, PondKind kind, int level, PondMask mask, int floorX, int floorZ, int damRaise) {
|
||||
return new Pond(id, kind, level, level - 8, floorX, floorZ, level + 1.5f, mask, 0L, damRaise, "water", floorX, floorZ);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user