mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 19:22:08 +00:00
Plunge flare
- Compute reach styles before widths - Widen channels by half at waterfall feet, fading over the plunge length - Keep the flare within the tier maximum and out of running widths - Skip reach ends, protected outlet stretches and estuaries - Test widths against channel maxima outside plunge pools
This commit is contained in:
4 files changed
+161
-9
No files matched your search
@@ -89,7 +89,7 @@ final class ReachGrader {
|
|||||||
return levels;
|
return levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float protectedStart(ReachDraft draft) {
|
static float protectedStart(ReachDraft draft) {
|
||||||
if (!draft.outlet) {
|
if (!draft.outlet) {
|
||||||
return 0f;
|
return 0f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public final class ReachShaper {
|
|||||||
private static final int SMOOTHING_PASSES = 2;
|
private static final int SMOOTHING_PASSES = 2;
|
||||||
private static final float TAPER_LENGTH = 24f;
|
private static final float TAPER_LENGTH = 24f;
|
||||||
private static final float WAIST = 0.5f;
|
private static final float WAIST = 0.5f;
|
||||||
|
static final float PLUNGE_FLARE = 0.5f;
|
||||||
public static final float OUTLET_LENGTH = 8f;
|
public static final float OUTLET_LENGTH = 8f;
|
||||||
private static final float LIP_MARGIN = 4f;
|
private static final float LIP_MARGIN = 4f;
|
||||||
private static final int LEAD_IN_REACH = 16;
|
private static final int LEAD_IN_REACH = 16;
|
||||||
@@ -380,8 +381,8 @@ public final class ReachShaper {
|
|||||||
upstream = Math.max(upstream, feeder.maxHalfWidth);
|
upstream = Math.max(upstream, feeder.maxHalfWidth);
|
||||||
feederEnd = Math.max(feederEnd, feeder.halfWidth[feeder.halfWidth.length - 1]);
|
feederEnd = Math.max(feederEnd, feeder.halfWidth[feeder.halfWidth.length - 1]);
|
||||||
}
|
}
|
||||||
widths(draft, upstream, feederEnd);
|
|
||||||
restyle(draft, seaLevel);
|
restyle(draft, seaLevel);
|
||||||
|
widths(draft, upstream, feederEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void restyle(ReachDraft draft, int seaLevel) {
|
private static void restyle(ReachDraft draft, int seaLevel) {
|
||||||
@@ -500,6 +501,7 @@ public final class ReachShaper {
|
|||||||
Opening estuary = draft.chain.end() == ReachTracer.End.OCEAN ? estuaryOpening(draft.tier.estuary(), draft.ocean, distance)
|
Opening estuary = draft.chain.end() == ReachTracer.End.OCEAN ? estuaryOpening(draft.tier.estuary(), draft.ocean, distance)
|
||||||
: Opening.closed(count);
|
: Opening.closed(count);
|
||||||
float widening = (draft.tier.estuary().flare() - 1f) * estuary.share();
|
float widening = (draft.tier.estuary().flare() - 1f) * estuary.share();
|
||||||
|
float[] plunge = plungeFlare(draft.grade, draft.style, draft.ocean, distance, ReachGrader.protectedStart(draft), draft.tier.waterfallMinimumDrop());
|
||||||
float running = upstream;
|
float running = upstream;
|
||||||
draft.halfWidth = new float[count];
|
draft.halfWidth = new float[count];
|
||||||
draft.depth = new float[count];
|
draft.depth = new float[count];
|
||||||
@@ -512,15 +514,35 @@ public final class ReachShaper {
|
|||||||
}
|
}
|
||||||
float lip = draft.held != null && draft.held[point] ? LIP_HALF_WIDTH : 0f;
|
float lip = draft.held != null && draft.held[point] ? LIP_HALF_WIDTH : 0f;
|
||||||
float channel = Math.max(Math.max(law, WAIST * running), lip);
|
float channel = Math.max(Math.max(law, WAIST * running), lip);
|
||||||
|
float flared = Math.max(channel, Math.min(draft.tier.maxHalfWidth(), channel * (1f + plunge[point])));
|
||||||
float progress = estuary.progress()[point];
|
float progress = estuary.progress()[point];
|
||||||
draft.halfWidth[point] = Math.min(HydrologySettings.MAX_HALF_WIDTH, channel * (1f + widening * progress));
|
draft.halfWidth[point] = Math.min(HydrologySettings.MAX_HALF_WIDTH, flared * (1f + widening * progress));
|
||||||
running = Math.max(running, channel);
|
running = Math.max(running, channel);
|
||||||
float depth = draft.tier.depth(channel);
|
float depth = draft.tier.depth(flared);
|
||||||
draft.depth[point] = depth + (HydrologyTier.MINIMUM_DEPTH - depth) * progress;
|
draft.depth[point] = depth + (HydrologyTier.MINIMUM_DEPTH - depth) * progress;
|
||||||
}
|
}
|
||||||
draft.maxHalfWidth = running;
|
draft.maxHalfWidth = running;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float[] plungeFlare(int[] grade, ReachStyle[] style, boolean[] ocean, float[] distance, float protectedLength, int waterfallMinimumDrop) {
|
||||||
|
int count = grade.length;
|
||||||
|
float[] flare = new float[count];
|
||||||
|
for (int foot = 1; foot < count - 1; foot++) {
|
||||||
|
int drop = grade[foot - 1] - grade[foot];
|
||||||
|
if (style[foot] != ReachStyle.WATERFALL || drop < waterfallMinimumDrop) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
float length = StepPools.plungeLength(drop);
|
||||||
|
for (int point = foot; point < count - 1 && !ocean[point] && distance[point] - distance[foot] < length; point++) {
|
||||||
|
if (distance[point] > protectedLength) {
|
||||||
|
float share = (distance[point] - distance[foot]) / length;
|
||||||
|
flare[point] = Math.max(flare[point], PLUNGE_FLARE * (1f - share * share * (3f - 2f * share)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flare;
|
||||||
|
}
|
||||||
|
|
||||||
static Opening estuaryOpening(HydrologyTier.Estuary estuary, boolean[] ocean, float[] distance) {
|
static Opening estuaryOpening(HydrologyTier.Estuary estuary, boolean[] ocean, float[] distance) {
|
||||||
int count = distance.length;
|
int count = distance.length;
|
||||||
if (estuary.length() == 0) {
|
if (estuary.length() == 0) {
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ final class StepPools {
|
|||||||
return tier.waterfallMinimumDrop() + STEP_EXTRA;
|
return tier.waterfallMinimumDrop() + STEP_EXTRA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float plungeLength(int drop) {
|
||||||
|
return Math.clamp(drop * PLUNGE_PER_DROP, PLUNGE_MIN, PLUNGE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
static void group(int[] grade, int[] floors, float[] xs, float[] zs, float[] catchments, HydrologyTier tier, float protectedLength, long seed) {
|
static void group(int[] grade, int[] floors, float[] xs, float[] zs, float[] catchments, HydrologyTier tier, float protectedLength, long seed) {
|
||||||
int count = grade.length;
|
int count = grade.length;
|
||||||
float[] along = along(xs, zs);
|
float[] along = along(xs, zs);
|
||||||
@@ -43,7 +47,7 @@ final class StepPools {
|
|||||||
int first = top - grade[point];
|
int first = top - grade[point];
|
||||||
boolean cliff = first >= tier.waterfallMinimumDrop();
|
boolean cliff = first >= tier.waterfallMinimumDrop();
|
||||||
float width = 2f * (tier.halfWidth(catchments[point]) + 1f);
|
float width = 2f * (tier.halfWidth(catchments[point]) + 1f);
|
||||||
float span = cliff ? Math.clamp(first * PLUNGE_PER_DROP, PLUNGE_MIN, PLUNGE_MAX)
|
float span = cliff ? plungeLength(first)
|
||||||
: Math.clamp(width * poolWidths(seed, xs[point], zs[point]), POOL_MIN, POOL_MAX);
|
: Math.clamp(width * poolWidths(seed, xs[point], zs[point]), POOL_MIN, POOL_MAX);
|
||||||
int end = point;
|
int end = point;
|
||||||
int highestFloor = Integer.MIN_VALUE;
|
int highestFloor = Integer.MIN_VALUE;
|
||||||
|
|||||||
+130
-4
@@ -582,6 +582,130 @@ public class ReachShaperTest {
|
|||||||
throw new AssertionError("no fall in the step window");
|
throw new AssertionError("no fall in the step window");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void waterfallFootFlaresWithinTierMax() {
|
||||||
|
HydrologySettings open = settings(config -> config.getTiers().forEach(tier -> tier.setHalfWidth(new KList<>(2D, 32D))));
|
||||||
|
HydrologySettings capped = settings(config -> config.getTiers().forEach(tier -> tier.setHalfWidth(new KList<>(3D, 4D))));
|
||||||
|
for (long seed = 1L; seed <= 24L; seed++) {
|
||||||
|
Reach roomy = fallingReach(open, 64, seed);
|
||||||
|
int foot = footOf(roomy);
|
||||||
|
String label = "seed " + seed + " " + Arrays.toString(roomy.halfWidth()) + ": ";
|
||||||
|
float above = roomy.halfWidth()[foot - 1];
|
||||||
|
assertEquals(label + "half as wide again at the foot", 1.5f * above, roomy.halfWidth()[foot], 0.05f * above);
|
||||||
|
assertFlareFades(label, roomy, foot);
|
||||||
|
for (float width : roomy.halfWidth()) {
|
||||||
|
assertTrue(label + "within the tier maximum", width <= roomy.tier().maxHalfWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
Reach full = fallingReach(capped, 64, seed);
|
||||||
|
int cappedFoot = footOf(full);
|
||||||
|
assertTrue("seed " + seed + " the channel has room to flare", full.halfWidth()[cappedFoot - 1] * 1.5f > full.tier().maxHalfWidth());
|
||||||
|
assertEquals("seed " + seed + " the flare stops at the tier maximum", full.tier().maxHalfWidth(), full.halfWidth()[cappedFoot], 1e-3f);
|
||||||
|
|
||||||
|
Reach ending = fallingReach(open, 26, seed);
|
||||||
|
int last = ending.xs().length - 1;
|
||||||
|
int endFoot = footOf(ending);
|
||||||
|
float below = ReachShaper.distances(ending.xs(), ending.zs())[last] - ReachShaper.distances(ending.xs(), ending.zs())[endFoot];
|
||||||
|
assertTrue("seed " + seed + " the reach ends inside the pool: " + below, below < plungeSpan(ending, endFoot));
|
||||||
|
assertEquals("seed " + seed + " the last point keeps its width, which feeds the next reach", ending.tier().halfWidth(ending.catchment()),
|
||||||
|
ending.halfWidth()[last], 1e-3f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void plungeFlareSkipsTheEndsOutletZonesAndTheSea() {
|
||||||
|
int count = 12;
|
||||||
|
float[] distance = new float[count];
|
||||||
|
for (int point = 0; point < count; point++) {
|
||||||
|
distance[point] = point * 2f;
|
||||||
|
}
|
||||||
|
int[] grade = new int[count];
|
||||||
|
boolean[] noOcean = new boolean[count];
|
||||||
|
boolean[] noZone = new boolean[count];
|
||||||
|
Arrays.fill(grade, 0, 3, 90);
|
||||||
|
Arrays.fill(grade, 3, count, 78);
|
||||||
|
ReachStyle[] style = ReachShaper.styles(grade, noOcean, noZone, 6, SEA_LEVEL);
|
||||||
|
float[] flare = ReachShaper.plungeFlare(grade, style, noOcean, distance, 0f, 6);
|
||||||
|
assertEquals(ReachShaper.PLUNGE_FLARE, flare[3], 0f);
|
||||||
|
assertEquals("nothing above the foot", 0f, flare[2], 0f);
|
||||||
|
assertTrue("fades through the pool", flare[3] > flare[4] && flare[4] > flare[5] && flare[5] > 0f);
|
||||||
|
assertEquals("gone past the pool", 0f, flare[3 + (int) Math.ceil(StepPools.plungeLength(12) / 2f)], 0f);
|
||||||
|
|
||||||
|
assertEquals("the protected outlet does not flare", 0f, ReachShaper.plungeFlare(grade, style, noOcean, distance, 10f, 6)[4], 0f);
|
||||||
|
assertTrue("past the protected outlet it does", ReachShaper.plungeFlare(grade, style, noOcean, distance, 7f, 6)[4] > 0f);
|
||||||
|
|
||||||
|
int[] atFirst = new int[count];
|
||||||
|
Arrays.fill(atFirst, 1, count, -12);
|
||||||
|
atFirst[0] = 0;
|
||||||
|
assertEquals("index 0 never flares", 0f, ReachShaper.plungeFlare(atFirst, ReachShaper.styles(atFirst, noOcean, noZone, 6, -40), noOcean, distance, 0f, 6)[0], 0f);
|
||||||
|
int[] atLast = new int[count];
|
||||||
|
atLast[count - 1] = -12;
|
||||||
|
assertEquals("the last index never flares", 0f, ReachShaper.plungeFlare(atLast, ReachShaper.styles(atLast, noOcean, noZone, 6, -40), noOcean, distance, 0f, 6)[count - 1], 0f);
|
||||||
|
|
||||||
|
boolean[] ocean = new boolean[count];
|
||||||
|
Arrays.fill(ocean, 3, count, true);
|
||||||
|
ReachStyle[] mouth = ReachShaper.styles(grade, ocean, noZone, 6, SEA_LEVEL);
|
||||||
|
float[] atSea = ReachShaper.plungeFlare(grade, mouth, ocean, distance, 0f, 6);
|
||||||
|
for (int point = 0; point < count; point++) {
|
||||||
|
assertEquals("a fall into the sea flares nothing at " + point, 0f, atSea[point], 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] plungeShare(Reach reach) {
|
||||||
|
boolean[] mouth = new boolean[reach.style().length];
|
||||||
|
for (int point = 0; point < mouth.length; point++) {
|
||||||
|
mouth[point] = reach.style()[point] == ReachStyle.MOUTH;
|
||||||
|
}
|
||||||
|
return ReachShaper.plungeFlare(reach.grade(), reach.style(), mouth, ReachShaper.distances(reach.xs(), reach.zs()), 0f, reach.tier().waterfallMinimumDrop());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float channelMaximum(Reach reach) {
|
||||||
|
float[] pool = plungeShare(reach);
|
||||||
|
float widest = 0f;
|
||||||
|
for (int point = 0; point < pool.length; point++) {
|
||||||
|
widest = pool[point] > 0f ? widest : Math.max(widest, reach.halfWidth()[point]);
|
||||||
|
}
|
||||||
|
return widest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertFlareFades(String label, Reach reach, int foot) {
|
||||||
|
float[] along = ReachShaper.distances(reach.xs(), reach.zs());
|
||||||
|
float span = plungeSpan(reach, foot);
|
||||||
|
float channel = reach.halfWidth()[foot - 1];
|
||||||
|
for (int point = foot + 1; point < reach.xs().length; point++) {
|
||||||
|
float below = along[point] - along[foot];
|
||||||
|
if (below >= span) {
|
||||||
|
assertTrue(label + "past the pool at " + point, reach.halfWidth()[point] < 1.1f * channel);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
assertTrue(label + "narrows down the pool at " + point, reach.halfWidth()[point] <= reach.halfWidth()[point - 1] + 0.05f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float plungeSpan(Reach reach, int foot) {
|
||||||
|
return StepPools.plungeLength(reach.grade()[foot - 1] - reach.grade()[foot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Reach fallingReach(HydrologySettings settings, int cells, long seed) {
|
||||||
|
ShapedNetwork shaped = shape(settings, network(settings, steppedValley(12), cells, 64, VALLEY_THRESHOLD, false), seed);
|
||||||
|
for (Reach reach : shaped.reaches()) {
|
||||||
|
if (footOf(reach) > 0) {
|
||||||
|
return reach;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new AssertionError("no fall in " + shaped.reaches());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int footOf(Reach reach) {
|
||||||
|
for (int point = 1; point < reach.xs().length; point++) {
|
||||||
|
if (reach.grade()[point - 1] - reach.grade()[point] >= reach.tier().waterfallMinimumDrop()) {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private static float brinkMidpoint(ShapedNetwork shaped) {
|
private static float brinkMidpoint(ShapedNetwork shaped) {
|
||||||
int falls = 0;
|
int falls = 0;
|
||||||
float midpoint = Float.NaN;
|
float midpoint = Float.NaN;
|
||||||
@@ -1822,7 +1946,7 @@ public class ReachShaperTest {
|
|||||||
if (reach.downstreamId() == 0L) {
|
if (reach.downstreamId() == 0L) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float carried = Math.max(upstreamMax.getOrDefault(reach.id(), 0f), maximum(reach.halfWidth()));
|
float carried = Math.max(upstreamMax.getOrDefault(reach.id(), 0f), channelMaximum(reach));
|
||||||
if (carried > upstreamMax.getOrDefault(reach.downstreamId(), 0f)) {
|
if (carried > upstreamMax.getOrDefault(reach.downstreamId(), 0f)) {
|
||||||
upstreamMax.put(reach.downstreamId(), carried);
|
upstreamMax.put(reach.downstreamId(), carried);
|
||||||
changed = true;
|
changed = true;
|
||||||
@@ -1832,9 +1956,10 @@ public class ReachShaperTest {
|
|||||||
int widened = 0;
|
int widened = 0;
|
||||||
for (Reach reach : shaped.reaches()) {
|
for (Reach reach : shaped.reaches()) {
|
||||||
float running = upstreamMax.getOrDefault(reach.id(), 0f);
|
float running = upstreamMax.getOrDefault(reach.id(), 0f);
|
||||||
|
float[] pool = plungeShare(reach);
|
||||||
for (int index = 0; index < reach.halfWidth().length; index++) {
|
for (int index = 0; index < reach.halfWidth().length; index++) {
|
||||||
assertTrue(reach + " at " + index, reach.halfWidth()[index] >= 0.5f * running - 1e-6f);
|
assertTrue(reach + " at " + index, reach.halfWidth()[index] >= 0.5f * running - 1e-6f);
|
||||||
running = Math.max(running, reach.halfWidth()[index]);
|
running = pool[index] > 0f ? running : Math.max(running, reach.halfWidth()[index]);
|
||||||
widened += reach.halfWidth()[index] > reach.tier().maxHalfWidth() ? 1 : 0;
|
widened += reach.halfWidth()[index] > reach.tier().maxHalfWidth() ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1928,9 +2053,10 @@ public class ReachShaperTest {
|
|||||||
float law = outlet.tier().halfWidth(outlet.catchment());
|
float law = outlet.tier().halfWidth(outlet.catchment());
|
||||||
float tributaryEnd = tributary.halfWidth()[tributary.halfWidth().length - 1];
|
float tributaryEnd = tributary.halfWidth()[tributary.halfWidth().length - 1];
|
||||||
assertTrue("the tributary " + tributaryEnd + " is narrower than the outlet " + law, tributaryEnd < 0.5f * law);
|
assertTrue("the tributary " + tributaryEnd + " is narrower than the outlet " + law, tributaryEnd < 0.5f * law);
|
||||||
|
float[] pool = plungeShare(outlet);
|
||||||
for (int point = 0; point < outlet.xs().length; point++) {
|
for (int point = 0; point < outlet.xs().length; point++) {
|
||||||
assertEquals("outlet half-width at point " + point + " (" + outlet.xs()[point] + "," + outlet.zs()[point] + ")", law,
|
assertEquals("outlet half-width at point " + point + " (" + outlet.xs()[point] + "," + outlet.zs()[point] + ")",
|
||||||
outlet.halfWidth()[point], 1e-3f);
|
Math.min(outlet.tier().maxHalfWidth(), law * (1f + pool[point])), outlet.halfWidth()[point], 1e-3f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user