facett-map3d/tests/flanking_houses_are_houses_you_can_see.rs
//! **`hus3d-1`'s residue: the car-nav "am I driving between the houses?" oracle was a
//! count of geometry that EXISTS, and could not tell a street from a pancake.**
//!
//! `mapdrive-15` was fixed and `buildings_visible` came back **340 581** with every claim
//! in `prove.sh` §5 passing — over a screenshot that is a flat white pancake, because the
//! scene spanned 55.7 km and the median house stood **0.66 px**. `skyline_screen_height_px`
//! was added to answer that, and it did. The entry's residue is that the fleet has MORE
//! oracles of the same shape, and named `flanking_houses` (`houses_left`/`houses_right`)
//! as the sharpest of them: it is the claim "houses line the road on either hand", it is
//! asserted by robot drives, and at 0.66 px it answers yes.
//!
//! This is that oracle's separating power, MEASURED at two scene spans of the SAME town:
//! the band count says the same thing at both, the pixel count does not.
mod common;
use facett_map3d::Map3D;
/// The two ends of the defect: the town on its own (houses resolvable) and the same town
/// inside a region extract (houses sub-pixel), framed by the shipped camera fitter.
fn framed(span_m: f64) -> Map3D {
let ways = common::region_with_town(span_m, 24);
// `from_ways` deliberately, NOT `from_geometry`: the town subset is what fixes the
// region case, and this guard has to be able to SEE the unfixed one.
let mut map = Map3D::from_ways("drive", &ways, 0.22);
map.frame_densest_cluster();
map
}
#[test]
fn the_flanking_oracle_can_tell_a_street_from_a_pancake() {
const VIEWPORT_PX: f32 = 1150.0; // the drive's real Xvfb window height
let mut rows = Vec::new();
for (label, span_m) in [("town", 2_400.0), ("region", 55_700.0)] {
let map = framed(span_m);
let (bl, br) = map.flanking_houses();
let (pl, pr) = map.flanking_houses_resolvable(VIEWPORT_PX);
let skyline = map.skyline_screen_height_px(VIEWPORT_PX);
println!(
" {label:<8} span {span_m:7.0} m m/du {:8.0} band ({bl:5}, {br:5}) \
resolvable ({pl:5}, {pr:5}) median wall {skyline:6.2} px",
map.metres_per_design_unit()
);
rows.push((label, bl, br, pl, pr, skyline));
}
let (_, t_bl, t_br, t_pl, t_pr, t_px) = rows[0];
let (_, r_bl, r_br, r_pl, r_pr, r_px) = rows[1];
// The premise: the region scene really is the pancake. If this fails the fixture
// stopped reproducing the defect and everything below is vacuous.
assert!(
r_px < Map3D::RESOLVABLE_WALL_PX,
"the region fixture must actually draw sub-pixel houses, got {r_px:.2} px — this \
guard has nothing to separate"
);
assert!(t_px >= 3.0, "…and the town fixture must actually draw a skyline, got {t_px:.2} px");
// THE BLIND ORACLE — recorded, not asserted as desirable: the band count answers
// "houses on both sides" in the pancake exactly as confidently as in the street.
assert!(
r_bl > 0 && r_br > 0,
"the band oracle is supposed to be BLIND here ({r_bl}, {r_br}) — if it went to zero \
on its own, the pixel oracle below is not the thing that fixed it"
);
// THE ONE THAT CAN SEE: houses you can resolve, at the same pose.
assert!(
t_pl > 0 && t_pr > 0,
"the town has resolvable houses on both hands, got ({t_pl}, {t_pr})"
);
assert_eq!(
(r_pl, r_pr),
(0, 0),
"the region pancake has NO resolvable house beside the car, but the pixel oracle \
reported ({r_pl}, {r_pr}) — it is counting geometry again"
);
// …and the separating power stated as one number, so a future regression that
// narrows it shows up as a ratio and not as a boolean.
println!(
" separating power: band {}x vs resolvable {}x (town/region)",
if r_bl + r_br > 0 { format!("{:.2}", (t_bl + t_br) as f32 / (r_bl + r_br) as f32) } else { "inf".into() },
if r_pl + r_pr > 0 { format!("{:.2}", (t_pl + t_pr) as f32 / (r_pl + r_pr) as f32) } else { "inf".into() }
);
assert!(
t_bl + t_br > 0,
"the town's band count is non-zero, so the band ratio above is a real comparison"
);
}
/// The resolvable count is a SUBSET of the band count, at every scale — the two answer
/// the same question about the same band, and only the pixel test may remove anything.
/// Without this, `flanking_houses_resolvable` could "pass" the guard above by counting
/// something else entirely.
#[test]
fn the_pixel_oracle_only_ever_removes_from_the_band() {
for span_m in [2_400.0, 8_000.0, 55_700.0] {
let map = framed(span_m);
let (bl, br) = map.flanking_houses();
let (pl, pr) = map.flanking_houses_resolvable(1150.0);
println!(" span {span_m:7.0} m band ({bl:5}, {br:5}) resolvable ({pl:5}, {pr:5})");
assert!(pl <= bl && pr <= br, "the pixel oracle added houses the band never had");
}
}
/// A viewport twice as tall resolves walls half as tall — so the oracle really is
/// reading PIXELS, not a constant dressed as one. Swept on the scene where it bites.
#[test]
fn the_pixel_oracle_reads_the_viewport() {
let map = framed(55_700.0);
let mut last = 0usize;
let mut moved = false;
for h in [1_150.0f32, 11_500.0, 115_000.0] {
let (pl, pr) = map.flanking_houses_resolvable(h);
let px = map.skyline_screen_height_px(h);
println!(" viewport {h:9.0} px median wall {px:8.2} px resolvable ({pl:5}, {pr:5})");
if pl + pr > last {
moved = true;
}
last = pl + pr;
}
assert!(
moved,
"blowing the viewport up 100x did not admit a single house — the oracle is not \
reading the viewport at all"
);
}