Meet river banks at midline

- End a tidal bank halfway to any other water within its band
- Ease it up to that water's own bank height, so the two sides join
- Leave river, pond and lake banks unchanged
This commit is contained in:
Brian Fopiano committed 2026-11-03 19:50:32 -05:00
1 parent f4cd64ee33
commit 8d18e0de7a
3 files changed
+140 -20

No files matched your search

@@ -43,6 +43,7 @@ final class RasterComposer {
private final HydrologyTier[] nearTier = new HydrologyTier[CELLS];
private final ReachGeometry.Lookup brinks;
private final ReachCursor cursor;
private final ReachCursor.Choice other = new ReachCursor.Choice();
private final Map<Long, String> reachFluids = new HashMap<>();
private NaturalHeights naturalHeight;
@@ -165,26 +166,6 @@ final class RasterComposer {
}
private void dry(int cell, int x, int z, int ground, double variation) {
int cut = ground;
int raise = Integer.MIN_VALUE;
double bankEdge = Double.POSITIVE_INFINITY;
ReachCursor.Choice bank = cursor.bank;
if (bank.reach != null) {
HydrologyTier bankTier = bank.reach.tier();
int surface = brinks.head(bank);
bankEdge = bank.distance - bank.halfWidth();
double u = bankEdge / bankTier.bankBand();
if (bankTier.bankStyle() != IrisBankStyle.CLIFF && bankTier.bankStyle() != IrisBankStyle.TERRACED) {
u = BedProfile.position(u, -variation);
}
if (ground >= surface) {
double slope = bank.reach.style()[0] == ReachStyle.TIDAL ? settings.deformation().bankSlope() : coneSlope(steepestToWater(x, z, bank, bankEdge));
double cone = slope * u * bankTier.bankBand();
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, cone, noise(x, z));
} else if (ground >= settings.seaLevel()) {
raise = BankProfile.levee(bankTier.bankStyle(), surface, ground, u, noise(x, z), settings.deformation().maxFill());
}
}
int nearPond = -1;
double pondEdge = Double.POSITIVE_INFINITY;
for (int index = 0; index < features.ponds(); index++) {
@@ -194,6 +175,29 @@ final class RasterComposer {
nearPond = index;
}
}
int cut = ground;
int raise = Integer.MIN_VALUE;
double bankEdge = Double.POSITIVE_INFINITY;
ReachCursor.Choice bank = cursor.bank;
if (bank.reach != null) {
bankEdge = bank.distance - bank.halfWidth();
if (bank.reach.style()[0] == ReachStyle.TIDAL) {
cut = tidalBank(bank, x, z, ground, variation, bankEdge, pondEdge);
} else {
HydrologyTier bankTier = bank.reach.tier();
int surface = brinks.head(bank);
double u = bankEdge / bankTier.bankBand();
if (bankTier.bankStyle() != IrisBankStyle.CLIFF && bankTier.bankStyle() != IrisBankStyle.TERRACED) {
u = BedProfile.position(u, -variation);
}
if (ground >= surface) {
double cone = coneSlope(steepestToWater(x, z, bank, bankEdge)) * u * bankTier.bankBand();
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, cone, noise(x, z));
} else if (ground >= settings.seaLevel()) {
raise = BankProfile.levee(bankTier.bankStyle(), surface, ground, u, noise(x, z), settings.deformation().maxFill());
}
}
}
int taper = settings.ponds().shore().taper();
boolean tapered = nearPond >= 0 && pondEdge <= taper;
if (tapered && ground > WaterHeads.standing(features.pond(nearPond).level(), settings.seaLevel())) {
@@ -208,6 +212,47 @@ final class RasterComposer {
nearestWater(cell, nearPond, pondEdge);
}
private int tidalBank(ReachCursor.Choice bank, int x, int z, int ground, double variation, double bankEdge, double pondEdge) {
HydrologyTier tidal = bank.reach.tier();
int surface = brinks.head(bank);
if (ground < surface) {
return ground;
}
double band = tidal.bankBand();
features.segments().nearestOther(x, z, bank.reach.id(), band, other);
double otherEdge = other.reach == null ? Double.POSITIVE_INFINITY : other.distance - other.halfWidth();
int meet = ground;
if (other.reach != null && otherEdge <= other.reach.tier().bankBand()) {
meet = Math.min(meet, otherBank(x, z, ground, variation, otherEdge));
}
double nearest = Math.min(otherEdge, pondEdge);
double reach = nearest == Double.POSITIVE_INFINITY ? band : Math.min(band, 0.5D * (bankEdge + nearest));
if (bankEdge >= reach) {
return Math.max(surface, meet);
}
double u = bankEdge / reach;
if (tidal.bankStyle() != IrisBankStyle.CLIFF && tidal.bankStyle() != IrisBankStyle.TERRACED) {
u = BedProfile.position(u, -variation);
}
double cone = settings.deformation().bankSlope() * u * reach;
return Math.min(ground, BankProfile.cut(tidal.bankStyle(), surface, Math.max(surface, meet), u, cone, noise(x, z)));
}
private int otherBank(int x, int z, int ground, double variation, double otherEdge) {
HydrologyTier otherTier = other.reach.tier();
int surface = brinks.head(other);
double u = otherEdge / otherTier.bankBand();
if (otherTier.bankStyle() != IrisBankStyle.CLIFF && otherTier.bankStyle() != IrisBankStyle.TERRACED) {
u = BedProfile.position(u, -variation);
}
if (ground < surface) {
return ground;
}
boolean tidal = other.reach.style()[0] == ReachStyle.TIDAL;
double slope = tidal ? settings.deformation().bankSlope() : coneSlope(steepestToWater(x, z, other, otherEdge));
return BankProfile.cut(otherTier.bankStyle(), surface, ground, u, slope * u * otherTier.bankBand(), noise(x, z));
}
private void nearestWater(int cell, int nearPond, double pondEdge) {
double best = Double.POSITIVE_INFINITY;
if (cursor.edge.reach != null) {
@@ -141,6 +141,33 @@ final class ReachSegments {
cursor.resolveChannel();
}
void nearestOther(double x, double z, long excluded, double reach, ReachCursor.Choice out) {
if (!sealed) {
seal();
}
out.reset();
double best = Double.POSITIVE_INFINITY;
for (int index = 0; index < size; index++) {
if (reaches[index].id() == excluded || beyond(x, z, Math.min(startX[index], endX[index]), Math.min(startZ[index], endZ[index]),
Math.max(startX[index], endX[index]), Math.max(startZ[index], endZ[index]), radius[index] + reach)) {
continue;
}
double ax = startX[index];
double az = startZ[index];
double dx = endX[index] - ax;
double dz = endZ[index] - 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 edge = distance - (startWidth[index] + t * (endWidth[index] - startWidth[index]));
if (edge < best && edge <= reach) {
best = edge;
out.reset();
out.offer(reaches[index], segments[index], index, t, distance);
}
}
}
private int coveredCell(double x, double z) {
if (coverStarts == null) {
return -1;