mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
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:
1 parent
904c889c2f
commit
d3b364fa15
17 files changed
+723
-18
No files matched your search
+29
@@ -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();
|
||||
|
||||
|
||||
+38
-2
@@ -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) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user