A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: the 1948 roads stop at the Old City's gates (refs #319) (#698)
Eyal Golan4a683796c164
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 19896e1c3..a94f2b966 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -33,6 +33,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBKnesset's history pages cover every value); the Provisional Government keeps its two named Wikipedia lines forthe coalition, the State Council keeps one named Wikipedia line for the seat distribution, and the ThirdGovernment keeps its named he.wiki lines. No values changed.+- The 1948 roads stop at the walls of Jerusalem's symbolic Old City instead of running inside them (refs #319). The map+ cuts the Jaffa, Hebron, Nablus and Jericho roads at the 4 km square's wall line, where the walls leave each a gate;+ the traced lines, which meet just outside the real walls by New Gate, are unchanged. The Jaffa–Jerusalem railway now+ ends at the walls too (owner: "Cut it at the walls"); its station stands outside the real walls. The route ribbons are+ re-baked.+ Map only: no golden and no content hash moves.- The Treasury is now shown as Money, כסף in Hebrew, on the top bar, the Budget screen and in the causes (refs #382,R-MONEY-001; spec §1.2, owner, 15 October 2026, Q-MONEY-4 and Q-HUD-3). Debt and foreign currency stay in the sim(D-C3). No upkeep yet: per Q-MONEY-2 it waits for Phase 3. No golden moves; the content hash does (the name is indiff --git a/docs/routes.md b/docs/routes.mdindex ef9794960..522bccaa6 100644--- a/docs/routes.md+++ b/docs/routes.md@@ -146,6 +146,18 @@ measurement in `docs/units.md`:| Burma Road | (not in the promo) | 200 m || Train (six cars) | about 250 px, about 8.8 km | 8.8 km: locomotive, tender and four coaches at 80x real length and 1.5x stockier across (at a uniform 65x the first checkpoint drew a thin dark line) |+**Jerusalem's Old City** (#319). The kits draw the Old City as a walled square 4 km across+(`SettlementKits.OldCityWalls`), about 4 times the real one. The four roads that start there in the traced data+(Jaffa–Jerusalem, Hebron, Nablus and Jericho) meet at a point about 60 m west of New Gate, outside the real walls, and+none crosses the real walled city, but near the city they fall inside the drawn square. The data keeps the real lines; the map cuts them instead (`RouteLayer.Drawn`):+- each road's run inside the square is cut off at the wall line, where the walls leave a gate for it;+- only the ribbons are cut; the corridors the kits and the units keep clear of stay on the traced lines, so no building+ or unit moves, and inside the walls the roads' clear ways read as the streets from the gates;+- the Jaffa–Jerusalem railway is cut the same way (owner, 16 October 2026: "Cut it at the walls"). Its station was outside+ the real walls, south-west of Jaffa Gate, but falls inside the drawn square, so the railway ends at the south wall;+- only a line's ends are cut, so a road or railway traced through the square would fail+ `RouteTests.TheRoadsAndTheRailwayStopAtTheOldCityWalls` and `test_no_road_or_railway_runs_inside_the_old_city_walls`.+**The mesh** (`RouteLayer.Ribbon`).- A cross-section every 120 m, square to the line's direction averaged over two steps each way.- Five vertices across each section.diff --git a/docs/visual-v1.md b/docs/visual-v1.mdindex ee1f6609d..63c4ec2e3 100644--- a/docs/visual-v1.md+++ b/docs/visual-v1.md@@ -2254,6 +2254,8 @@ blocks, village houses, red-roofed villas), Jaffa 6 → 7, Tel Aviv 8 → 7.- **Jerusalem's Old City is symbolic and squeezed by the roads.**- It is 4 km across, about 4 times the real one. The drawn 1948 roads (300 m ribbons) meet by Jaffa Gate and loopround the north and east, so at any readable size they cross inside the square, through gaps in the walls.+ Since #319 the map cuts each road and the railway at the walls (`docs/routes.md`, "Jerusalem's Old City"), so none+ runs inside them. The Haram's shape below, and the gates, are still as round 2 placed them.- Only one place in its south-east quadrant fits a platform clear of every route: 1.3 x 1.1 km, wider than long. Al-Aqsatherefore stands in its south-east corner, not across its south end.- The citadel is moved east off the drawn Hebron road.diff --git a/tools/tests/test_route_ribbon_bake.py b/tools/tests/test_route_ribbon_bake.pyindex beed077a6..69d36d821 100644--- a/tools/tests/test_route_ribbon_bake.py+++ b/tools/tests/test_route_ribbon_bake.py@@ -13,11 +13,13 @@ RouteLayer.Derive and what they call; comments and whitespace left out) covers icolours): an edit to it fails here until the ribbons are re-baked, RouteRibbonFile.Version is bumped and the fingerprintis re-pinned. There is no numpy port: the ribbons drape on Unity's terrain sampling (GetInterpolatedHeight and Normal)."""import codecs+import jsonimport reimport structfrom pathlib import Pathimport numpy as np+import pytestimport yaml12from test_terrain_water_bake import MAP, csharp, fingerprint, heights_check, method, unity_heights@@ -140,14 +142,15 @@ def test_the_check_is_fnv1a():# The fingerprint of the ribbons' C# code (code_fingerprint), and the RouteRibbonFile.Version it was pinned at. Re-pin both# together, only after re-baking (RouteRibbonBake.Bake) with Version bumped.-PINNED_VERSION, PINNED_CODE = 1, "533ef09adbfaf34c768842be54486f6370eb938456b1bcb069bc482dd43dae68"+PINNED_VERSION, PINNED_CODE = 3, "a60ad9441761c59d2dab361e68be89fb710cc59a5edc31e0c051a6ff14367328"def code_fingerprint() -> str:"""The code between the inputs and the bake: RouteRibbonFile.Bake (the terrain and frame it builds), the plans and- their routes' windows, and RouteLayer's geometry. Its constants are left out: the header holds them (FLOATS, INTS)."""+ their routes' windows, RouteLayer's geometry, and the Old City's walls the roads are cut at (#319). Its constants are left out: the header holds them (FLOATS, INTS)."""layer = csharp("Scripts/Map/Routes/RouteLayer.cs")paths = csharp("Scripts/Map/Routes/RoutePaths.cs")+ landmarks = csharp("Scripts/Map/" + LANDMARKS)return fingerprint([method(csharp("Scripts/Map/Routes/RouteRibbonFile.cs"), "public static byte[] Bake("),method(csharp("Scripts/Map/MapBuilder.cs"), "public static Vector3 TerrainSize("),@@ -159,6 +162,12 @@ def code_fingerprint() -> str:method(layer, "public static List<RibbonPlan> Plan("),method(layer, "public static RibbonGeometry Derive("),method(layer, "public static List<Vector2> World("),+ method(layer, "public static List<Vector2> Drawn("),+ method(layer, "public static List<Vector2> TrimEndsInside("),+ method(layer, "static Vector2 Exit("),+ method(landmarks, "public const double OldCityLon"),+ method(landmarks, "public const float OldCityHalfM"),+ method(landmarks, "public static (Vector2 centre, float half) OldCityWalls("),method(layer, "public static (List<Vector2> points, List<float> along) Resample("),method(layer, "public static float GradeHeight("),method(layer, "public static float FlatHalfWidth("),@@ -175,3 +184,67 @@ def test_the_ribbon_code_is_the_one_the_bake_was_made_with():f"the C# that makes the route ribbons changed (version {bake_version()}, fingerprint {code_fingerprint()}): "f"{BAKE.relative_to(ROOT)} is stale until you {REBAKE} after bumping RouteRibbonFile.Version, then re-pin PINNED_VERSION and PINNED_CODE in ""tools/tests/test_route_ribbon_bake.py")+++# Jerusalem's symbolic Old City (SettlementKits.OldCityWalls): its walled square is 4 km across, so the real 1948 roads by+# New Gate and the Jaffa-Jerusalem railway's station, all outside the real walls, fall inside it; the map cuts each road+# and the railway at the walls (RouteLayer.Drawn, #319; the railway on the owner's ruling, "Cut it at the walls").+LANDMARKS = "Kits/SettlementKits.Landmarks.cs"+OLD_CITY_ROADS = ("jaffa_jerusalem_road", "jerusalem_hebron_beersheba_road", "jerusalem_nablus_nazareth_road",+ "jerusalem_jericho_road")+OLD_CITY_RAIL = ("jaffa_jerusalem_railway",)+++def ribbon_vertices_by_route(look: str) -> dict[str, np.ndarray]:+ """Every ribbon vertex (world x, z) of one look in the bake ("Roads": the roads and tracks; "Rail"), by route id."""+ r = Reader(bake_bytes())+ head = read_header(r)+ out: dict[str, list] = {}+ for _ in range(head["meshes"]):+ name = r.text()+ nv, ni, nr = r.take("<3i")+ spans = []+ for _ in range(nr):+ rid = r.text()+ first_v, count_v, _, _ = r.take("<4i")+ spans.append((rid, first_v, count_v))+ xyz = np.array(r.take(f"<{3 * nv}f"), dtype=np.float64).reshape(-1, 3) if nv else np.zeros((0, 3))+ r.take(f"<{5 * nv}f")+ r.take(f"<{ni}i")+ if name.startswith(f"Route{look} "):+ for rid, first, count in spans:+ out.setdefault(rid, []).append(xyz[first:first + count][:, [0, 2]])+ return {k: np.concatenate(v) for k, v in out.items()}+++def old_city_square() -> tuple[np.ndarray, float]:+ """The walls' centre (world x, z) and half side, from the C# constants and the bake's terrain size (GeoFrame.ToWorld)."""+ head = read_header(Reader(bake_bytes()))+ size_x, _, size_z = head["terrain"][:3]+ meta = json.loads((MAP / "heightmap.json").read_text())+ lon, lat = (float(csharp_const(LANDMARKS, n)) for n in ("OldCityLon", "OldCityLat"))+ centre = np.array([(lon - meta["lon0"]) / (meta["lon1"] - meta["lon0"]) * size_x,+ (lat - meta["lat0"]) / (meta["lat1"] - meta["lat0"]) * size_z])+ return centre, float(csharp_const(LANDMARKS, "OldCityHalfM"))++[email protected]("look, width, reaching", [("Roads", "RoadWidthM", OLD_CITY_ROADS), ("Rail", "RailWidthM", OLD_CITY_RAIL)])+def test_no_road_or_railway_runs_inside_the_old_city_walls(look, width, reaching):+ """Each road and the railway end at the walls: no ribbon vertex lies inside the square by more than half the ribbon's+ width (the end section is square to the line, so a line meeting the wall at a slant reaches that far in under the+ wall). Not vacuous: the square is where the real Old City is, and the four roads that start there and the railway+ that ends there each reach to within 300 m of it."""+ centre, half = old_city_square()+ assert 1000 < half < 5000, half+ depth_allowed = float(csharp_const("Routes/RouteLayer.cs", width)) / 2+ ribbons = ribbon_vertices_by_route(look)+ assert ribbons, f"no {look} ribbons in the bake"+ inside, near = {}, {}+ for rid, xz in ribbons.items():+ d = np.abs(xz - centre).max(axis=1) # Chebyshev distance: inside the square where it is under half+ if (deep := int((d < half - depth_allowed).sum())):+ inside[rid] = deep+ near[rid] = int(((d >= half - depth_allowed) & (d < half + 300)).sum())+ assert not inside, f"{look} vertices inside the Old City's walls: {inside}"+ missing = [rid for rid in reaching if near.get(rid, 0) == 0]+ assert not missing, f"these should reach the Old City's walls: {missing}"diff --git a/unity/Assets/Editor/RouteCapture.cs b/unity/Assets/Editor/RouteCapture.csindex 3f259b024..31e14dce3 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, the Jericho road and the Jezreel Valley line's Jordan end.</summary>+ /// the Burma Road, the Atlit coast line, the Sorek gorge, the Jericho road, the Jezreel Valley line's Jordan end and Jerusalem's Old City.</summary>static readonly (string name, double lon, double lat, float distance, float yaw)[] Views ={("train", 34.83, 32.01, 16000f, 10f),@@ -23,6 +23,7 @@ public static class RouteCapture("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)+ ("jerusalem", 35.234, 31.777, 32000f, 0f), // the Old City's walls and the roads that end at them (#319)};public static void Close()diff --git a/unity/Assets/Resources/Routes/RouteRibbons.bytes b/unity/Assets/Resources/Routes/RouteRibbons.bytesindex 919a67da0..3c42b25c3 100644Binary files a/unity/Assets/Resources/Routes/RouteRibbons.bytes and b/unity/Assets/Resources/Routes/RouteRibbons.bytes differdiff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.csindex a877a40eb..a09178948 100644--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs@@ -152,9 +152,15 @@ namespace Statecraft.Game.Map.Kits/// <summary>The Old City's centre (its sourced coordinate) and the half side (m) of its symbolic walled square: 4 km/// across, about 4 times the real Old City (0.9 km^2), so the walls hold the Haram and a quarter of stone houses at/// the kits' scale. In metres, not scaled with the kits: the drawn 1948 roads fix where the Haram can stand- /// (docs/visual-v1.md, "Towns round 2"). Those roads ran round the real walls; at this size they cross inside the- /// square, through gaps in the walls.</summary>- static (Vector2 centre, float half) OldCity(KitGround g) => (World(g, 35.23417, 31.77667), 2000f);+ /// (docs/visual-v1.md, "Towns round 2"). Those roads ran round the real walls; at this size their real lines fall+ /// inside the square, so the map cuts each road at the walls (RouteLayer.Drawn, #319).</summary>+ public const double OldCityLon = 35.23417, OldCityLat = 31.77667;+ public const float OldCityHalfM = 2000f;++ /// <summary>The Old City's walled square in world metres: its centre and half side (<see cref="OldCityHalfM"/>).</summary>+ public static (Vector2 centre, float half) OldCityWalls(GeoFrame f) { var w = f.ToWorld(OldCityLon, OldCityLat, 0); return (new Vector2(w.x, w.z), OldCityHalfM); }++ static (Vector2 centre, float half) OldCity(KitGround g) => OldCityWalls(g.Frame);/// <summary>How far inside the walls the Old City's houses keep (and outside them the new city's).</summary>const float OldCityInset = 220f;@@ -174,8 +180,9 @@ namespace Statecraft.Game.Map.Kitsint n = 0;// The Haram al-Sharif in the city's south-east (in the real city it fills the east side down to the south wall):// its platform, the Dome of the Rock and Al-Aqsa, where the platform keeps clear of the drawn Jericho road. The- // roads leave no room for the real platform's north-south length, so it is wider than long and Al-Aqsa stands in- // its south-east corner rather than across its south end (docs/visual-v1.md, "Towns round 2").+ // roads left no room for the real platform's north-south length, so it is wider than long and Al-Aqsa stands in+ // its south-east corner rather than across its south end (docs/visual-v1.md, "Towns round 2"). Since #319 the+ // roads stop at the walls; reshaping the platform is the rest of that issue.float pw = 1300f, pl = 1100f;var pc = oc + new Vector2(350f, -1200f);var paving = C(0.86f, 0.82f, 0.72f);diff --git a/unity/Assets/Scripts/Map/Routes/RouteLayer.cs b/unity/Assets/Scripts/Map/Routes/RouteLayer.csindex 8e0bb8faf..0d8b151be 100644--- a/unity/Assets/Scripts/Map/Routes/RouteLayer.cs+++ b/unity/Assets/Scripts/Map/Routes/RouteLayer.cs@@ -82,7 +82,7 @@ namespace Statecraft.Game.Map.Routes/// lot or crown still keeps about 130 m from the visible dirt.</summary>public const float RoadCorridorMarginM = 40f;- /// <summary>Every route's line (world x, z) with the half-width kits must keep clear of: half the drawn width plus+ /// <summary>Every route's traced line (world x, z; <see cref="World"/>, not cut as <see cref="Drawn"/> is) with the half-width kits must keep clear of: half the drawn width plus/// <see cref="CorridorMarginM"/> (<see cref="RoadCorridorMarginM"/> for roads). All routes, whatever their window: the/// kits are built once, not per date, so a route that appears later (the Burma Road) has its corridor from the start.</summary>public static List<(List<Vector2> line, float halfWidth)> Corridors(GeoFrame frame, IEnumerable<RoutePath> routes) =>@@ -126,7 +126,7 @@ namespace Statecraft.Game.Map.Routes/// <summary>A plan's ribbon, derived from the terrain (what the bake stores). A change to it or to what it calls/// (World, Geometry and their helpers) needs a re-bake and a bump of RouteRibbonFile.Version (see Plan).</summary>public static RibbonGeometry Derive(RibbonPlan plan, GeoFrame frame, TerrainData data, Vector3 origin) =>- Geometry(plan.Routes.Select(r => (r.Id, World(frame, r), WidthOf(r.Kind))), data, origin, plan.RailGrade);+ Geometry(plan.Routes.Select(r => (r.Id, Drawn(frame, r), WidthOf(r.Kind))), data, origin, plan.RailGrade);/// <summary>Builds the routes under <paramref name="terrain"/> (so a map rebuild destroys them): one group per display/// window (its rail and road ribbons), shown as at <paramref name="date"/>, and, when <paramref name="train"/> is not@@ -224,6 +224,50 @@ namespace Statecraft.Game.Map.Routesreturn w;}+ /// <summary>A route's line as the map draws its ribbon: <see cref="World"/>, with a road's or a railway's ends+ /// cut at the walls of Jerusalem's symbolic Old City (#319). The walled square (SettlementKits.OldCityWalls) is 4 km+ /// across, about 4 times the real Old City, so the real 1948 roads that start outside the real walls, by New Gate and+ /// Jaffa Gate, and the Jaffa-Jerusalem railway's station, also outside them, fall inside it. Cut there, each line+ /// ends on the wall line, where the walls leave it a gap (the railway on the owner's ruling, "Cut it at the walls"),+ /// and the traced data keeps the real lines. Only a line's ends are cut: one that ran through the square would keep+ /// its middle, and RouteTests.TheRoadsAndTheRailwayStopAtTheOldCityWalls fails on it. Tracks are not cut (none comes+ /// near). The corridors (<see cref="Corridors"/>) keep the traced lines, so the kits and the units stand where+ /// they did: inside the walls the roads' clear ways read as the streets from the gates.</summary>+ public static List<Vector2> Drawn(GeoFrame frame, RoutePath route)+ {+ var line = World(frame, route);+ if (route.Kind == RoutePaths.Track) return line;+ var (centre, half) = Kits.SettlementKits.OldCityWalls(frame);+ return TrimEndsInside(line, centre, half);+ }++ /// <summary><paramref name="line"/> without its leading and trailing runs inside the square (centre+ /// <paramref name="c"/>, half side <paramref name="half"/>), each cut where it crosses the square's edge. A line wholly+ /// inside comes back empty, one wholly outside unchanged.</summary>+ public static List<Vector2> TrimEndsInside(List<Vector2> line, Vector2 c, float half)+ {+ bool Inside(Vector2 p) => Mathf.Abs(p.x - c.x) < half && Mathf.Abs(p.y - c.y) < half;+ int first = line.FindIndex(p => !Inside(p)), last = line.FindLastIndex(p => !Inside(p));+ if (first < 0) return new List<Vector2>();+ if (first == 0 && last == line.Count - 1) return line;+ var cut = new List<Vector2>(last - first + 3);+ void Add(Vector2 q) { if (cut.Count == 0 || (q - cut[cut.Count - 1]).sqrMagnitude > 1e-4f) cut.Add(q); }+ if (first > 0) Add(Exit(line[first - 1], line[first], c, half));+ for (int i = first; i <= last; i++) Add(line[i]);+ if (last < line.Count - 1) Add(Exit(line[last + 1], line[last], c, half));+ return cut;+ }++ /// <summary>Where the segment from <paramref name="a"/> (inside the square) to <paramref name="b"/> (outside) crosses+ /// its edge.</summary>+ static Vector2 Exit(Vector2 a, Vector2 b, Vector2 c, float half)+ {+ var d = b - a; float t = 1f;+ if (d.x != 0f) t = Mathf.Min(t, ((d.x > 0f ? c.x + half : c.x - half) - a.x) / d.x);+ if (d.y != 0f) t = Mathf.Min(t, ((d.y > 0f ? c.y + half : c.y - half) - a.y) / d.y);+ return a + d * Mathf.Max(0f, t);+ }+/// <summary>Points every <paramref name="step"/> metres along a polyline, its last point included, and the/// distance along it of each.</summary>public static (List<Vector2> points, List<float> along) Resample(IReadOnlyList<Vector2> line, float step)diff --git a/unity/Assets/Scripts/Map/Routes/RouteRibbonFile.cs b/unity/Assets/Scripts/Map/Routes/RouteRibbonFile.csindex 0941c2bf4..8d591f8b0 100644--- a/unity/Assets/Scripts/Map/Routes/RouteRibbonFile.cs+++ b/unity/Assets/Scripts/Map/Routes/RouteRibbonFile.cs@@ -63,7 +63,7 @@ namespace Statecraft.Game.Map.Routes/// <summary>Bump it when RouteLayer.Geometry's rule changes (the constants are checked on their own), so CI fails a/// bake made by the old rule. tools/tests/test_route_ribbon_bake.py pins it with a fingerprint of that code/// (RouteLayer.Plan, Derive and what they call, and Bake below) and fails on an edit until both are re-pinned.</summary>- public const int Version = 1;+ public const int Version = 3; // 2: roads cut at the Old City's walls (RouteLayer.Drawn, #319); 3: the railway tooconst int Magic = 0x31524353; // "SCR1"/// <summary>What the ribbons were made from, as the map read it.</summary>diff --git a/unity/Assets/Tests/EditMode/RouteTests.cs b/unity/Assets/Tests/EditMode/RouteTests.csindex 1a4ce77ba..a3b55ee5f 100644--- a/unity/Assets/Tests/EditMode/RouteTests.cs+++ b/unity/Assets/Tests/EditMode/RouteTests.cs@@ -101,7 +101,7 @@ public class RouteTestsusing var sha = System.Security.Cryptography.SHA256.Create();return string.Concat(sha.ComputeHash(bytes.ToArray()).Select(b => b.ToString("x2")));}- const string RailMeshHash = "5363889121beb4aae19525a062cb108ff35394ba04e397b42f75a03a8e82439d"; // #252: full width where only one side leaves the tolerance+ const string RailMeshHash = "e6b1710041c05f9ce18d1591e5173c003b933308e9cb84fa807e23b015f16fbd"; // #252: full width where only one side leaves the tolerance; #319: cut at the Old City's walls[Test]public void TheMapBuildsRibbonsOnTheGroundAndTheTogglesHideThem()@@ -126,7 +126,7 @@ public class RouteTests// clears the ground under it by the clearance, and lies on the terrain.var routes = RoutePaths.Parse(CommittedYaml, Bounds);var data = map.Terrain.terrainData; var origin = map.Terrain.transform.position;- var check = RouteLayer.Ribbon(routes.Where(r => r.Kind == RoutePaths.Rail).Select(r => (RouteLayer.World(map.Frame, r), RouteLayer.RailWidthM)), data, origin, "check", railGrade: true);+ var check = RouteLayer.Ribbon(routes.Where(r => r.Kind == RoutePaths.Rail).Select(r => (RouteLayer.Drawn(map.Frame, r), RouteLayer.RailWidthM)), data, origin, "check", railGrade: true);try{Assert.AreEqual(railVerts, check.vertexCount, "the same data gives the same vertices");@@ -136,7 +136,7 @@ public class RouteTests}// Roads keep main's drape: every vertex clears the ground under it by the clearance (the railways' clearance// under their rails is TheRailClearsTheGroundUnderItsRailsAndRampsItsWidth).- var roadCheck = RouteLayer.Ribbon(routes.Where(r => r.Kind != RoutePaths.Rail).Select(r => (RouteLayer.World(map.Frame, r), RouteLayer.WidthOf(r.Kind))), data, origin, "roads");+ var roadCheck = RouteLayer.Ribbon(routes.Where(r => r.Kind != RoutePaths.Rail).Select(r => (RouteLayer.Drawn(map.Frame, r), RouteLayer.WidthOf(r.Kind))), data, origin, "roads");Assert.AreEqual(roadVerts, roadCheck.vertexCount);foreach (var v in roadCheck.vertices)Assert.GreaterOrEqual(v.y - RouteLayer.Ground(data, origin, new Vector2(v.x, v.z)), RouteLayer.ClearanceM - 0.01f);@@ -454,6 +454,77 @@ public class RouteTestsfinally { Object.DestroyImmediate(map.gameObject); }}+ /// <summary>RouteLayer.TrimEndsInside, on hand-made lines (no map): an end inside the square is cut exactly on the wall+ /// line, nothing that is left lies inside, and only the ends are cut (#319 review). The railway case uses its real+ /// numbers, in metres from the square's centre: its first point inside is only 92 m deep, well under the 340 m the+ /// ribbon test allows, so this test is what pins the crossing.</summary>+ [Test]+ public void TrimEndsInsideCutsEachEndExactlyOnTheWall()+ {+ var c = new Vector2(98264f, 257260f); const float half = 2000f, eps = 0.05f; // float32 at these world coordinates has a 0.03 m step+ List<Vector2> Line(params float[] xy) { var l = new List<Vector2>(); for (int i = 0; i < xy.Length; i += 2) l.Add(c + new Vector2(xy[i], xy[i + 1])); return l; }+ float Cheb(Vector2 p) => Mathf.Max(Mathf.Abs(p.x - c.x), Mathf.Abs(p.y - c.y));+ void NothingInside(List<Vector2> l, string what) { foreach (var p in l) Assert.GreaterOrEqual(Cheb(p), half - eps, $"{what}: {p - c} is inside"); }++ // The railway: in through the south wall, its last two points inside (92 m and 1094 m deep).+ var rail = RouteLayer.TrimEndsInside(Line(-2227f, -2570f, -1743f, -1908f, -904f, -1094f), c, half);+ Assert.AreEqual(2, rail.Count, "the railway keeps its outside point and gains the crossing");+ var end = rail[rail.Count - 1] - c;+ Assert.AreEqual(-2000f, end.y, eps, "the railway ends on the south wall");+ Assert.AreEqual(-1743f + (-484f) * (92f / 662f), end.x, 0.1f, "where its last segment crosses it");+ NothingInside(rail, "railway");++ // A line that starts inside and leaves by the east wall: its first point becomes the crossing (2000, 150).+ var east = RouteLayer.TrimEndsInside(Line(0f, 0f, 1500f, 100f, 2500f, 200f), c, half);+ Assert.AreEqual(2, east.Count);+ Assert.AreEqual(2000f, (east[0] - c).x, eps); Assert.AreEqual(150f, (east[0] - c).y, eps);+ Assert.AreEqual(half, Cheb(east[0]), eps, "the cut end lies on the wall line");+ NothingInside(east, "east");++ // Wholly outside: unchanged. Wholly inside: empty. Through the square: only the ends are cut, so it keeps its middle.+ var outside = Line(-3000f, -3000f, 3000f, -3000f);+ CollectionAssert.AreEqual(outside, RouteLayer.TrimEndsInside(outside, c, half));+ CollectionAssert.IsEmpty(RouteLayer.TrimEndsInside(Line(-100f, 0f, 100f, 0f), c, half));+ var through = Line(-3000f, 0f, 0f, 0f, 3000f, 0f);+ CollectionAssert.AreEqual(through, RouteLayer.TrimEndsInside(through, c, half));+ }++ /// <summary>Jerusalem's symbolic Old City is a walled square 4 km across (SettlementKits.OldCityWalls), so the real 1948+ /// roads that meet by New Gate, and the Jaffa-Jerusalem railway's station, all outside the real walls, fall inside it.+ /// The map cuts each road's and the railway's ribbon at the walls (#319; the railway on the owner's ruling, "Cut it at+ /// the walls"): no ribbon vertex lies inside the square by more than half its ribbon's width (an end section is square+ /// to the line, so a line meeting the wall at a slant reaches that far in, under the wall), and the four roads and the+ /// railway that meet there each reach to within 300 m outside it.</summary>+ [Test]+ public void TheRoadsAndTheRailwayStopAtTheOldCityWalls()+ {+ var map = BuildMap();+ try+ {+ var data = map.Terrain.terrainData; var origin = map.Terrain.transform.position;+ var (c, half) = Statecraft.Game.Map.Kits.SettlementKits.OldCityWalls(map.Frame);+ Assert.Greater(half, 1000f, "the square is not empty");+ var inside = new SortedSet<string>(); var reach = new SortedSet<string>();+ foreach (var plan in RouteLayer.Plan(RoutePaths.Parse(CommittedYaml, Bounds)))+ {+ float allowed = (plan.RailGrade ? RouteLayer.RailWidthM : RouteLayer.RoadWidthM) / 2f;+ var g = RouteLayer.Derive(plan, map.Frame, data, origin);+ foreach (var span in g.Routes)+ for (int v = span.FirstVertex; v < span.FirstVertex + span.VertexCount; v++)+ {+ var p = g.Vertices[v];+ float d = Mathf.Max(Mathf.Abs(p.x - c.x), Mathf.Abs(p.z - c.y)); // under half: inside the walls+ if (d < half - allowed) inside.Add(span.Id);+ else if (d < half + 300f) reach.Add(span.Id);+ }+ }+ CollectionAssert.IsEmpty(inside, "ribbons inside the Old City's walls");+ CollectionAssert.IsSubsetOf(new[] { "jaffa_jerusalem_road", "jerusalem_hebron_beersheba_road", "jerusalem_nablus_nazareth_road",+ "jerusalem_jericho_road", "jaffa_jerusalem_railway" }, reach, "the roads and the railway that reach the walls");+ }+ finally { Object.DestroyImmediate(map.gameObject); }+ }+/// <summary>Kits and routes together (#179 on main): no kit building, landmark or tree reaches into any route's/// corridor, half the drawn width plus RouteLayer.CorridorMarginM, the Burma Road included (the kits are built once,/// not per date). Checked by brute force against every segment, independent of KitGround's grid.</summary>