Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

map: railways keep their width beside one-sided hills (fixes #252) (#261)

Eyal Golanbdb5cd20a2bd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d59a93cc7..914173d27 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -151,6 +151,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
It decodes to the same bytes, so the terrain is unchanged (#44).
### Fixed
+- Railways keep their width outside the gorges: a rail band narrows only where the ground leaves its tolerance on both
+ sides (a gorge floor, a gorge side, a ridge), not for one hill or one drop beside the line. The Jaffa–Jerusalem line
+ keeps 94.9% of its width outside the Sorek (87.4% before) and the Jezreel Valley line 92.1% outside its gorges (82.8%).
+ Map only; the goldens do not move (#252).
- Railways and roads on the map no longer zigzag on straight stretches (the traced lines are smoothed, keeping real
bends), and the Jaffa–Jerusalem railway no longer climbs the Sorek gorge's walls: the track keeps its own grade,
flat across, narrows smoothly to the gorge floor and stays clear of the ground under its rails (#212, #213).
diff --git a/docs/routes.md b/docs/routes.md
index 669f96e1b..e2f817dbe 100644
--- a/docs/routes.md
+++ b/docs/routes.md
@@ -155,8 +155,16 @@ measurement in `docs/units.md`:
- **The old rule.** Each vertex took the highest ground around itself, so in the Sorek gorge the 680 m band rode up
both walls and its rails and sleepers warped.
- **Width.** It narrows to the gorge floor and ramps: `RailHalfWidths`.
- - Per section, `FlatHalfWidth` cuts the band back symmetrically to where the ground on both sides is neither more
- than 40 m above it nor more than 60 m below it, down to 25% of the width.
+ - Per section, `FlatHalfWidth` looks for ground more than 40 m above the band or more than 60 m below it, out to
+ the band's edge on each side.
+ - Where it finds such ground on both sides (a gorge floor, a gorge side, a ridge), it cuts the band back
+ symmetrically to the last sample before the first one, down to 25% of the width.
+ - Where only one side has it (one hill or one drop beside the line), the band keeps its full width. That edge reads
+ as a cutting or an embankment (#252).
+ - Cutting both sides for it had narrowed the foothill lines: on main (f974c9f), 85% of the narrowed
+ Jaffa–Jerusalem sections and 93% of the Jezreel Valley ones failed on one side only. That covers the Latrun
+ foothills, the Carmel foot by Haifa and the Jordan terraces.
+ - The smoothing below cost only 5–7 points.
- An edge under a little higher ground reads as a cutting.
- A stricter rule (any rise over the clearance) also thinned the band on the rolling Shephelah foothills.
- Then it takes the minimum over two sections each way.
@@ -174,6 +182,18 @@ measurement in `docs/units.md`:
- `TheRailClearsTheGroundUnderItsRailsAndRampsItsWidth`: on every railway, no ground over the rails, no width
jump over 10%, and the edges' float bounded (p99 85 m, bound 100 m). It fails on 005e60e: 67 sections with ground
over the rails, 819 width jumps and an edge float p99 of 107 m.
+ - `EveryRailwayKeepsItsWidthOutsideTheGorges` (#252): every line keeps at least 90% of its width, on average, outside
+ the gorges (sections where the ground leaves the tolerance on both sides), and its mean width stays at its pinned
+ floor. The edge float p99 stays 86 m; the Sorek numbers do not move.
+
+ | Line | Mean width, main (f974c9f) | Now | Outside the gorges, main | Now | Sections in gorges |
+ |---|---|---|---|---|---|
+ | Jaffa–Jerusalem | 70.7% | 76.2% | 87.4% | 94.9% | 178 of 665 (the Sorek) |
+ | Main line south | 98.9% | 100.0% | 98.9% | 100.0% | 0 of 856 |
+ | Eastern Railway | 99.3% | 100.0% | 99.3% | 100.0% | 0 of 525 |
+ | Hadera–Haifa | 92.0% | 97.4% | 93.5% | 99.0% | 9 of 419 |
+ | Haifa–Beirut | 95.1% | 95.5% | 97.0% | 97.4% | 9 of 326 |
+ | Jezreel Valley | 74.5% | 82.5% | 82.8% | 92.1% | 113 of 775 (the Beisan–Jordan descent, the Yarmuk, the Carmel foot) |
- u runs across the ribbon and v along it, in metres.
**The shader** (`Statecraft/Route`). It is transparent and has no new keywords; the shadow keywords are the terrain's.
diff --git a/unity/Assets/Editor/RouteCapture.cs b/unity/Assets/Editor/RouteCapture.cs
index 642210d34..3f259b024 100644
--- a/unity/Assets/Editor/RouteCapture.cs
+++ b/unity/Assets/Editor/RouteCapture.cs
@@ -13,7 +13,7 @@ using UnityEngine;
public static class RouteCapture
{
/// <summary>(name, lon, lat, distance m, yaw): the still train east of Jaffa, Lydda junction, Latrun to Bab al-Wad with
- /// the Burma Road, the Atlit coast line, the Sorek gorge and the Jericho road.</summary>
+ /// the Burma Road, the Atlit coast line, the Sorek gorge, the Jericho road and the Jezreel Valley line's Jordan end.</summary>
static readonly (string name, double lon, double lat, float distance, float yaw)[] Views =
{
("train", 34.83, 32.01, 16000f, 10f),
@@ -22,6 +22,7 @@ public static class RouteCapture
("atlit", 34.95, 32.70, 14000f, 0f), // the Hadera–Haifa line along the Atlit coast (review B14)
("sorek", 35.07, 31.755, 10000f, 0f), // the Jaffa–Jerusalem line in the Sorek gorge (review B15)
("jericho", 35.36, 31.80, 14000f, 0f), // the Jerusalem–Jericho road's descent (review A-I1)
+ ("jezreel", 35.55, 32.60, 16000f, 0f), // the Jezreel Valley line's Jordan end, Beisan to Gesher (#252)
};
public static void Close()
diff --git a/unity/Assets/Scripts/Map/Routes/RouteLayer.cs b/unity/Assets/Scripts/Map/Routes/RouteLayer.cs
index 2990679f5..9d99864c0 100644
--- a/unity/Assets/Scripts/Map/Routes/RouteLayer.cs
+++ b/unity/Assets/Scripts/Map/Routes/RouteLayer.cs
@@ -206,24 +206,30 @@ namespace Statecraft.Game.Map.Routes
/// <summary>Samples per side when a cross-section looks for where it must stop.</summary>
const int NarrowSamples = 8;
- /// <summary>The half-width (m) a cross-section at <paramref name="q"/> (flat at <paramref name="y"/>) may span: the full
- /// <paramref name="half"/>, cut back symmetrically (so the rails stay centred) to the last sample where the ground on
- /// both sides is neither more than <see cref="RiseToleranceM"/> above the section nor more than <see cref="FallToleranceM"/> below it, but
- /// never under <see cref="MinWidthShare"/> of the width. Railways only (RailHalfWidths smooths it along the line):
- /// in the Sorek gorge the band keeps to the floor instead of riding up the walls (review B15); on the plains nothing
- /// changes.</summary>
+ /// <summary>The half-width (m) a cross-section at <paramref name="q"/> (flat at <paramref name="y"/>) may span. A sample
+ /// leaves the tolerance where the ground is more than <see cref="RiseToleranceM"/> above the section or more than
+ /// <see cref="FallToleranceM"/> below it. Where the ground leaves it on both sides within the half-width (a gorge floor, a
+ /// gorge side, a ridge), the section is cut back symmetrically (so the rails stay centred) to the last sample before
+ /// the first one that leaves it, on either side, but never under <see cref="MinWidthShare"/> of the width. Where it leaves
+ /// it on one side only (one hill or one drop beside the line), the full <paramref name="half"/>: that edge reads as a
+ /// cutting or an embankment, and cutting both sides for it narrowed the foothill lines to about 70% (#252). Railways
+ /// only (RailHalfWidths smooths it along the line): in the Sorek gorge the band keeps to the floor instead of riding up
+ /// the walls (review B15); on the plains nothing changes.</summary>
public static float FlatHalfWidth(TerrainData data, Vector3 origin, Vector2 q, Vector2 side, float y, float half)
{
- float allowed = half;
- for (int k = 1; k <= NarrowSamples; k++)
+ int left = 0, right = 0; // the first sample out of tolerance each side
+ for (int k = 1; k <= NarrowSamples && (left == 0 || right == 0); k++)
{
float o = half * k / NarrowSamples;
- float gl = Ground(data, origin, q - side * o), gr = Ground(data, origin, q + side * o);
- if (gl > y + RiseToleranceM || gr > y + RiseToleranceM || gl < y - FallToleranceM || gr < y - FallToleranceM) { allowed = half * (k - 1) / NarrowSamples; break; }
+ if (left == 0 && OutOfTolerance(Ground(data, origin, q - side * o), y)) left = k;
+ if (right == 0 && OutOfTolerance(Ground(data, origin, q + side * o), y)) right = k;
}
- return Mathf.Max(allowed, half * MinWidthShare);
+ if (left == 0 || right == 0) return half;
+ return Mathf.Max(half * (Math.Min(left, right) - 1) / NarrowSamples, half * MinWidthShare);
}
+ static bool OutOfTolerance(float ground, float y) => ground > y + RiseToleranceM || ground < y - FallToleranceM;
+
/// <summary>The ground height (world y) under (x, z), clamped to the terrain.</summary>
public static float Ground(TerrainData data, Vector3 origin, Vector2 p) =>
origin.y + data.GetInterpolatedHeight(Mathf.Clamp01((p.x - origin.x) / data.size.x), Mathf.Clamp01((p.y - origin.z) / data.size.z));
diff --git a/unity/Assets/Tests/EditMode/RouteTests.cs b/unity/Assets/Tests/EditMode/RouteTests.cs
index 1da24cce8..b38ea6023 100644
--- a/unity/Assets/Tests/EditMode/RouteTests.cs
+++ b/unity/Assets/Tests/EditMode/RouteTests.cs
@@ -101,7 +101,7 @@ public class RouteTests
using var sha = System.Security.Cryptography.SHA256.Create();
return string.Concat(sha.ComputeHash(bytes.ToArray()).Select(b => b.ToString("x2")));
}
- const string RailMeshHash = "f54a7a63ead7bed5db05f09aa2284ba7251573fb95b8a6e1e701e3cc736061b1";
+ const string RailMeshHash = "5363889121beb4aae19525a062cb108ff35394ba04e397b42f75a03a8e82439d"; // #252: full width where only one side leaves the tolerance
[Test]
public void TheMapBuildsRibbonsOnTheGroundAndTheTogglesHideThem()
@@ -278,6 +278,66 @@ public class RouteTests
// is 25% width). 005e60e: 67 sections with ground over the rails, 819 width jumps, edge float p99 107 m.
const float EdgeFloatP99BoundM = 100f;
+ /// <summary>#252: a railway keeps its width outside the gorges. A section is in a gorge where, within the band's
+ /// half-width, the ground leaves the tolerance on both sides (a wall or a drop each side: a gorge floor, a gorge side,
+ /// a ridge); one hill or one drop beside the line is not a gorge. Every line keeps at least 90% of its width, on
+ /// average, outside the gorges, and its mean width over all its sections stays at or above the pinned floor.</summary>
+ [Test]
+ public void EveryRailwayKeepsItsWidthOutsideTheGorges()
+ {
+ var map = BuildMap();
+ try
+ {
+ var data = map.Terrain.terrainData; var origin = map.Terrain.transform.position;
+ var failures = new List<string>();
+ foreach (var r in RoutePaths.Parse(CommittedYaml, Bounds).Where(r => r.Kind == RoutePaths.Rail))
+ {
+ var mesh = RouteLayer.Ribbon(new[] { (RouteLayer.World(map.Frame, r), RouteLayer.RailWidthM) }, data, origin, r.Id, railGrade: true);
+ try
+ {
+ var v = mesh.vertices; int n = RouteLayer.Across; float half = RouteLayer.RailWidthM / 2f;
+ var all = new List<float>(); var open = new List<float>(); int gorge = 0;
+ for (int i = 0; i + n <= v.Length; i += n)
+ {
+ var left = new Vector2(v[i].x, v[i].z); var right = new Vector2(v[i + n - 1].x, v[i + n - 1].z);
+ var cq = (left + right) / 2f; float share = (right - left).magnitude / RouteLayer.RailWidthM;
+ var side = (right - left).normalized; var t = new Vector2(-side.y, side.x);
+ float y = RouteLayer.GradeHeight(data, origin, cq, t);
+ bool Leaves(float s)
+ {
+ for (int k = 1; k <= 8; k++)
+ {
+ float g = RouteLayer.Ground(data, origin, cq + side * (s * half * k / 8f));
+ if (g > y + RouteLayer.RiseToleranceM || g < y - RouteLayer.FallToleranceM) return true;
+ }
+ return false;
+ }
+ all.Add(share);
+ if (Leaves(-1f) && Leaves(1f)) gorge++; else open.Add(share);
+ }
+ float mean = all.Average(), outside = open.Count > 0 ? open.Average() : 1f;
+ float floor = MeanWidthFloor.TryGetValue(r.Id, out var f) ? f : 0.9f;
+ TestContext.WriteLine($"{r.Id}: {all.Count} sections, {gorge} in gorges; mean width {mean:P1} (floor {floor:P0}), outside the gorges {outside:P1}");
+ if (outside < 0.9f) failures.Add($"{r.Id} keeps {outside:P1} of its width outside the gorges");
+ if (mean < floor) failures.Add($"{r.Id} keeps {mean:P1} of its width, under its floor {floor:P0}");
+ }
+ finally { Object.DestroyImmediate(mesh); }
+ }
+ Assert.IsEmpty(failures, string.Join("; ", failures));
+ }
+ finally { Object.DestroyImmediate(map.gameObject); }
+ }
+ /// <summary>Each line's pinned mean width (share of the full width, all sections, gorges included). Lines without an
+ /// entry need 90%. Measured 2026-10-12 (#252), main (f974c9f) in brackets: Jaffa–Jerusalem 76.2% (70.7%; 178 of 665
+ /// sections in gorges: the Sorek), main line south 100.0% (98.9%), Eastern Railway 100.0% (99.3%), Hadera–Haifa 97.4%
+ /// (92.0%), Haifa–Beirut 95.5% (95.1%), Jezreel Valley 82.5% (74.5%; 113 of 775 in gorges: chiefly the Beisan–Jordan
+ /// descent and the Yarmuk, and about 20 under the Carmel by Haifa). Outside the gorges main kept 87.4% on Jaffa–Jerusalem and 82.8% on the Jezreel line, so this fails there.</summary>
+ static readonly Dictionary<string, float> MeanWidthFloor = new Dictionary<string, float>
+ {
+ ["jaffa_jerusalem_railway"] = 0.76f, ["kantara_main_line_south"] = 0.99f, ["eastern_railway"] = 0.99f,
+ ["hadera_haifa_railway"] = 0.97f, ["haifa_beirut_railway"] = 0.95f, ["jezreel_valley_railway"] = 0.82f,
+ };
+
/// <summary>C1: the Burma Road shows only from its completion on 14 June 1948; the start (15 May 1948) does not have
/// it, every other route is there from the start.</summary>
[Test]