facett-demo/tests/osm3d_wall_proportion.rs
//! **The OSM-3D tab's houses must be houses, on the REAL data.**
//!
//! `facett-map3d/tests/wall_roof_ratio.rs` pins the proportion rule on a synthetic
//! untagged town. This one runs it on the *actual* scene the demo's `OSM 3D` tab
//! builds — the embedded Sigtuna GeoParquet, cropped to the town core exactly as
//! `osm3d_view` does — because that is the surface the owner was looking at when he
//! reported "the houses' walls have been enlarged and the roofs look like they lean
//! directly on the ground".
//!
//! The measured before/after on this exact scene (182 buildings, all untagged):
//!
//! | quantity | before | after |
//! |---|---:|---:|
//! | buildings taller than they are long | 77 | 0 |
//! | worst wall / footprint long side | 1.77 | 0.90 |
//! | median wall / footprint long side | 0.83 | 0.72 |
//! | median roof rise / wall | 0.36 | 0.41 |
use facett_demo::osm_tabs::{crop_to_town_core, load_sigtuna, osm3d_view};
use facett_map3d::extrude::building_height_stats;
/// The exact way set `osm_tabs::osm3d_view` extrudes.
fn demo_scene_ways() -> Vec<facett_map::Way> {
let geo = load_sigtuna().expect("the embedded Sigtuna GeoParquet decodes");
let core = crop_to_town_core(&geo.ways_3d, 400.0);
if core.len() >= 20 { core } else { geo.ways_3d.clone() }
}
/// **RED-when-broken on real data.** Not one building in the demo's 3D city may be
/// taller than its own footprint is long.
#[test]
fn the_demo_city_has_no_building_taller_than_it_is_long() {
let ways = demo_scene_ways();
let s = building_height_stats(&ways, 3.0);
assert!(s.buildings > 100, "the town core extrudes a real city, got {}", s.buildings);
// The premise of the whole bug: this extract is essentially untagged, so every
// one of these walls comes from the DEFAULT height rule.
assert!(
s.defaulted * 10 > s.buildings * 9,
"≥90% of this city's buildings are untagged ({} of {}) — the default height rule \
is what shapes it",
s.defaulted,
s.buildings
);
assert_eq!(
s.taller_than_long, 0,
"{} of {} buildings in the demo's OSM 3D city are TALLER THAN THEY ARE LONG \
(worst wall/footprint {:.2}) — walls that swallow their roofs",
s.taller_than_long, s.buildings, s.wall_over_footprint_max
);
assert!(
s.wall_over_footprint_median < 0.85,
"the median house is wider than it is tall, got {:.3}",
s.wall_over_footprint_median
);
assert!(
s.roof_over_wall_median > 0.30,
"the median roof is a real share of the building, got {:.3}",
s.roof_over_wall_median
);
}
/// The same property, read back through the pane's own `state_json` — so a robot /
/// matrix driver sees it without reaching into the extruder.
#[test]
fn the_proportion_is_observable_from_the_panes_state() {
use facett_core::Facet;
let geo = load_sigtuna().expect("sigtuna");
let m = osm3d_view(&geo);
let sj = m.state_json();
let sky = &sj["skyline"];
assert!(sky["buildings"].as_u64().unwrap() > 100, "the tab extruded a city");
assert_eq!(sky["taller_than_long"].as_u64().unwrap(), 0, "no wall swallows its roof");
assert!(sky["wall_over_footprint_max"].as_f64().unwrap() <= 0.9001);
}