Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
db0bf27
trailview-features: a pair has a part at each end of both chains, and…
timohueser Nov 21, 2026
d23e853
trailview-parts: the pair, the rim of an opening in the rock and of a…
timohueser Nov 21, 2026
21f4cac
data-steps: features revision 36
timohueser Nov 21, 2026
32d6d75
trailview-parts: two built tubes whose shells overlap meet at the mid…
timohueser Nov 21, 2026
ff27de6
trailview-parts: a head ends at the middle between its tube and a nea…
timohueser Nov 21, 2026
ebac942
trailview-parts: a tube and a head end at the meeting with a near tub…
timohueser Nov 21, 2026
f63558a
specs: a pair needs a part at both ends of its two chains, and its he…
timohueser Nov 21, 2026
6276fec
trailview-parts: comments fit the line and name the general cut
timohueser Nov 21, 2026
c07d6c3
trailview-parts: the cuts' map shares the openings' map type, and a s…
timohueser Nov 21, 2026
bd57096
wasm: the recorded size of the parts bridge with the pair, the rim an…
timohueser Nov 21, 2026
2908211
wasm: the parts and ground plan bridges' sizes as CI measures this br…
timohueser Nov 21, 2026
ff722bd
trailview-parts: tubes meet only where both are, heads only where a t…
timohueser Nov 21, 2026
570f77d
trailview-features: each tube of a pair has its own collar; cap and f…
timohueser Nov 21, 2026
dd67223
specs: each tube of a pair has its own collar; the face and foot of a…
timohueser Nov 21, 2026
2b8eda5
trailview-parts: test a pair whose tubes run 25 degrees apart from on…
timohueser Nov 21, 2026
948828b
trailview-parts: a head's closing faces bound their spans with max an…
timohueser Nov 21, 2026
8e5c5f4
trailview-parts: a clip takes off the other's side of the own axis
timohueser Nov 21, 2026
156e769
trailview-parts: a tube is met between the planes of its rings; a hea…
timohueser Nov 21, 2026
3ac162b
wasm: the parts bridge's size with the cut only where both tubes are …
timohueser Nov 21, 2026
e9e4f30
wasm: the parts and ground plan bridges' sizes as CI measures 3ac162ba6
timohueser Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions builder/wasm/wasm_size_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
# the sidewalks' slabs with their ends, rings and kerbs, and the portal line's levels with the cover's sides.
# The owner allows about 60 kB of code growth for the crossing block, stated in its pull request and recorded here.
# The built tunnel ends (obc-trailview-parts) with their open stretches and the approaches to their openings add
# about 36 kB gzipped; measured on that build with wasm-pack 0.15.0 and rustc 1.99.0, which gives the build before it
# about 5 kB more than CI.
GROUND_PLAN_MEASURED = {"gzipped": 828_795, "raw_wasm": 2_129_601}
# about 36 kB gzipped; the openings of a pair's mate (the parts' `mouths`) about 2 kB more, measured in CI with
# wasm-pack 0.15.0 and rustc 1.100.0.
GROUND_PLAN_MEASURED = {"gzipped": 831_313, "raw_wasm": 2_133_837}
# 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
Expand All @@ -46,9 +46,10 @@
}

# Measured in CI on the build of the tunnel parts' arch, tube, boxes and underpasses, with a tile's volumes built once
# and selected per node, with wasm-pack 0.15.0 and rustc 1.100.0. The margin is the ground plan's, raw by the same
# fraction.
PARTS_MEASURED = {"gzipped": 125_922, "raw_wasm": 293_466}
# and selected per node, and the pair, the rim, the closed free end and the cut of two tubes that meet only where both
# are, with the closed cut of a head, with wasm-pack 0.15.0 and rustc 1.100.0. The margin is the ground plan's, raw by
# the same fraction.
PARTS_MEASURED = {"gzipped": 147_785, "raw_wasm": 335_603}
PARTS_MARGIN = {
"gzipped": GROUND_PLAN_MARGIN_GZIPPED,
"raw_wasm": round(GROUND_PLAN_MARGIN_GZIPPED * PARTS_MEASURED["raw_wasm"] / PARTS_MEASURED["gzipped"]),
Expand Down
4 changes: 2 additions & 2 deletions builder/web/src/lib/trailview/structures/parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export function partStamps(list: Feature[], tile: Node, lines: Line[]): PartStam
};
for (const { kind, tags } of list) {
if (kind !== 'tunnel-end') continue;
for (const [way, shift] of [[tags.way, tags.shift], [tags.mate_way, tags.mate_shift]]) {
for (const [way, shift, collar] of [[tags.way, tags.shift, tags.collar], [tags.mate_way, tags.mate_shift, tags.mate_collar]]) {
// `way` is in the frame of the ground plan, 16 units to a world unit.
const [x, y] = way?.split(' ').map(Number) ?? [];
for (const [line, end] of at.get(`${x / 16},${y / 16}`) ?? []) stop(line, end, Number(shift) + Number(tags.collar) + COVER_START_M);
for (const [line, end] of at.get(`${x / 16},${y / 16}`) ?? []) stop(line, end, Number(shift) + Number(collar) + COVER_START_M);
}
}
return out;
Expand Down
2 changes: 1 addition & 1 deletion host/obc-data-steps/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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: 35, ..whole("planner/trailview-features", 4, &[&WEB_PLANNER]) };
Layer { revision: 36, ..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 =
Expand Down
20 changes: 8 additions & 12 deletions host/obc-ground-plan/src/openings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The built tunnel ends of a cell's input (`obc-trailview-parts`): the openings that its ground reaches.

use obc_trailview_parts::{built_ends, Chord, End, Rules};
use obc_trailview_parts::{mouths, Chord, End, Rules};

use crate::frame::GlobalPoint;
use crate::graph::OpenEnd;
Expand Down Expand Up @@ -48,19 +48,15 @@ pub fn built(input: &CellInput) -> Built {
_ => {}
}
}
let built = built_ends(&ends, &chords, rules);
let [x0, y0, x1, y1] = input.key.grown();
let (mut open, mut mouths) = (Vec::new(), Vec::new());
for (end, _) in ends.iter().zip(&built).filter(|(_, &b)| b) {
mouths.push(Mouth { at: end.at.map(|v| v * FRAME), into: end.way_in(), half_m: end.half });
let ways = [Some((end.way, end.shift)), end.mate_way.zip(end.mate_shift)];
for (way, shift_m) in ways.into_iter().flatten() {
if (x0..=x1).contains(&way[0]) && (y0..=y1).contains(&way[1]) {
open.push(OpenEnd { way: GlobalPoint { x: way[0], y: way[1] }, shift_m });
}
let (mut open, mut out) = (Vec::new(), Vec::new());
for m in mouths(&ends, &chords, rules) {
out.push(Mouth { at: m.at.map(|v| v * FRAME), into: m.into, half_m: m.half });
if (x0..=x1).contains(&m.way[0]) && (y0..=y1).contains(&m.way[1]) {
open.push(OpenEnd { way: GlobalPoint { x: m.way[0], y: m.way[1] }, shift_m: m.shift });
}
}
Built { open, mouths }
Built { open, mouths: out }
}

#[cfg(test)]
Expand Down Expand Up @@ -220,7 +216,7 @@ mod tests {

#[test]
fn a_chain_with_an_end_that_is_not_built_keeps_its_tunnel_way() {
let (graph, mesh) = build(&input(Some("arch free")));
let (graph, mesh) = build(&input(Some("arch none")));
let (develop_graph, develop) = build(&input(None));
assert_eq!((&graph.ways, &graph.samples), (&develop_graph.ways, &develop_graph.samples));
assert_eq!(mesh.to_bytes(), develop.to_bytes());
Expand Down
93 changes: 60 additions & 33 deletions host/obc-trailview-features/src/parts/ladder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ use super::{along_dir, built_openings, counts, distance, first_way_m, left_of, o
pub use obc_trailview_parts::Part as Kind;

/// The numbers of a drawn opening (Plan 8 of the design): metres, `left` and `right` per metre out from the frame's
/// outer edge, and in a pair the mate's opening and the metres to its axis to the left; `height` is the inside height
/// of the tube's chord there.
/// outer edge, and in a pair the mate's opening, the metres to its axis to the left and its collar; `height` is the
/// inside height of the tube's chord there; `heading` is square to its frame line, into the tube of the opening farther
/// in.
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct Numbers {
pub heading: f64,
pub height: f64,
pub collar: f64,
pub face: f64,
pub left: Vec<f64>,
pub right: Vec<f64>,
pub foot: f64,
pub mate: Option<(usize, f64)>,
pub mate: Option<(usize, f64, f64)>,
}

/// An opening's decision: every kind that fits in the order of the rungs, the part of the end (the first; also the
Expand Down Expand Up @@ -260,15 +262,23 @@ pub(crate) fn decide(tubes: &[Tube], openings: &mut [Opening], input: &Input, me
rung[i] = Some(r);
kinds[i] = k;
}
// Rung 5: the pairs, nearest first, each end in one pair at most.
// Rung 5: the pairs, nearest first, each end in one pair at most. A pair is one part of two chains, so each of them
// has a part at both of its ends.
let mut mate: Vec<Option<usize>> = vec![None; n];
let is_hill = |i: usize| hill.contains(&i);
// The opening at each end of each tube.
let mut at_end: Vec<[Option<usize>; 2]> = vec![[None; 2]; tubes.len()];
for (i, o) in openings.iter().enumerate() {
at_end[o.tube][o.end].get_or_insert(i);
}
let whole: Vec<bool> = at_end.iter().map(|e| e.iter().all(|i| i.is_some_and(|i| !kinds[i].is_empty()))).collect();
for x in &near {
let (a, c) = (x.a, x.b);
if !is_hill(a) || !is_hill(c) || mate[a].is_some() || mate[c].is_some() {
continue;
}
if tubes[openings[a].tube].rail != tubes[openings[c].tube].rail {
let (ta, tc) = (openings[a].tube, openings[c].tube);
if tubes[ta].rail != tubes[tc].rail || !whole[ta] || !whole[tc] {
continue;
}
mate[a] = Some(c);
Expand Down Expand Up @@ -369,27 +379,26 @@ pub(crate) fn decide(tubes: &[Tube], openings: &mut [Opening], input: &Input, me
let refitted = (0..n).filter(|&i| kinds[i].first().copied() != before[i]).count();
// The floor of each tube with a part, from opening to opening; an end with no opening holds the end vertex. Its
// chord at an opening gives the opening its inside height.
let spans: Vec<Option<[f64; 2]>> = (0..tubes.len())
.map(|t| {
let at = |end: usize| openings.iter().position(|o| o.tube == t && o.end == end);
let with = [at(0), at(1)].into_iter().flatten().any(|i| !kinds[i].is_empty());
let s0 = at(0).map_or(0.0, |i| openings[i].s);
let s1 = at(1).map_or(tubes[t].curve.len, |i| openings[i].s);
let spans: Vec<Option<[f64; 2]>> = (tubes.iter().zip(&at_end))
.map(|(t, &[a, z])| {
let with = [a, z].into_iter().flatten().any(|i| !kinds[i].is_empty());
let s0 = a.map_or(0.0, |i| openings[i].s);
let s1 = z.map_or(t.curve.len, |i| openings[i].s);
(with && s1 - s0 > 1e-6).then_some([s0, s1])
})
.collect();
let (floors, floor_metrics) = floor::floors(tubes, &spans, (&half, &height), input);
let end_height = |o: &Opening| floors[o.tube].as_ref().map_or(height[o.tube], |f| f.end_height(o.end));
let heights: Vec<f64> = openings.iter().map(end_height).collect();
// The numbers of each drawn opening.
let mut ends: Vec<End> = Vec::with_capacity(n);
for i in 0..n {
let kind = kinds[i].first().copied();
// A pair has one record, at the opening of the lower feature id.
let drawn = mate[i].is_none_or(|m| (openings[i].way_id, i) < (openings[m].way_id, m));
let m = Measured { sites: &sites, rights: &rights, cover: &cover, moved: &moved };
let h = end_height(&openings[i]);
let numbers = (kind.filter(|_| drawn))
.map(|kind| numbers(i, kind, (mate[i], far_of[i]), &m, (openings, tubes), (&half, h), input));
.map(|kind| numbers(i, kind, (mate[i], far_of[i]), &m, (openings, tubes), (&half, &heights), input));
ends.push(End { kinds: kinds[i].clone(), kind, rung: rung[i].unwrap_or_default(), numbers });
}
let shown = |e: &End| match e.kind {
Expand Down Expand Up @@ -424,15 +433,15 @@ struct Measured<'a> {
moved: &'a [f64],
}

/// The numbers of drawn opening i of `kind` (Plan 8) with the inside height `h` there: its frame is its own, or in a
/// pair the frame line of the opening farther in, which holds both.
/// The numbers of drawn opening i of `kind` (Plan 8), with the inside height of each opening: its frame is its own, or
/// in a pair the frame line of the opening farther in, which holds both.
fn numbers(
i: usize,
kind: Kind,
(mate, far): (Option<usize>, usize),
m: &Measured,
(openings, tubes): (&[Opening], &[Tube]),
(half, h): (&[f64], f64),
(half, heights): (&[f64], &[f64]),
input: &Input,
) -> Numbers {
let Measured { sites, rights, cover, moved } = *m;
Expand All @@ -456,8 +465,11 @@ fn numbers(
.filter_map(ground)
.collect();
let highest = frame.iter().copied().fold(f64::NEG_INFINITY, f64::max);
let mut face = (h + b.shell_m + b.band_m).max(highest - floor + b.coping_m);
face = face.min(h + b.shell_m + b.face_over_crown_max_m);
// The wall holds its band over the higher crown of the frame's tubes, and fits the ground up to its cap over the
// lower.
let crowns = members.iter().map(|&k| openings[k].floor - floor + heights[k] + b.shell_m);
let (low, high) = crowns.fold((f64::INFINITY, f64::NEG_INFINITY), |(l, h), c| (l.min(c), h.max(c)));
let mut face = (high + b.band_m).max((highest - floor + b.coping_m).min(low + b.face_over_crown_max_m));
// A deck over the frame line or its wing walls: its underside lies over the floor (a way that goes on from the
// opening on a deck lies at the floor, not over it).
for &(x, under) in &site.decks {
Expand Down Expand Up @@ -489,22 +501,37 @@ fn numbers(
let (left, right) = (wing(hi, 1.0), wing(lo, -1.0));
let collar_of = |k: usize| cover[k].map(|d| (d - moved[k]).max(0.0));
let half_chain = t.curve.len / 2.0;
let collar = match kind {
Kind::Pair => members.iter().filter_map(|&k| collar_of(k)).fold(0.0, f64::max),
Kind::Arch | Kind::Rock => collar_of(i).expect("an arch is covered within its collar"),
Kind::Box => collar_of(i).unwrap_or(f64::INFINITY).min(half_chain),
Kind::Free => collar_of(i).unwrap_or(f64::INFINITY).min(b.free_max_m).min(half_chain),
};
// The lowest ground under the frame, its wing walls and the collar.
let own = sites[i].as_ref().expect("a measured opening");
// Each tube of a pair has its own collar.
let collars: Vec<f64> = (members.iter())
.map(|&k| match kind {
Kind::Pair | Kind::Arch | Kind::Rock => collar_of(k).expect("an arch is covered within its collar"),
Kind::Box => collar_of(k).unwrap_or(f64::INFINITY).min(half_chain),
Kind::Free => collar_of(k).unwrap_or(f64::INFINITY).min(b.free_max_m).min(half_chain),
})
.collect();
// The lowest ground under the frame, its wing walls and the collars, and the floors.
let (from, to) = (lo - right.len() as f64, hi + left.len() as f64);
let under = (from.ceil() as i64..=to.floor() as i64).filter_map(|x| ground(x as f64));
let collar_ground = (own.stations.iter())
.skip(moved[i].round() as usize)
.take(collar.ceil() as usize + 1)
.flat_map(|st| st.iter().flatten().copied());
let lowest = under.chain(collar_ground).fold(floor, f64::min);
let mate = mate.map(|m| (m, axis(m) - axis(i)));
let collar_ground = members.iter().zip(&collars).flat_map(|(&k, collar)| {
let site = sites[k].as_ref().expect("a measured opening");
(site.stations.iter())
.skip(moved[k].round() as usize)
.take(collar.ceil() as usize + 1)
.flat_map(|st| st.iter().flatten().copied())
});
let floors = members.iter().map(|&k| openings[k].floor);
let lowest = under.chain(collar_ground).chain(floors).fold(floor, f64::min);
let mate = mate.map(|m| (m, axis(m) - axis(i), collars[1]));
let numbers = if kind == Kind::Free { (Vec::new(), Vec::new()) } else { (left, right) };
Numbers { height: h, collar, face, left: numbers.0, right: numbers.1, foot: lowest - b.foot_m - floor, mate }
let heading = openings[far].heading();
Numbers {
heading,
height: heights[i],
collar: collars[0],
face,
left: numbers.0,
right: numbers.1,
foot: lowest - b.foot_m - floor,
mate,
}
}
5 changes: 3 additions & 2 deletions host/obc-trailview-features/src/parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ fn records(tubes: &[Tube], openings: &[Opening], decided: &ladder::Decided, inpu
let look = if kind == Kind::Rock { "rock" } else { input.rules.groups[tubes[o.tube].group].look.as_str() };
t.insert("look".into(), look.into());
t.insert("part".into(), kind.name().into());
t.insert("heading".into(), format!("{}", (o.heading() * 1000.0).round() / 1000.0));
t.insert("heading".into(), format!("{}", (n.heading * 1000.0).round() / 1000.0));
t.insert("collar".into(), num(n.collar));
if kind != Kind::Free {
t.insert("face".into(), num(n.face));
Expand All @@ -558,10 +558,11 @@ fn records(tubes: &[Tube], openings: &[Opening], decided: &ladder::Decided, inpu
t.insert("foot".into(), num(n.foot));
t.insert("way".into(), format!("{} {}", o.way[0], o.way[1]));
t.insert("shift".into(), num(o.shift));
if let Some((mate, m)) = n.mate.as_ref().map(|(i, m)| (&openings[*i], *m)) {
if let Some((mate, m, collar)) = n.mate.map(|(i, m, collar)| (&openings[i], m, collar)) {
t.insert("mate".into(), num(m));
t.insert("mate_way".into(), format!("{} {}", mate.way[0], mate.way[1]));
t.insert("mate_shift".into(), num(mate.shift));
t.insert("mate_collar".into(), num(collar));
}
let part = Part { outer: false, points: vec![o.p], z: Some(vec![o.floor]), plan: None };
features.push(("tunnel-end", t, part));
Expand Down
29 changes: 23 additions & 6 deletions host/obc-trailview-features/src/parts/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ fn each_rung_gives_its_kinds_in_the_order_of_the_rungs() {
#[test]
fn a_pair_has_one_frame_line_and_a_way_in_a_wider_tube_has_no_part() {
use Kind::*;
// Two road tunnels 20 m apart under one ridge; the second starts 3 m farther in. A footway 2.5 m beside the first
// lies in its tube.
// Two road tunnels 20 m apart under one ridge, which rises half as fast over the second; the second starts 3 m
// farther in. A footway 2.5 m beside the first lies in its tube.
let mut case = Case::default();
let a = case.tunnel(&ROAD, (0.0, 200.0), 0.0);
let b = case.tunnel(&ROAD, (3.0, 200.0), 20.0);
let foot = case.tunnel(&FOOT, (0.0, 200.0), 2.5);
let placed = case.place(&site(&ridge(200.0, 1.0), &[], false), &mut Vec::new());
let (steep, gentle) = (ridge(200.0, 1.0), ridge(200.0, 0.5));
let ground = |p: [f64; 2]| if p[1] < 10.0 { steep(p) } else { gentle(p) };
let placed = case.place(&site(&ground, &[], false), &mut Vec::new());
assert_eq!(of(&placed, a), vec![(vec![Pair, Arch, Free], "hill"); 2]);
assert_eq!(of(&placed, b), vec![(vec![Pair, Arch, Free], "hill"); 2]);
assert_eq!(of(&placed, foot), vec![(vec![], "same tube"); 2]);
Expand All @@ -223,9 +225,12 @@ fn a_pair_has_one_frame_line_and_a_way_in_a_wider_tube_has_no_part() {
assert_eq!(ends.len(), 2);
let west = ends.iter().find(|t| t["mate"] == "20").expect("the west pair");
assert_eq!((west["part"].as_str(), west["shift"].as_str(), west["mate_shift"].as_str()), ("pair", "3", "0"));
assert!(ends.iter().any(|t| t["mate"] == "-20" && t["shift"] == "0"));
// A pair is not built yet: the device keeps the moved stretch a tunnel, and so does the measure of the numbers.
assert_eq!(placed.metrics["measured_again"].as_u64(), Some(0));
let east = ends.iter().find(|t| t["mate"] == "-20" && t["shift"] == "0").expect("the east pair");
// Each tube has its own collar: the hill over the second comes later, and the first moved 3 m in.
assert_eq!((west["collar"].as_str(), west["mate_collar"].as_str()), ("4", "9"));
assert_eq!((east["collar"].as_str(), east["mate_collar"].as_str()), ("7", "12"));
// A pair is built: the device opens the moved stretch, so the measure reads the four openings near it again.
assert_eq!(placed.metrics["measured_again"].as_u64(), Some(4));
// The first tube widens to the far edge of the footway and its margin.
let foot_half = widths().way("tunnel", &tags(&FOOT), false).half_m;
assert_eq!(west["half"], num(2.5 + foot_half + 0.6));
Expand All @@ -239,6 +244,18 @@ fn a_pair_has_one_frame_line_and_a_way_in_a_wider_tube_has_no_part() {
assert_eq!(of(&placed, a), [(vec![Arch, Free], "hill")]);
assert_eq!(of(&placed, b)[0], (vec![Arch, Free], "hill"));
assert_eq!(placed.metrics["pairs_that_do_not_reach"].as_u64(), Some(1));
// A pair is one part of two chains: where the second chain forks in the hill, so that its end there has no part,
// the two are no pair.
let mut case = Case::default();
let a = case.tunnel(&ROAD, (0.0, 200.0), 0.0);
let b = case.tunnel(&ROAD, (3.0, 200.0), 20.0);
for n in [60.0, -20.0] {
case.ways.push(("tunnel", tags(&ROAD), vec![part(&[[200.0, 20.0], [210.0, n]], &[500.0; 2])]));
}
let placed = case.place(&site(&ridge(200.0, 1.0), &[], false), &mut Vec::new());
assert_eq!(of(&placed, a)[0], (vec![Arch, Free], "hill"));
assert_eq!(of(&placed, b)[0], (vec![Arch, Free], "hill"));
assert_eq!(placed.tags[&b]["parts"], "arch none");
}

#[test]
Expand Down
Loading
Loading