facett-demo/tests/osm3d_street_tour.rs
//! **facett-demo OSM-3D tab — the street-level tour proof** (headless, no window).
//!
//! The user reported that `facett-demo`'s 3D map tour "seems to have a similar tour
//! but the walk doesn't go down to street level" — unlike `sigtuna_demo`, which
//! descends to a street chase. The tab used to auto-play the framed **flythrough**
//! (which orbits the city HIGH and never lands); it now flies the SAME shared
//! [`facett_map3d::SigtunaTour`] the `sigtuna_demo` bin does (air-circle → descend →
//! drive the streets), reusing `osm_tabs::street_route` for the drive path (L5).
//!
//! This proves — as DATA off the live render camera, no GPU, no window — that the tab
//! the demo actually ships (`osm_tabs::osm3d_view(load())`):
//! 1. flies an active tour with a real street route attached,
//! 2. walks Circle → Descend → Drive across the loop,
//! 3. genuinely DESCENDS bird → street (air distance ≫ street distance, and the
//! drive sits at a real ~street-level metre distance from the road), and
//! 4. the houses are VISIBLE at the air-circle (`buildings_visible > 0`).
//!
//! RED when broken: revert the tab to the framed flythrough (no descent, no route) and
//! `has_route` / the descent ratio / the street-level metre bound all fail.
#![cfg(not(target_arch = "wasm32"))]
use facett_demo::osm_tabs;
use facett_map3d::TourPhase;
#[test]
fn osm3d_tab_tour_descends_to_street_level_and_sees_the_houses() {
// The EXACT object the demo's OSM-3D tab is built from (real embedded Sigtuna, or
// the liechtenstein/env fixture when present) — build it the way `DemoState::new`
// does, then fly it headlessly.
let geo = osm_tabs::load();
eprintln!("[osm3d-tour] source={:?} ways_3d={}", geo.source, geo.ways_3d.len());
let mut map = osm_tabs::osm3d_view(&geo);
// (1) The shipped tab flies an ACTIVE tour with a real street route to follow.
assert!(map.tour_active(), "the OSM-3D tab auto-plays the cinematic tour");
assert!(map.has_route(), "the drive phase has a real street route (the descend chase target)");
let mpu = map.metres_per_design_unit(); // real metres per design unit for the scene
// (2)+(3) Walk the whole loop and read the camera at each phase.
let total = 18.0 + 8.0 + 26.0; // SigtunaTour default circle+descend+drive seconds
let (mut circle, mut descend, mut drive) = (false, false, false);
let mut air_dist = 0.0f32;
let mut street_dist = f32::INFINITY;
let mut circle_houses = 0usize;
// "Between the houses": the best drive sample where buildings flank BOTH sides of
// the forward axis (the car-nav on-street oracle the owner asked for — houses on the
// left AND the right at the same street segment).
let mut best_both_sides = 0usize;
for i in 0..=160 {
let t = i as f64 * total / 160.0;
map.set_clock(t);
match map.tour_phase().expect("active tour → a phase at every clock") {
TourPhase::Circle => {
circle = true;
circle_houses = circle_houses.max(map.buildings_visible());
air_dist = air_dist.max(map.render_camera().distance);
}
TourPhase::Descend => descend = true,
TourPhase::Drive => {
drive = true;
street_dist = street_dist.min(map.render_camera().distance);
let (l, r) = map.flanking_houses();
best_both_sides = best_both_sides.max(l.min(r)); // both sides ⇒ min > 0
}
}
}
let street_m = street_dist * mpu;
let air_m = air_dist * mpu;
eprintln!(
"[osm3d-tour] mpu={mpu:.0} circle={circle} descend={descend} drive={drive} \
air_m={air_m:.0} street_m={street_m:.0} circle_houses={circle_houses} both_sides={best_both_sides}"
);
// The tour walks all three legs …
assert!(circle && descend && drive, "the tab tour walks circle → descend → drive");
// … and genuinely descends bird → street: the drive sits at street level (a real
// car-nav metre distance, NOT the regional 100s-of-metres the flythrough held) …
assert!(street_m < 90.0, "the drive rides the street at street level ({street_m:.0} m from the road)");
assert!(air_m > street_m * 3.0, "the tour descends bird → street (air {air_m:.0} m ≫ street {street_m:.0} m)");
// … and (4) the houses are in frame at the air-circle ("SEE THE HOUSES").
assert!(circle_houses > 0, "the houses are visible circling from the air ({circle_houses} risen verts in frame)");
// … and (5) the drive runs BETWEEN THE HOUSES — at some street segment the buildings
// flank BOTH sides of the forward axis (the owner's "run ON the streets, between the
// houses" — not drifting outside the town or facing backward into open ground).
assert!(
best_both_sides > 0,
"the drive runs down the street with houses on BOTH sides (best both-sides count {best_both_sides})"
);
// Determinism (FC-7): the same clock ⇒ the same pose.
map.set_clock(9.0);
let a = map.render_camera().eye();
map.set_clock(9.0);
let b = map.render_camera().eye();
assert_eq!(a, b, "the tour pose is a pure function of the clock");
#[cfg(feature = "testmatrix")]
{
let ok = circle && descend && drive && street_m < 90.0 && air_m > street_m * 3.0
&& circle_houses > 0 && best_both_sides > 0 && a == b;
facett_core::testmatrix::emit(
"facett-demo",
"osm3d_street_tour",
ok,
&format!(
"source={:?} circle={circle} descend={descend} drive={drive} air_m={air_m:.0} \
street_m={street_m:.0} circle_houses={circle_houses} both_sides={best_both_sides}",
geo.source
),
);
}
}