diff --git a/builder/wasm/wasm_size_guard.py b/builder/wasm/wasm_size_guard.py index 842c899a8c..0ddbb8bd40 100644 --- a/builder/wasm/wasm_size_guard.py +++ b/builder/wasm/wasm_size_guard.py @@ -22,7 +22,7 @@ # junction ends, their ends on the stubs' points, what each deck is made of, the junctions that lie on the # ground, and a building passage of an older bake on the ground (the crate's feature `storeys` on, stable 1.100.0). # The owner allows about 60 kB of code growth for the crossing block, stated in its pull request and recorded here. -GROUND_PLAN_MEASURED = {"gzipped": 808_271, "raw_wasm": 2_090_936} +GROUND_PLAN_MEASURED = {"gzipped": 808_099, "raw_wasm": 2_090_936} # The owner's margin: compiler and dependency updates move the size by a few kilobytes and must not fail # unrelated pull requests; real growth past the margin still fails. Raw gets the same fraction as gzipped. # A pull request that changes the bridge's code records its own CI size here; the margin is only for toolchain diff --git a/builder/web/tests/browser/trailview/fixture/features/13/4286/2887.bin b/builder/web/tests/browser/trailview/fixture/features/13/4286/2887.bin index 0e21381552..96f51ddfd7 100644 Binary files a/builder/web/tests/browser/trailview/fixture/features/13/4286/2887.bin and b/builder/web/tests/browser/trailview/fixture/features/13/4286/2887.bin differ diff --git a/builder/web/tests/browser/trailview/fixture/features/13/4287/2887.bin b/builder/web/tests/browser/trailview/fixture/features/13/4287/2887.bin index 0ab7d3ef27..bb61b2fb8e 100644 Binary files a/builder/web/tests/browser/trailview/fixture/features/13/4287/2887.bin and b/builder/web/tests/browser/trailview/fixture/features/13/4287/2887.bin differ diff --git a/host/obc-data-steps/src/planner.rs b/host/obc-data-steps/src/planner.rs index 00af2dddc2..b31b63df8c 100644 --- a/host/obc-data-steps/src/planner.rs +++ b/host/obc-data-steps/src/planner.rs @@ -68,7 +68,7 @@ pub static PLANNER_SNOW: Layer = whole("planner/snow", 2, &[&WEB_PLANNER]); /// holds what the stamp worker makes of the tiles; `stamp_version` of `specs/trailview-tiles.md` says /// which stamp code made it. pub static PLANNER_TRAILVIEW_FEATURES: Layer = - Layer { revision: 20, ..whole("planner/trailview-features", 4, &[&WEB_PLANNER]) }; + Layer { revision: 21, ..whole("planner/trailview-features", 4, &[&WEB_PLANNER]) }; /// The TrailView ruleset, `rules.json` of `specs/trailview-tiles.md`. Its format is `format` of /// `rules.json`, `FORMAT` of `tools/trailview/rules.py`. pub static PLANNER_TRAILVIEW_RULES: Layer = diff --git a/host/obc-ground-plan/src/faces/heights/tests.rs b/host/obc-ground-plan/src/faces/heights/tests.rs index afd6bec08f..4a80ac8468 100644 --- a/host/obc-ground-plan/src/faces/heights/tests.rs +++ b/host/obc-ground-plan/src/faces/heights/tests.rs @@ -3,38 +3,13 @@ use super::check::{border, edge_steps, scan, terrain_at, Class, Scan}; use super::{height_at, height_at_sides, Kind, Step}; use crate::faces::records::{self, find}; -use crate::faces::tests::{at, cell, input_of, line, main_road, mpu, road, track, Line}; +use crate::faces::tests::{at, cell, input_of, line, main_road, mpu, plane, road, track, Line}; use crate::faces::Rules; use crate::frame::{CellKey, CELL_UNITS}; use crate::graph::build; use crate::sections::Sections; -use crate::terrain::{StoredPage, Terrain, PAGE}; use crate::CellInput; -/// The terrain of a cell on every page that it reads: z of metres east and south of the centre of -/// `cell()`. -fn plane(key: CellKey, z: &dyn Fn(f64, f64) -> f64) -> Terrain { - let centre = at([0.0, 0.0]); - let pages = Terrain::wanted(key) - .into_iter() - .map(|k| { - let s = crate::frame::FRAME_BITS - 8 - u32::from(k.level); - let texel = |i: usize, base: u32| ((i64::from(base) << 8) + i as i64) << s | 1 << (s - 1); - let h: Vec = (0..PAGE * PAGE) - .map(|t| { - let (x, y) = (texel(t % PAGE, k.x), texel(t / PAGE, k.y)); - z((x - centre.x) as f64 * mpu(), (y - centre.y) as f64 * mpu()) - }) - .collect(); - let (min, max) = h.iter().fold((f64::MAX, f64::MIN), |(a, b), &v| (a.min(v), b.max(v))); - let scale = ((max - min) / 65534.0).max(1e-4); - let codes = h.iter().map(|v| ((v - min) / scale).round() as u16).collect(); - StoredPage { level: k.level, x: k.x, y: k.y, offset: min as f32, scale: scale as f32, codes } - }) - .collect(); - Terrain::new(key, pages) -} - struct Built { key: CellKey, words: Vec, diff --git a/host/obc-ground-plan/src/faces/tests.rs b/host/obc-ground-plan/src/faces/tests.rs index b40352b366..8198376b3a 100644 --- a/host/obc-ground-plan/src/faces/tests.rs +++ b/host/obc-ground-plan/src/faces/tests.rs @@ -3,7 +3,7 @@ use super::records::{self, check as records_check}; use super::*; use crate::frame::{from_lon_lat, metres_per_unit, GlobalPoint}; use crate::graph::{build, WayGraph}; -use crate::terrain::Terrain; +use crate::terrain::{StoredPage, Terrain, PAGE}; use crate::tile::{self, Alignment, Feature, Geometry, Tags}; pub(crate) fn cell() -> CellKey { @@ -89,6 +89,30 @@ pub(crate) fn input_of(key: CellKey, lines: &[Line]) -> CellInput { } } +/// The terrain of a cell on every page that it reads: z of metres east and south of the centre of +/// `cell()`. +pub(crate) fn plane(key: CellKey, z: &dyn Fn(f64, f64) -> f64) -> Terrain { + let centre = at([0.0, 0.0]); + let pages = Terrain::wanted(key) + .into_iter() + .map(|k| { + let s = crate::frame::FRAME_BITS - 8 - u32::from(k.level); + let texel = |i: usize, base: u32| ((i64::from(base) << 8) + i as i64) << s | 1 << (s - 1); + let h: Vec = (0..PAGE * PAGE) + .map(|t| { + let (x, y) = (texel(t % PAGE, k.x), texel(t / PAGE, k.y)); + z((x - centre.x) as f64 * mpu(), (y - centre.y) as f64 * mpu()) + }) + .collect(); + let (min, max) = h.iter().fold((f64::MAX, f64::MIN), |(a, b), &v| (a.min(v), b.max(v))); + let scale = ((max - min) / 65534.0).max(1e-4); + let codes = h.iter().map(|v| ((v - min) / scale).round() as u16).collect(); + StoredPage { level: k.level, x: k.x, y: k.y, offset: min as f32, scale: scale as f32, codes } + }) + .collect(); + Terrain::new(key, pages) +} + /// The plan of a cell from lines, with check 1 at 0 faults. fn plan_of(key: CellKey, lines: &[Line]) -> (FacePlan, WayGraph) { let input = input_of(key, lines); diff --git a/host/obc-ground-plan/src/graph/levels.rs b/host/obc-ground-plan/src/graph/levels.rs index 490be58662..a50f42c173 100644 --- a/host/obc-ground-plan/src/graph/levels.rs +++ b/host/obc-ground-plan/src/graph/levels.rs @@ -22,7 +22,7 @@ pub struct Structures { pub cover_m: f64, /// Free ground over a bore may lack this much of the least room. pub lift_max_m: f64, - /// A tunnel way is open only this far along from a tag end. + /// A tunnel way is open only this far along from a tag end: the longest open cut of the crossing design. pub open_max_m: f64, /// A deck shorter than this between its end lines is a ground way. pub deck_min_m: f64, @@ -427,10 +427,11 @@ impl<'a> Ctx<'a> { /// Storey 0 at q without way `not` and the ways that go on from its ends: the terrain and the bodies /// of the ground ways near q (their surface less their `fill` times the metres past the paved - /// stroke). And whether a paved stroke covers q. - fn ground(&self, q: [f64; 2], not: u32) -> (f64, bool) { + /// stroke). And the highest paved stroke that covers q, less the at-grade band of it and `not` (the + /// lower of their `snap_height_m`, as at a crossing); None where none covers q. + fn ground(&self, q: [f64; 2], not: u32) -> (f64, Option) { let mpu = self.mpu(q); - let (mut z, mut paved) = (self.terrain(q), false); + let (mut z, mut paved) = (self.terrain(q), None::); for f in self.feet(q, HALF_MAX_M + BODY_M) { if f.way == not || self.g.ways[f.way as usize].level != Level::Ground || self.joined(not, f.way) { continue; @@ -438,8 +439,12 @@ impl<'a> Ctx<'a> { let Rule::Way(s, _) = self.rule(f.way) else { continue }; let past = f.d * mpu - self.foot_half(&f); if past <= s.reach_m { - paved |= past <= 0.0; - z = z.max(self.surface(&f, q) - s.fill * past.max(0.0)); + let surface = self.surface(&f, q); + if past <= 0.0 { + let top = surface - s.snap_height_m.min(self.snap_m(not)); + paved = Some(paved.map_or(top, |p| p.max(top))); + } + z = z.max(surface - s.fill * past.max(0.0)); } } (z, paved) @@ -460,7 +465,8 @@ impl<'a> Ctx<'a> { } /// The bore test at a point of a tunnel way: `c` less what it needs (the least room, or that less - /// `lift_max_m` on free ground). `c` is the least of storey 0 over the bore's width less the floor. + /// `lift_max_m` on free ground, where no paved stroke lies: a paved face never moves). `c` is the + /// least of storey 0 over the bore's width less the floor. fn bore(&self, w: u32, a: &At) -> f64 { let Rule::Way(s, _) = self.rule(w) else { return f64::NEG_INFINITY }; let half = (s.half_m + a.widen) / self.mpu(a.p); @@ -471,18 +477,21 @@ impl<'a> Ctx<'a> { let (z, paved) = self.ground(q, w); let across = -cross(a.tangent, sub(q, a.p)) * self.mpu(a.p); c = c.min(z - (a.z + a.bank * across)); - free &= !paved; + free &= paved.is_none(); } let least = s.bore_least_m + s.roof_least_m; c - if free { least - self.s.lift_max_m } else { least } } - /// The state of a tunnel station by its own test: BORE, OPEN or HIDDEN. OPEN needs the floor at - /// most `snap_height_m` over the terrain: at a tag end the floor lies on the ground way that goes on. + /// The state of a tunnel station by its own test: BORE where the bore fits; else OPEN within + /// `open_max_m` of a tag end, wherever its floor lies against the terrain (the way goes on as a ground + /// way, on its bank where the floor lies over the terrain, until the cover holds), unless a way lies on + /// top: a paved stroke over the floor by more than the at-grade band; else HIDDEN. fn tunnel_state(&self, w: u32, a: &At, tag_m: f64) -> State { + let on_top = || self.ground(a.p, w).1.is_some_and(|top| top > a.z); if self.bore(w, a) >= 0.0 { State::Bore - } else if tag_m > self.s.open_max_m || a.z > self.terrain(a.p) + self.snap_m(w) || self.ground(a.p, w).1 { + } else if tag_m > self.s.open_max_m || on_top() { State::Hidden } else { State::Open diff --git a/host/obc-ground-plan/src/graph/tests.rs b/host/obc-ground-plan/src/graph/tests.rs index d7ebf5c9f6..44d9c71aed 100644 --- a/host/obc-ground-plan/src/graph/tests.rs +++ b/host/obc-ground-plan/src/graph/tests.rs @@ -105,7 +105,18 @@ fn graph(lines: &[Line]) -> WayGraph { } fn graph_of(key: CellKey, lines: &[Line]) -> WayGraph { - let input = input_of(key, lines); + graph_with(input_of(key, lines)) +} + +/// The graph of lines on terrain z of metres east and south of the cell's centre. +fn graph_on(lines: &[Line], z: &dyn Fn(f64, f64) -> f64) -> WayGraph { + let mut input = input_of(cell(), lines); + input.terrain = crate::faces::tests::plane(cell(), z); + graph_with(input) +} + +fn graph_with(input: CellInput) -> WayGraph { + let key = input.key; let mut g = build(key, &input, Sections::embedded()); assert_eq!(check(&g), Vec::new()); let structures = &crate::faces::Rules::embedded().structures; @@ -911,6 +922,84 @@ fn the_room_reads_each_way_on_its_own_curve() { assert!(g.crossings.iter().any(|c| c.ladder.is_some())); } +/// The states of a way's runs in order, and its end lines by kind and metres along it. +type WayLevels = (Vec, Vec<(EndKind, f64)>); + +/// The levels of the one tunnel way of a graph. +fn tunnel_levels(g: &WayGraph) -> WayLevels { + let tunnels: Vec<&Way> = g.ways.iter().filter(|w| w.level == Level::Tunnel).collect(); + assert_eq!(tunnels.len(), 1); + let w = tunnels[0]; + let states = g.levels.runs.iter().filter(|r| r.way == w.id).map(|r| r.state).collect(); + let at = |l: &EndLine| (l.kind, super::points::between(&g.parts, &w.from, &l.at)); + (states, g.levels.end_lines.iter().filter(|l| l.way == w.id).map(at).collect()) +} + +#[test] +fn a_tunnel_that_comes_in_over_the_terrain_is_open_from_its_tag_end_up_to_open_max_m() { + use EndKind::*; + use State::*; + // A residential way 3 m over flat terrain, a tunnel from x 0 to `len` through a ridge that rises `slope` per metre + // from each tag end. The bore needs the least room less the lift on free ground: 3.0 + 0.3 - 1.0 = 2.3 m of + // cover, at (3 + 2.3) / slope in from each end. On the steep ridge that lies within `open_max_m` (30 m): the way is + // open from its tag end, on its bank, to the portal. On the gentle one it lies past 30 m: open to 30 m, then + // closed. + let street = [("highway", "residential")]; + let tunnel = [("highway", "residential"), ("tunnel", "yes")]; + let cases: [(f64, f64, WayLevels); 2] = [ + (0.5, 80.0, (vec![Open, Bore, Open], vec![(Portal, 10.6), (Portal, 69.4)])), + ( + 0.1, + 160.0, + ( + vec![Open, Hidden, Bore, Hidden, Open], + vec![(Closed, 30.0), (Closed, 53.0), (Closed, 107.0), (Closed, 130.0)], + ), + ), + ]; + for (slope, len, (want_states, want_lines)) in cases { + let lines = [ + line("road", &street, &[[-60.0, 0.0], [0.0, 0.0]], 3.0), + line("tunnel", &tunnel, &[[0.0, 0.0], [len, 0.0]], 3.0), + line("road", &street, &[[len, 0.0], [len + 60.0, 0.0]], 3.0), + ]; + let g = graph_on(&lines, &|x, _| (slope * x.min(len - x)).max(0.0)); + let (states, lines) = tunnel_levels(&g); + assert_eq!(states, want_states, "slope {slope}: {lines:?}"); + assert_eq!(lines.len(), want_lines.len(), "slope {slope}: {lines:?}"); + for (got, want) in lines.iter().zip(&want_lines) { + assert!(got.0 == want.0 && (got.1 - want.1).abs() < 0.3, "slope {slope}: {got:?}, want {want:?}"); + } + } +} + +#[test] +fn a_paved_stroke_hides_a_tunnel_station_only_where_it_lies_on_top() { + // A residential tunnel with no cover on flat terrain between two roads at its height, and a residential road + // beside it from x 5 to 30, 2 m off its middle, so that the road's paved stroke covers the tunnel's middle line. + // Lower than the tunnel's floor, or within `snap_height_m` (0.5 m) over it, the road lies beside it and the tunnel + // is open along its whole length; higher, the road lies on top and hides the tunnel under its stroke. + let street = [("highway", "residential")]; + let tunnel = [("highway", "residential"), ("tunnel", "yes")]; + for (dz, hidden) in [(-2.0, false), (0.5, false), (0.55, true)] { + let lines = [ + line("road", &street, &[[-60.0, 0.0], [0.0, 0.0]], 0.0), + line("tunnel", &tunnel, &[[0.0, 0.0], [40.0, 0.0]], 0.0), + line("road", &street, &[[40.0, 0.0], [100.0, 0.0]], 0.0), + line("road", &street, &[[5.0, 2.0], [30.0, 2.0]], dz), + ]; + let g = graph_on(&lines, &|_, _| 0.0); + let (states, lines) = tunnel_levels(&g); + if hidden { + assert_eq!(states, [State::Open, State::Hidden, State::Open], "dz {dz}: {lines:?}"); + let (a, b) = (lines[0].1, lines[1].1); + assert!(a > 2.0 && a < 5.0 && b > 30.0 && b < 33.0, "dz {dz}: the road's stroke, {lines:?}"); + } else { + assert_eq!((states, lines), (vec![State::Open], Vec::new()), "dz {dz}"); + } + } +} + #[test] fn a_passage_through_a_building_of_kind_tunnel_lies_on_the_ground_and_a_tunnel_does_not() { let level = |tunnel: &'static str| { diff --git a/specs/trailview-features.md b/specs/trailview-features.md index 8f7e46d7c1..aa8154cdea 100644 --- a/specs/trailview-features.md +++ b/specs/trailview-features.md @@ -428,7 +428,12 @@ class and waterway kind, and the `structures` of `plan.json`), so a change of th of the code of the levels takes a new revision. The bake builds each zoom-16 cell of each zoom-13 tile that holds a way of the road solver as the viewer does: from the zoom-13 tiles of the bake and the terrain tiles of zooms 13 and 12 of the grid. Each cell decides the ways inside its square. A way has a state where it is a bridge or a tunnel, or -where it ends at the body of a way that it crosses. The A lines of one deck group that cross or lie within +where it ends at the body of a way that it crosses. A station of a tunnel is `B` where the ground over it gives +the least room of its class (`bore_least_m` and `roof_least_m`, less `lift_max_m` where no paved way lies on that +ground). Else it is `O` within `open_max_m` (30 m) of a tag end and before the first `B` from its nearer tag end, +also where its floor lies over the terrain (the way goes on as a way on the ground until the cover holds), but `H` +where a paved way lies on top of it: more than the lower `snap_height_m` of the two ways over its floor. Else it is +`H`. The A lines of one deck group that cross or lie within `edge_band_m` of each other move in together: each A moves in along its way to where its centre line meets the line normal to their mean direction into the decks through the farthest one in, and each end line stays square to its own way. One pass merges them; a cell merges the A lines that it sees. The storey is one per deck group, the deck ways that share a