Seeded river deltas

- Add the tier delta {channels 0 or 2..4, spreadDegrees 35, length 64}, validated in HydrologySettings with messages naming the tier and fingerprinted
- Guard the delta extent so a delta channel and its banks stay within the 512-block window span
- Emit delta channels after grading as ordinary sea-level MOUTH reaches that branch below the estuary start and fan out by seeded angles to the sea
- Size each delta channel at the estuary-start half-width over sqrt(channels) and taper its depth to one block at the sea
- Leave out delta channels over ground above sea level plus maxFill, across ponds, lakes, other reaches or the river's above-sea water, or short of the sea within length
- Recapture DEFAULT_FINGERPRINT and EXPECTED_SCHEMA_DIGEST
- Cover seeded, grid-independent deltas and their obstacles, the delta bounds, and inlets keeping clear of sea-level delta channels
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 23:53:17 -05:00
1 parent 904c889c2f
commit d3b364fa15
17 files changed
+723 -18

No files matched your search

@@ -0,0 +1,29 @@
package art.arcane.iris.generation.hydrology.config;
import art.arcane.iris.pack.schema.annotation.MaxNumber;
import art.arcane.iris.pack.schema.annotation.MinNumber;
import art.arcane.volmlib.util.documentation.Description;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Where a channel's estuary crosses low coastal ground it can split into a delta: extra channels at sea level that branch from the estuary and fan out to the sea on both sides of it.")
@Data
public class IrisHydrologyDelta {
@MinNumber(0)
@MaxNumber(4)
@Description("Channels that branch from each estuary of this tier: 0 for no delta, or 2 to 4. Each has the half-width of the channel where its estuary starts divided by the square root of this count. A delta channel is left out where it would cross ground more than deformation.maxFill blocks above sea level, a pond or lake, or another channel, or where it does not reach the sea within length blocks; sea inlets keep clear of delta channels.")
private int channels = 0;
@MinNumber(10)
@MaxNumber(80)
@Description("Largest angle in degrees between a delta channel and its estuary. The channels share the angles up to this value on both sides of the estuary, each turned a little at random, and bend gently back toward the sea.")
private double spreadDegrees = 35D;
@MinNumber(8)
@MaxNumber(384)
@Description("Most blocks a delta channel runs from its estuary before it reaches the sea. This length, plus the tier's halfWidth max, plus bankBand, plus 3 must not exceed 512.")
private int length = 64;
}
@@ -63,6 +63,9 @@ public class IrisHydrologyTier {
@Description("How the channel widens into an estuary where it reaches the sea.")
private IrisHydrologyEstuary estuary = new IrisHydrologyEstuary();
@Description("How the estuary splits into delta channels across low coastal ground.")
private IrisHydrologyDelta delta = new IrisHydrologyDelta();
@Description("Blocks painted on the bed, shore and banks of this tier.")
private IrisHydrologyMaterials materials = new IrisHydrologyMaterials();
@@ -8,6 +8,7 @@ import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyClimate;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDeformation;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDelta;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDrainage;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyEstuary;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyLakes;
@@ -22,6 +23,7 @@ import art.arcane.iris.generation.hydrology.config.IrisPondShore;
import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.hydrology.water.ReachShaper;
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
import com.google.gson.Gson;
@@ -39,6 +41,12 @@ public final class HydrologySettings {
private static final int MAX_BANK_BAND = 64;
private static final int MAX_ESTUARY_LENGTH = 256;
private static final double MAX_ESTUARY_FLARE = 4D;
private static final int MIN_DELTA_CHANNELS = 2;
private static final int MAX_DELTA_CHANNELS = 4;
private static final double MIN_DELTA_SPREAD = 10D;
private static final double MAX_DELTA_SPREAD = 80D;
private static final int MIN_DELTA_LENGTH = 8;
private static final int MAX_DELTA_LENGTH = 384;
public static final float MAX_HALF_WIDTH = 64f;
private static final double MIN_INLET_HALF_WIDTH = 1D;
private static final double MAX_INLET_HALF_WIDTH = 16D;
@@ -242,8 +250,35 @@ public final class HydrologySettings {
return new HydrologyTier(config.getName(), (float) config.getMinCatchment(), halfWidth.min(), halfWidth.max(),
(float) config.getWidthFactor(), (float) config.getDepthRatio(), config.getInset(), config.isCascades(),
config.getWaterfallMinimumDrop(), config.getBankBand(), config.getBankStyle(),
estuary(config.getEstuary(), field + ".estuary"), materials(config.getMaterials(), field + ".materials"), config.getFluid(),
decorators(config.getDecorators(), field + ".decorators"));
estuary(config.getEstuary(), field + ".estuary"), delta(config, halfWidth.max(), field + ".delta"),
materials(config.getMaterials(), field + ".materials"), config.getFluid(), decorators(config.getDecorators(), field + ".decorators"));
}
private static HydrologyTier.Delta delta(IrisHydrologyTier tier, float maxHalfWidth, String field) {
IrisHydrologyDelta config = tier.getDelta();
String named = "Hydrology " + field + " of tier '" + tier.getName() + "'";
if (config == null) {
throw new IllegalArgumentException(named + " must be an object");
}
if (config.getChannels() != 0 && (config.getChannels() < MIN_DELTA_CHANNELS || config.getChannels() > MAX_DELTA_CHANNELS)) {
throw new IllegalArgumentException(named + " has channels " + config.getChannels() + "; a delta has 0 channels (none) or "
+ MIN_DELTA_CHANNELS + " to " + MAX_DELTA_CHANNELS);
}
if (!(config.getSpreadDegrees() >= MIN_DELTA_SPREAD && config.getSpreadDegrees() <= MAX_DELTA_SPREAD)) {
throw new IllegalArgumentException(named + " has spreadDegrees " + config.getSpreadDegrees() + "; it must stay within "
+ MIN_DELTA_SPREAD + ".." + MAX_DELTA_SPREAD);
}
if (config.getLength() < MIN_DELTA_LENGTH || config.getLength() > MAX_DELTA_LENGTH) {
throw new IllegalArgumentException(named + " has length " + config.getLength() + "; it must stay within "
+ MIN_DELTA_LENGTH + ".." + MAX_DELTA_LENGTH);
}
long extent = (long) config.getLength() + ReachShaper.DELTA_STEP + (long) Math.ceil(maxHalfWidth) + tier.getBankBand() + 1L;
if (config.getChannels() > 0 && extent > WindowKey.SIZE) {
throw new IllegalArgumentException(named + " reaches " + extent + " blocks from its sea end (length " + config.getLength()
+ " + " + ReachShaper.DELTA_STEP + " for the last step + halfWidth max " + maxHalfWidth + " + bankBand " + tier.getBankBand()
+ " + 1); a delta channel and its banks must stay within " + WindowKey.SIZE + " blocks");
}
return new HydrologyTier.Delta(config.getChannels(), (float) config.getSpreadDegrees(), config.getLength());
}
private static HydrologyTier.Estuary estuary(IrisHydrologyEstuary config, String field) {
@@ -569,6 +604,7 @@ public final class HydrologySettings {
.add(tier.widthFactor()).add(tier.depthRatio()).add(tier.inset()).add(tier.cascades())
.add(tier.waterfallMinimumDrop()).add(tier.bankBand()).add(tier.bankStyle())
.add(tier.estuary().length()).add(tier.estuary().flare())
.add(tier.delta().channels()).add(tier.delta().spreadDegrees()).add(tier.delta().length())
.add(tier.materials()).add(tier.fluid());
}
}
@@ -19,6 +19,7 @@ public record HydrologyTier(
int bankBand,
IrisBankStyle bankStyle,
Estuary estuary,
Delta delta,
IrisHydrologyMaterials materials,
String fluid,
List<IrisDecorator> decorators
@@ -37,4 +38,7 @@ public record HydrologyTier(
public record Estuary(int length, float flare) {
}
public record Delta(int channels, float spreadDegrees, int length) {
}
}
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.hydrology.water;
import art.arcane.iris.generation.hydrology.grid.CellHash;
import art.arcane.iris.generation.hydrology.grid.DemGrid;
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.plan.WindowKey;
import art.arcane.iris.generation.hydrology.raster.LinkBlend;
@@ -10,10 +11,12 @@ import art.arcane.iris.generation.hydrology.raster.LinkBlend;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
public final class ReachShaper {
public static final int DELTA_STEP = 2;
private static final int SMOOTHING_PASSES = 2;
private static final float TAPER_LENGTH = 24f;
private static final float WAIST = 0.5f;
@@ -26,6 +29,10 @@ public final class ReachShaper {
private static final long SALT_COARSE_START = 0x434f4152534553L;
private static final long SALT_COARSE_END = 0x434f415253454eL;
private static final long SALT_SHAPE = 0x5348415045L;
private static final long SALT_DELTA = 0x44454c5441L;
private static final float DELTA_CLEARANCE = 2f;
private static final double DELTA_BEND = 0.5D;
private static final double DELTA_JITTER = 0.25D;
private final HydrologySettings settings;
@@ -91,7 +98,269 @@ public final class ReachShaper {
Pond settled = lowered(ponds.get(pond), levels[pond]);
linked.add(outletDrafts[pond] < 0 ? settled : settled.withOutletReachId(drafts.get(outletDrafts[pond]).id));
}
return new ShapedNetwork(reaches(drafts), linked);
List<Reach> reaches = reaches(drafts);
reaches.addAll(deltas(drafts, reaches, linked, fine, seed));
return new ShapedNetwork(reaches, linked);
}
private List<Reach> deltas(List<ReachDraft> drafts, List<Reach> reaches, List<Pond> ponds, HeightLattice fine, long seed) {
List<Integer> mouths = new ArrayList<>();
for (int index = 0; index < drafts.size(); index++) {
ReachDraft draft = drafts.get(index);
if (draft.tier.delta().channels() > 0 && draft.chain.end() == ReachTracer.End.OCEAN) {
mouths.add(index);
}
}
if (mouths.isEmpty()) {
return List.of();
}
mouths.sort(Comparator.comparingLong((Integer index) -> drafts.get(index).id).thenComparingDouble(index -> drafts.get(index).xs[0])
.thenComparingDouble(index -> drafts.get(index).zs[0]));
List<Reach> accepted = new ArrayList<>();
for (int index : mouths) {
ReachDraft mouth = drafts.get(index);
Reach parent = reaches.get(index);
List<Reach> earlier = List.copyOf(accepted);
for (Reach channel : distributaries(mouth, mouth.tier, fine, seed)) {
if (!crosses(channel, parent, reaches, earlier, ponds)) {
accepted.add(channel);
}
}
}
return accepted;
}
private List<Reach> distributaries(ReachDraft mouth, HydrologyTier tier, HeightLattice fine, long seed) {
int last = mouth.xs.length - 1;
int start = estuaryStart(mouth.style);
int channels = tier.delta().channels();
float halfWidth = Math.min(tier.maxHalfWidth(), mouth.halfWidth[start] / (float) Math.sqrt(channels));
float[] distance = distances(mouth.xs, mouth.zs);
float lip = start == 0 ? 0f : 0.5f * (distance[start] - distance[start - 1]);
float branch = distance[start] + halfWidth + DELTA_CLEARANCE + 1f + lip;
double axisX = mouth.xs[last] - mouth.xs[start];
double axisZ = mouth.zs[last] - mouth.zs[start];
if (start == last || branch >= distance[last] || Math.hypot(axisX, axisZ) < 1e-3D) {
return List.of();
}
float[] at = pointAt(mouth.xs, mouth.zs, distance, start, branch);
double heading = Math.atan2(axisZ, axisX);
long choices = CellHash.mix(seed, SALT_DELTA, (int) Math.floor(mouth.xs[last]), (int) Math.floor(mouth.zs[last]));
int firstSide = CellHash.unit(CellHash.mix(choices, SALT_DELTA, -1, 0)) < 0.5D ? 1 : -1;
List<Reach> made = new ArrayList<>(channels);
for (int channel = 0; channel < channels; channel++) {
long channelChoices = CellHash.mix(choices, SALT_DELTA, channel, 0);
Fan fan = new Fan(CellHash.mix(mouth.id, SALT_DELTA, channel, channels), at[0], at[1], heading,
angle(tier.delta(), channelChoices, channel, firstSide), DELTA_BEND * CellHash.unit(CellHash.mix(channelChoices, SALT_DELTA, 2, 0)),
halfWidth);
Reach reach = distributary(mouth, tier, fine, fan);
if (reach != null) {
made.add(reach);
}
}
return made;
}
private static int estuaryStart(ReachStyle[] style) {
int start = style.length - 1;
if (style[start] != ReachStyle.MOUTH) {
return start;
}
while (start > 0 && style[start - 1] == ReachStyle.MOUTH) {
start--;
}
return start;
}
private static float[] pointAt(float[] xs, float[] zs, float[] distance, int from, float along) {
int segment = from;
while (distance[segment + 1] < along) {
segment++;
}
float share = (along - distance[segment]) / Math.max(1e-6f, distance[segment + 1] - distance[segment]);
return new float[]{xs[segment] + share * (xs[segment + 1] - xs[segment]), zs[segment] + share * (zs[segment + 1] - zs[segment])};
}
private static double angle(HydrologyTier.Delta delta, long channelChoices, int channel, int firstSide) {
int side = channel % 2 == 0 ? firstSide : -firstSide;
int onSide = side == firstSide ? (delta.channels() + 1) / 2 : delta.channels() / 2;
double turn = CellHash.unit(CellHash.mix(channelChoices, SALT_DELTA, 1, 0));
return side * Math.toRadians(delta.spreadDegrees()) * (channel / 2 + 1 - DELTA_JITTER * turn) / onSide;
}
private Reach distributary(ReachDraft mouth, HydrologyTier tier, HeightLattice fine, Fan fan) {
int length = tier.delta().length();
int stations = (length + DELTA_STEP - 1) / DELTA_STEP + 1;
float[] xs = new float[stations];
float[] zs = new float[stations];
xs[0] = fan.x();
zs[0] = fan.z();
for (int station = 1; station < stations; station++) {
double direction = fan.heading() + fan.angle() * (1D - fan.bend() * ((station - 1) * DELTA_STEP) / length);
xs[station] = (float) (xs[station - 1] + DELTA_STEP * Math.cos(direction));
zs[station] = (float) (zs[station - 1] + DELTA_STEP * Math.sin(direction));
}
int step = fine.cell();
int[] nodeX = new int[3 * stations];
int[] nodeZ = new int[3 * stations];
for (int station = 0; station < stations; station++) {
int next = Math.min(stations - 1, station + 1);
int previous = Math.max(0, station - 1);
double dx = xs[next] - xs[previous];
double dz = zs[next] - zs[previous];
double run = Math.max(1e-6D, Math.hypot(dx, dz));
for (int offset = -1; offset <= 1; offset++) {
int node = 3 * station + offset + 1;
nodeX[node] = (int) Math.floor((xs[station] - offset * fan.halfWidth() * dz / run) / step + 0.5D);
nodeZ[node] = (int) Math.floor((zs[station] + offset * fan.halfWidth() * dx / run) / step + 0.5D);
}
}
HydrologySampleBuffer samples = new HydrologySampleBuffer(nodeX.length);
fine.fill(nodeX, nodeZ, samples);
float highest = settings.seaLevel() + settings.deformation().maxFill();
int sea = -1;
for (int station = 0; station < stations; station++) {
if (samples.ocean()[3 * station + 1]) {
sea = station;
break;
}
for (int node = 3 * station; node < 3 * station + 3; node++) {
if (samples.height()[node] > highest) {
return null;
}
}
}
if (sea < 2) {
return null;
}
int end = Math.min(stations - 1, sea + 1);
return reach(mouth, tier, fan, Arrays.copyOf(xs, end + 1), Arrays.copyOf(zs, end + 1));
}
private Reach reach(ReachDraft mouth, HydrologyTier tier, Fan fan, float[] xs, float[] zs) {
int count = xs.length;
float[] distance = distances(xs, zs);
int[] grade = new int[count];
float[] halfWidth = new float[count];
float[] depth = new float[count];
ReachStyle[] style = new ReachStyle[count];
float channelDepth = tier.depth(fan.halfWidth());
for (int point = 0; point < count; point++) {
grade[point] = settings.seaLevel();
halfWidth[point] = fan.halfWidth();
depth[point] = channelDepth + (HydrologyTier.MINIMUM_DEPTH - channelDepth) * distance[point] / distance[count - 1];
style[point] = ReachStyle.MOUTH;
}
return new Reach(fan.id(), tier, 0L, xs, zs, grade, halfWidth, depth, style, mouth.catchment / tier.delta().channels());
}
private boolean crosses(Reach channel, Reach parent, List<Reach> reaches, List<Reach> earlier, List<Pond> ponds) {
float reach = channel.halfWidth()[0] + DELTA_CLEARANCE;
int minX = (int) Math.floor(minimum(channel.xs()) - reach);
int minZ = (int) Math.floor(minimum(channel.zs()) - reach);
int maxX = (int) Math.ceil(maximum(channel.xs()) + reach);
int maxZ = (int) Math.ceil(maximum(channel.zs()) + reach);
List<Reach> others = new ArrayList<>();
for (Reach other : reaches) {
if (other != parent && near(other, minX, minZ, maxX, maxZ)) {
others.add(other);
}
}
for (Reach other : earlier) {
if (near(other, minX, minZ, maxX, maxZ)) {
others.add(other);
}
}
List<Pond> nearby = new ArrayList<>();
for (Pond pond : ponds) {
if (near(pond.mask(), minX, minZ, maxX, maxZ)) {
nearby.add(pond);
}
}
boolean parentNear = near(parent, minX, minZ, maxX, maxZ);
for (int z = minZ; z <= maxZ; z++) {
for (int x = minX; x <= maxX; x++) {
if (distanceTo(channel, x, z) > reach) {
continue;
}
for (Pond pond : nearby) {
if (pond.mask().contains(x, z)) {
return true;
}
}
for (Reach other : others) {
if (waterGrade(other, x, z) != Integer.MIN_VALUE) {
return true;
}
}
if (parentNear && waterGrade(parent, x, z) > settings.seaLevel()) {
return true;
}
}
}
return false;
}
private static int waterGrade(Reach reach, double x, double z) {
double nearest = Double.POSITIVE_INFINITY;
int grade = Integer.MIN_VALUE;
for (int segment = 0; segment + 1 < reach.xs().length; segment++) {
double ax = reach.xs()[segment];
double az = reach.zs()[segment];
double dx = reach.xs()[segment + 1] - ax;
double dz = reach.zs()[segment + 1] - az;
double length = dx * dx + dz * dz;
double t = length == 0D ? 0D : Math.clamp(((x - ax) * dx + (z - az) * dz) / length, 0D, 1D);
double distance = Math.hypot(x - (ax + t * dx), z - (az + t * dz));
double width = reach.halfWidth()[segment] + t * (reach.halfWidth()[segment + 1] - reach.halfWidth()[segment]);
if (distance <= width && distance < nearest) {
nearest = distance;
grade = reach.grade()[t < 0.5D ? segment : segment + 1];
}
}
return grade;
}
private static double distanceTo(Reach reach, double x, double z) {
double nearest = Double.POSITIVE_INFINITY;
for (int segment = 0; segment + 1 < reach.xs().length; segment++) {
double ax = reach.xs()[segment];
double az = reach.zs()[segment];
double dx = reach.xs()[segment + 1] - ax;
double dz = reach.zs()[segment + 1] - az;
double length = dx * dx + dz * dz;
double t = length == 0D ? 0D : Math.clamp(((x - ax) * dx + (z - az) * dz) / length, 0D, 1D);
nearest = Math.min(nearest, Math.hypot(x - (ax + t * dx), z - (az + t * dz)));
}
return nearest;
}
private static boolean near(Reach reach, int minX, int minZ, int maxX, int maxZ) {
float widest = maximum(reach.halfWidth());
return minimum(reach.xs()) - widest <= maxX && maximum(reach.xs()) + widest >= minX
&& minimum(reach.zs()) - widest <= maxZ && maximum(reach.zs()) + widest >= minZ;
}
private static boolean near(PondMask mask, int minX, int minZ, int maxX, int maxZ) {
int half = mask.step() >> 1;
return mask.originX() - half <= maxX && mask.originX() + (mask.width() - 1) * mask.step() + half >= minX
&& mask.originZ() - half <= maxZ && mask.originZ() + (mask.depth() - 1) * mask.step() + half >= minZ;
}
private static float minimum(float[] values) {
float minimum = Float.POSITIVE_INFINITY;
for (float value : values) {
minimum = Math.min(minimum, value);
}
return minimum;
}
private static float maximum(float[] values) {
float maximum = Float.NEGATIVE_INFINITY;
for (float value : values) {
maximum = Math.max(maximum, value);
}
return maximum;
}
public List<Reach> coarsePaths(DemGrid filled, int[] receivers, float[] accumulation, BitSet channels, long seed) {
@@ -658,4 +927,7 @@ public final class ReachShaper {
return new Opening(new float[count], 0f);
}
}
private record Fan(long id, float x, float z, double heading, double angle, double bend, float halfWidth) {
}
}
@@ -18,9 +18,9 @@ public class IrisHydrologyDefaultsTest {
"enabled": false,
"drainage": { "fillEpsilon": 0.001, "breachDepth": 24, "wetnessThinning": true, "minimumHeadKeep": 0.25, "saturationCatchment": 4194304 },
"tiers": [
{ "name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "widthFactor": 1.0, "depthRatio": 0.4, "inset": 1, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 0, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "materials": {}, "fluid": "water" },
{ "name": "river", "minCatchment": 20000, "halfWidth": [2, 8], "widthFactor": 1.0, "depthRatio": 0.45, "inset": 2, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 32, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "materials": {}, "fluid": "water" },
{ "name": "major", "minCatchment": 320000, "halfWidth": [8, 16], "widthFactor": 1.0, "depthRatio": 0.5, "inset": 3, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 48, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "materials": {}, "fluid": "water" }
{ "name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "widthFactor": 1.0, "depthRatio": 0.4, "inset": 1, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 0, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "delta": { "channels": 0, "spreadDegrees": 35, "length": 64 }, "materials": {}, "fluid": "water" },
{ "name": "river", "minCatchment": 20000, "halfWidth": [2, 8], "widthFactor": 1.0, "depthRatio": 0.45, "inset": 2, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 32, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "delta": { "channels": 0, "spreadDegrees": 35, "length": 64 }, "materials": {}, "fluid": "water" },
{ "name": "major", "minCatchment": 320000, "halfWidth": [8, 16], "widthFactor": 1.0, "depthRatio": 0.5, "inset": 3, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 48, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "delta": { "channels": 0, "spreadDegrees": 35, "length": 64 }, "materials": {}, "fluid": "water" }
],
"ponds": {
"natural": { "enabled": true, "keep": 1.0, "minArea": 256, "maxArea": 65536, "minDepth": 2 },
@@ -127,7 +127,7 @@ public class HydrologyPlanCodecTest {
}
HydrologyTier foreign = new HydrologyTier("foreign", 0f, 1f, 2f, 1f, 0.4f, 1, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(), "water", List.of());
Reach stray = new Reach(6L, foreign, -1L, new float[]{1f, 2f}, new float[]{1f, 2f}, new int[]{1, 1}, new float[]{1f, 1f},
new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.RUN}, 1f);
try {
@@ -32,7 +32,7 @@ public class HydrologySettingsTest {
private static final int SEA_LEVEL = 62;
private static final int MIN_Y = -64;
private static final int MAX_Y = 320;
private static final long DEFAULT_FINGERPRINT = 4889114733390836736L;
private static final long DEFAULT_FINGERPRINT = -5309117903859653038L;
@Test
public void densityIsBoundedAndChangesThePlanIdentity() {
@@ -238,6 +238,18 @@ public class HydrologySettingsTest {
estuaryFlare.getTiers().get(2).getEstuary().setFlare(3D);
fingerprints.add(compile(estuaryFlare).fingerprint());
IrisHydrology deltaChannels = new IrisHydrology();
deltaChannels.getTiers().get(2).getDelta().setChannels(3);
fingerprints.add(compile(deltaChannels).fingerprint());
IrisHydrology deltaSpread = new IrisHydrology();
deltaSpread.getTiers().get(2).getDelta().setSpreadDegrees(50D);
fingerprints.add(compile(deltaSpread).fingerprint());
IrisHydrology deltaLength = new IrisHydrology();
deltaLength.getTiers().get(2).getDelta().setLength(96);
fingerprints.add(compile(deltaLength).fingerprint());
fingerprints.add(HydrologySettings.compile(new IrisHydrology(), SEED + 1L, SEA_LEVEL, MIN_Y, MAX_Y).fingerprint());
fingerprints.add(HydrologySettings.compile(new IrisHydrology(), SEED, SEA_LEVEL + 1, MIN_Y, MAX_Y).fingerprint());
@@ -395,6 +407,42 @@ public class HydrologySettingsTest {
assertEquals(new HydrologyTier.Estuary(48, 2.5f), compiled.tiers().get(2).estuary());
}
@Test
public void compileRejectsADeltaOutsideItsBounds() {
for (int channels : new int[]{-1, 1, 5}) {
IrisHydrology config = new IrisHydrology();
config.getTiers().get(2).getDelta().setChannels(channels);
assertRejected(config, "tiers[2].delta of tier 'major' has channels " + channels);
}
for (double spread : new double[]{9.99D, 80.01D, Double.NaN}) {
IrisHydrology config = new IrisHydrology();
config.getTiers().get(1).getDelta().setSpreadDegrees(spread);
assertRejected(config, "tiers[1].delta of tier 'river' has spreadDegrees");
}
for (int length : new int[]{7, 385}) {
IrisHydrology config = new IrisHydrology();
config.getTiers().get(0).getDelta().setLength(length);
assertRejected(config, "tiers[0].delta of tier 'stream' has length " + length);
}
IrisHydrology missing = new IrisHydrology();
missing.getTiers().get(0).setDelta(null);
assertRejected(missing, "tiers[0].delta of tier 'stream' must be an object");
IrisHydrology wide = new IrisHydrology();
wide.getTiers().get(2).setHalfWidth(new KList<>(8D, 64D)).setBankBand(64).getDelta().setLength(384).setChannels(2);
assertRejected(wide, "tiers[2].delta of tier 'major' reaches 515 blocks");
wide.getTiers().get(2).getDelta().setChannels(0);
assertEquals(new HydrologyTier.Delta(0, 35f, 384), compile(wide).tiers().get(2).delta());
IrisHydrology bounds = new IrisHydrology();
bounds.getTiers().get(0).getDelta().setChannels(2).setSpreadDegrees(10D).setLength(8);
bounds.getTiers().get(1).getDelta().setChannels(4).setSpreadDegrees(80D).setLength(384);
HydrologySettings compiled = compile(bounds);
assertEquals(new HydrologyTier.Delta(2, 10f, 8), compiled.tiers().get(0).delta());
assertEquals(new HydrologyTier.Delta(4, 80f, 384), compiled.tiers().get(1).delta());
assertEquals(new HydrologyTier.Delta(0, 35f, 64), compiled.tiers().get(2).delta());
}
@Test
public void compileRejectsHalfWidthAbove64() {
IrisHydrology config = new IrisHydrology();
@@ -906,7 +906,7 @@ public class ChunkWaterRasterTest {
@Test
public void crossWindowJunctionDropsSpreadOnTiersWithoutCascades() {
HydrologyTier gentle = new HydrologyTier("stream", 0f, 2f, 2f, 0f, 0.5f, 1, false, 6, 4, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), 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)));
@@ -1208,7 +1208,7 @@ public class ChunkWaterRasterTest {
private static HydrologyTier lavaTier() {
return new HydrologyTier("lava", 0f, 1.5f, 1.5f, 0f, 0.5f, 1, true, 6, 8, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "lava", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(), "lava", List.of());
}
private static void assertLavaSealedFromTheSea(Scene scene, HydrologySettings settings, IntBinaryOperator coast) {
@@ -1308,7 +1308,7 @@ public class ChunkWaterRasterTest {
private static HydrologyTier tier(String name, float halfWidth, float depthRatio, int bankBand, IrisBankStyle style) {
return new HydrologyTier(name, 0f, halfWidth, halfWidth, 0f, depthRatio, 1, true, 6, bankBand, style,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(), "water", List.of());
}
private static Reach line(long id, HydrologyTier tier, long downstreamId, float startX, float startZ, float endX, float endZ, Grade grade) {
@@ -121,7 +121,7 @@ public class PondChannelSettlementTest {
private static Reach line(long id, int x0, int z0, int x1, int z1, float width, int first, int last) {
HydrologyTier tier = new HydrologyTier("river", 0f, width, width, 0f, 0.5f, 2, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), null, "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), null, "water", List.of());
float[] widths = new float[]{width, width};
float[] depth = new float[]{2f, 2f};
ReachStyle[] styles = new ReachStyle[2];
@@ -26,7 +26,7 @@ public class ReachIndexTest {
private static final WindowKey WINDOW = new WindowKey(0, 0);
private static final int BANK_BAND = 4;
private static final HydrologyTier TIER = new HydrologyTier("test", 0f, 1f, 4f, 1f, 0.4f, 1, true, 6, BANK_BAND, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(), "water", List.of());
@Test
public void aReachIdTwiceInOnePlanFailsClosedNamingTheWindow() {
@@ -187,7 +187,7 @@ public class ReachIndexTest {
private static HydrologyTier tier(String name, int bankBand) {
return new HydrologyTier(name, 0f, 0.5f, 4f, 1f, 0.4f, 1, true, 6, bankBand, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(),
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(),
"water", List.of());
}
@@ -18,7 +18,7 @@ import static org.junit.Assert.assertTrue;
public class ReachSegmentsTest {
private static final HydrologyTier TIER = new HydrologyTier("test", 0f, 1f, 4f, 1f, 0.4f, 1, true, 6, 4, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(), "water", List.of());
@Test
public void coveredChannelLookupsMatchTheFullScan() {
@@ -4,6 +4,7 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.plan.WindowKey;
import art.arcane.iris.generation.hydrology.water.Reach;
import art.arcane.iris.generation.hydrology.water.ReachStyle;
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
@@ -277,6 +278,68 @@ public class SeaInletPlannerTest {
}
}
@Test
public void inletsKeepClearOfSeaLevelDeltaChannels() {
HydrologySettings settings = InletTerrain.settings();
InletTerrain terrain = InletTerrain.cliff(30D);
List<SeaInlet> open = terrain.plan(settings);
assertFalse(open.isEmpty());
SeaInlet first = open.get(0);
Reach channel = deltaChannel(settings, first.xs()[1] + 16f, first.zs()[1], InletTerrain.COAST_X - 12f, first.zs()[0]);
assertTrue("the channel runs through the inlet's opening", crosses(first, channel));
List<SeaInlet> planned = terrain.plan(settings, new ShapedNetwork(List.of(channel), List.of()));
for (SeaInlet inlet : planned) {
assertFalse(inlet + " crosses the delta channel", crosses(inlet, channel));
}
}
private static Reach deltaChannel(HydrologySettings settings, float fromX, float fromZ, float toX, float toZ) {
int points = Math.max(2, (int) Math.ceil(Math.hypot(toX - fromX, toZ - fromZ) / 2D) + 1);
float[] xs = new float[points];
float[] zs = new float[points];
int[] grades = new int[points];
float[] widths = new float[points];
float[] depths = new float[points];
ReachStyle[] styles = new ReachStyle[points];
for (int point = 0; point < points; point++) {
xs[point] = fromX + (toX - fromX) * point / (points - 1);
zs[point] = fromZ + (toZ - fromZ) * point / (points - 1);
grades[point] = SEA;
widths[point] = 3.5f;
depths[point] = 1.5f;
styles[point] = ReachStyle.MOUTH;
}
return new Reach(79L, settings.tiers().get(2), 0L, xs, zs, grades, widths, depths, styles, 150000f);
}
private static boolean crosses(SeaInlet inlet, Reach channel) {
int[] bounds = SeaInletRasterizer.bounds(inlet);
int[] column = new int[2];
for (int z = bounds[1]; z <= bounds[3]; z++) {
for (int x = bounds[0]; x <= bounds[2]; x++) {
if (SeaInletRasterizer.column(inlet, x, z, column) && inWater(channel, x, z)) {
return true;
}
}
}
return false;
}
private static boolean inWater(Reach reach, int x, int z) {
for (int segment = 0; segment + 1 < reach.xs().length; segment++) {
double ax = reach.xs()[segment];
double az = reach.zs()[segment];
double dx = reach.xs()[segment + 1] - ax;
double dz = reach.zs()[segment + 1] - az;
double length = dx * dx + dz * dz;
double t = length == 0D ? 0D : Math.clamp(((x - ax) * dx + (z - az) * dz) / length, 0D, 1D);
if (Math.hypot(x - (ax + t * dx), z - (az + t * dz)) <= reach.halfWidth()[segment]) {
return true;
}
}
return false;
}
@Test
public void endsInChamber() {
HydrologySettings settings = InletTerrain.settings();
@@ -50,6 +50,11 @@ public class ReachShaperTest {
private static final int WINDOW_MIN_X = 140;
private static final int WINDOW_MAX_X = 250;
private static final int OUTLET_POND_LEVEL = SEA_LEVEL + 3;
private static final int DELTA_ROW = 128;
private static final int DELTA_SEA_X = 240;
private static final double DELTA_COAST_X = 236D;
private static final double DELTA_RISE = 0.1D;
private static final int DELTA_HILL_Z = DELTA_ROW + 12;
private static final byte ALLOW_ALL = HydrologySampleBuffer.ALLOW_STREAMS | HydrologySampleBuffer.ALLOW_PONDS;
@Test
@@ -1028,6 +1033,75 @@ public class ReachShaperTest {
assertEquals(1f, half.progress()[2], 1e-6f);
}
@Test
public void majorMouthSplitsIntoSeededDistributaries() {
for (int channels = 2; channels <= 4; channels++) {
HydrologySettings settings = deltaSettings(channels);
ShapedNetwork shaped = deltaCoast(settings, 0, 0, List.of(), Integer.MIN_VALUE, SEED);
Reach parent = deltaParent(shaped, DELTA_ROW);
List<Reach> fan = distributaries(shaped, parent);
assertEquals(channels + " delta channels", channels, fan.size());
assertEquals("only the river and its delta", channels + 1, shaped.reaches().size());
int estuary = trailingMouth(parent);
float halfWidth = parent.halfWidth()[estuary] / (float) Math.sqrt(channels);
for (Reach channel : fan) {
int last = channel.xs().length - 1;
assertEquals(channel.toString(), 0L, channel.downstreamId());
assertEquals(channel.toString(), parent.tier(), channel.tier());
for (int point = 0; point <= last; point++) {
assertEquals(channel + " at sea level at " + point, SEA_LEVEL, channel.grade()[point]);
assertEquals(channel + " is a mouth at " + point, ReachStyle.MOUTH, channel.style()[point]);
assertEquals(channel + " half-width at " + point, halfWidth, channel.halfWidth()[point], 1e-6f);
}
assertTrue(channel + " branches below the estuary start", channel.xs()[0] > parent.xs()[estuary]);
assertTrue(channel + " ends where the sea begins", deltaGround(fineNode(channel.xs()[last]), fineNode(channel.zs()[last])) <= SEA_LEVEL);
assertTrue(channel + " crosses land first", deltaGround(fineNode(channel.xs()[1]), fineNode(channel.zs()[1])) > SEA_LEVEL);
double angle = Math.toDegrees(Math.atan2(Math.abs(channel.zs()[last] - channel.zs()[0]), channel.xs()[last] - channel.xs()[0]));
assertTrue(channel + " fans out within the spread: " + angle, angle > 3D && angle < 37D);
assertEquals(channel + " depth meets the seabed", HydrologyTier.MINIMUM_DEPTH, channel.depth()[last], 1e-6f);
}
assertDeltaClear(shaped, List.of());
assertEquals("deterministic", byId(shaped.reaches()), byId(deltaCoast(settings, 0, 0, List.of(), Integer.MIN_VALUE, SEED).reaches()));
assertEquals("independent of the grid origin", byId(shaped.reaches()),
byId(deltaCoast(settings, -64, -40, List.of(), Integer.MIN_VALUE, SEED).reaches()));
List<Reach> reseeded = distributaries(deltaCoast(settings, 0, 0, List.of(), Integer.MIN_VALUE, SEED + 1L), null);
assertEquals(channels, reseeded.size());
assertNotEquals("the seed chooses the channels", ends(fan), ends(reseeded));
}
HydrologySettings settings = deltaSettings(2);
List<Reach> clean = distributaries(deltaCoast(settings, 0, 0, List.of(), Integer.MIN_VALUE, SEED), null);
Reach north = clean.get(0).zs()[clean.get(0).xs().length - 1] > DELTA_ROW ? clean.get(0) : clean.get(1);
Reach south = north == clean.get(0) ? clean.get(1) : clean.get(0);
int far = north.xs().length - 3;
Pond pond = new Pond(91L, PondKind.NATURAL, SEA_LEVEL + 1, SEA_LEVEL - 1, 0, 0, SEA_LEVEL + 1.5f,
disk(Math.round(north.xs()[far]), Math.round(north.zs()[far]), 2), 0L, 0, "water", Math.round(north.xs()[far]),
Math.round(north.zs()[far]));
assertTrue("the pond lies on the northern channel", coversMask(north, pond.mask()));
ShapedNetwork ponded = deltaCoast(settings, 0, 0, List.of(pond), Integer.MIN_VALUE, SEED);
assertFalse("the pond lies clear of the river", coversMask(deltaParent(ponded, DELTA_ROW), pond.mask()));
assertEquals("a channel that would cross a pond is left out", List.of(south), distributaries(ponded, null));
assertDeltaClear(ponded, List.of(pond));
boolean climbs = false;
for (int point = 0; point < north.xs().length; point++) {
climbs |= north.zs()[point] > DELTA_HILL_Z + 2 && north.xs()[point] < DELTA_COAST_X - 4D;
}
assertTrue("the northern channel would climb the hill", climbs);
ShapedNetwork hill = deltaCoast(settings, 0, 0, List.of(), Integer.MIN_VALUE, SEED, ReachShaperTest::northHill);
assertEquals("a channel that would cut through ground above the fill limit is left out", List.of(south), distributaries(hill, null));
ShapedNetwork twin = deltaCoast(settings, 0, 0, List.of(), DELTA_ROW + 32, SEED);
Reach neighbour = deltaParent(twin, DELTA_ROW + 32);
assertTrue("the northern channel would cross the neighbouring river", crossesWater(north, neighbour));
List<Reach> kept = distributaries(twin, deltaParent(twin, DELTA_ROW));
assertEquals("a channel that would cross another river is left out", List.of(south), kept);
for (Reach channel : distributaries(twin, neighbour)) {
assertTrue(channel + " turns away from the other river", channel.zs()[channel.xs().length - 1] > DELTA_ROW + 32);
}
assertDeltaClear(twin, List.of());
}
@Test
public void groundReadIsSymmetricAroundThePoint() {
HydrologySettings settings = settings(config -> {
@@ -1677,6 +1751,14 @@ public class ReachShaperTest {
return new PondMask(originX, originZ, FINE, width, depth, bits);
}
private static float minimum(float[] values) {
float minimum = Float.POSITIVE_INFINITY;
for (float value : values) {
minimum = Math.min(minimum, value);
}
return minimum;
}
private static float maximum(float[] values) {
float maximum = 0f;
for (float value : values) {
@@ -1946,6 +2028,174 @@ public class ReachShaperTest {
return shaped.reaches().get(0);
}
private static HydrologySettings deltaSettings(int channels) {
return settings(config -> {
config.getTiers().get(2).setHalfWidth(new KList<>(3D, 5D));
config.getTiers().get(2).getDelta().setChannels(channels);
});
}
private static Reach deltaParent(ShapedNetwork shaped, int row) {
for (Reach reach : shaped.reaches()) {
if (reach.style()[0] != ReachStyle.MOUTH && Math.abs(reach.zs()[0] - row) < 1f) {
return reach;
}
}
throw new AssertionError("no river along z=" + row + " in " + shaped.reaches());
}
private static List<Reach> distributaries(ShapedNetwork shaped, Reach parent) {
List<Reach> fan = new ArrayList<>();
for (Reach reach : shaped.reaches()) {
if (reach.style()[0] == ReachStyle.MOUTH && (parent == null || branchesFrom(reach, parent))) {
fan.add(reach);
}
}
return fan;
}
private static boolean branchesFrom(Reach channel, Reach parent) {
int point = coveringPoint(parent, Math.round(channel.xs()[0]), Math.round(channel.zs()[0]));
return point >= 0 && parent.grade()[point] == SEA_LEVEL;
}
private static void assertDeltaClear(ShapedNetwork shaped, List<Pond> ponds) {
List<Reach> fan = distributaries(shaped, null);
for (Reach channel : fan) {
Reach parent = null;
for (Reach reach : shaped.reaches()) {
if (reach.style()[0] != ReachStyle.MOUTH && branchesFrom(channel, reach)) {
parent = reach;
}
}
assertNotNull(channel + " branches from a river's estuary", parent);
for (Reach other : shaped.reaches()) {
boolean sibling = other != channel && fan.contains(other) && branchesFrom(other, parent)
&& other.xs()[0] == channel.xs()[0] && other.zs()[0] == channel.zs()[0];
if (other == channel || other == parent || sibling) {
continue;
}
assertFalse(channel + " crosses " + other, crossesWater(channel, other));
}
for (Reach sibling : fan) {
if (sibling != channel && sibling.xs()[0] == channel.xs()[0] && sibling.zs()[0] == channel.zs()[0]) {
assertFalse(channel + " and " + sibling + " cross", linesCross(channel, sibling));
}
}
for (Pond pond : ponds) {
assertFalse(channel + " crosses pond " + pond.id(), coversMask(channel, pond.mask()));
}
for (int z = (int) Math.floor(minimum(channel.zs())) - 16; z <= (int) Math.ceil(maximum(channel.zs())) + 16; z++) {
for (int x = (int) Math.floor(minimum(channel.xs())) - 16; x <= (int) Math.ceil(maximum(channel.xs())) + 16; x++) {
int point = coveringPoint(parent, x, z);
assertTrue(channel + " meets its river above the sea at " + x + "," + z,
coveringPoint(channel, x, z) < 0 || point < 0 || parent.grade()[point] == SEA_LEVEL);
}
}
}
}
private static boolean crossesWater(Reach channel, Reach other) {
for (int z = (int) Math.floor(minimum(channel.zs())) - 16; z <= (int) Math.ceil(maximum(channel.zs())) + 16; z++) {
for (int x = (int) Math.floor(minimum(channel.xs())) - 16; x <= (int) Math.ceil(maximum(channel.xs())) + 16; x++) {
if (coveringPoint(channel, x, z) >= 0 && coveringPoint(other, x, z) >= 0) {
return true;
}
}
}
return false;
}
private static boolean coversMask(Reach reach, PondMask mask) {
for (int j = 0; j < mask.depth(); j++) {
for (int i = 0; i < mask.width(); i++) {
if (mask.node(i, j) && coveringPoint(reach, mask.originX() + i * mask.step(), mask.originZ() + j * mask.step()) >= 0) {
return true;
}
}
}
return false;
}
private static boolean linesCross(Reach first, Reach second) {
for (int a = 1; a + 1 < first.xs().length; a++) {
for (int b = 1; b + 1 < second.xs().length; b++) {
if (segmentsCross(first.xs()[a], first.zs()[a], first.xs()[a + 1], first.zs()[a + 1], second.xs()[b], second.zs()[b],
second.xs()[b + 1], second.zs()[b + 1])) {
return true;
}
}
}
return false;
}
private static boolean segmentsCross(double ax, double az, double bx, double bz, double cx, double cz, double dx, double dz) {
double first = turn(ax, az, bx, bz, cx, cz);
double second = turn(ax, az, bx, bz, dx, dz);
double third = turn(cx, cz, dx, dz, ax, az);
double fourth = turn(cx, cz, dx, dz, bx, bz);
return first * second < 0D && third * fourth < 0D;
}
private static double turn(double ax, double az, double bx, double bz, double px, double pz) {
return (bx - ax) * (pz - az) - (bz - az) * (px - ax);
}
private static List<String> ends(List<Reach> fan) {
List<String> ends = new ArrayList<>();
for (Reach channel : fan) {
int last = channel.xs().length - 1;
ends.add(channel.xs()[last] + "," + channel.zs()[last]);
}
return ends;
}
private static double fineNode(float coordinate) {
return Math.floor(coordinate / FINE + 0.5D) * FINE;
}
private static ShapedNetwork deltaCoast(HydrologySettings settings, int originX, int originZ, List<Pond> ponds, int neighbourZ, long seed) {
return deltaCoast(settings, originX, originZ, ponds, neighbourZ, seed, ReachShaperTest::deltaGround);
}
private static ShapedNetwork deltaCoast(HydrologySettings settings, int originX, int originZ, List<Pond> ponds, int neighbourZ, long seed,
DoubleBinaryOperator ground) {
int width = (DELTA_SEA_X + 32 - originX) / CELL + 1;
int depth = (DELTA_ROW + 96 - originZ) / CELL + 1;
DemGrid surface = new DemGrid(originX, originZ, CELL, width, depth);
for (int j = 0; j < depth; j++) {
for (int i = 0; i < width; i++) {
surface.set(i, j, originX + i * CELL >= DELTA_SEA_X ? 30f : 60f);
}
}
int[] receivers = new int[width * depth];
Arrays.fill(receivers, -1);
float[] accumulation = new float[width * depth];
BitSet channels = new BitSet(width * depth);
deltaRow(surface, receivers, accumulation, channels, 0, DELTA_ROW, 20000f);
if (neighbourZ != Integer.MIN_VALUE) {
deltaRow(surface, receivers, accumulation, channels, 0, neighbourZ, 20000f);
}
HeightLattice fine = new HeightLattice(new Terrain(ground), FINE, false, 1 << 16);
return new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, ponds, fine, seed);
}
private static void deltaRow(DemGrid grid, int[] receivers, float[] accumulation, BitSet channels, int fromX, int z, float perCell) {
int j = (z - grid.originZ()) / CELL;
for (int x = fromX; x < DELTA_SEA_X; x += CELL) {
int i = (x - grid.originX()) / CELL;
flow(grid, receivers, accumulation, channels, i, j, i + 1, j, perCell * ((x - fromX) / CELL + 1));
}
}
private static double deltaGround(double x, double z) {
return x < DELTA_COAST_X ? SEA_LEVEL + 0.5D + DELTA_RISE * (DELTA_COAST_X - x) : SEA_LEVEL - 4D;
}
private static double northHill(double x, double z) {
return z > DELTA_HILL_Z && x < DELTA_COAST_X ? SEA_LEVEL + 10D : deltaGround(x, z);
}
private static int trailingMouth(Reach reach) {
int start = reach.style().length;
while (start > 0 && reach.style()[start - 1] == ReachStyle.MOUTH) {
@@ -352,7 +352,7 @@ public class IrisComplexHeightStreamTest {
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
IrisHydrologyMaterials tierMaterials = new IrisHydrologyMaterials();
HydrologyTier tier = new HydrologyTier("river", 0f, 1f, 2f, 1f, 0.4f, 1, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), tierMaterials, "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), tierMaterials, "water", List.of());
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
when(raster.tier(5, 9)).thenReturn(tier);
when(raster.fluid(5, 9)).thenReturn("molten");
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "6caf6bfdfd8b4cc360bf0da070a7636982d23aae13a1cfe14310b8d5f2410f26";
private static final String EXPECTED_SCHEMA_DIGEST = "3e10064463f6935c5ac8fe0558f0bb06483e5b0e116f5bfe6e54d13f2e0877d1";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -82,7 +82,7 @@ public final class WaterScene {
public static HydrologyTier tier(String name, float halfWidth, float depthRatio) {
return new HydrologyTier(name, 0f, halfWidth, halfWidth, 0f, depthRatio, 1, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new HydrologyTier.Delta(0, 35f, 64), new IrisHydrologyMaterials(), "water", List.of());
}
public static Reach line(long id, HydrologyTier tier, int startX, int startZ, int endX, int endZ, IntBinaryOperator grade) {