use super::*;
fn model_rtc(anchor: (f64, f64, f64)) -> RenderFrameRebase {
RenderFrameRebase::from_frame(MeshFrame::ModelRtc { anchor })
}
const OFFSET: (f64, f64, f64) = (12_050.0, -14_530.0, 407.0);
#[test]
fn each_axis_is_rebased_by_its_own_component() {
let rebase = model_rtc(OFFSET);
let (x, y) = rebase.plan(12_000.0, -14_500.0);
assert!((x - -50.0).abs() < 1e-3, "x: {x}");
assert!((y - -30.0).abs() < 1e-3, "y2d: {y}");
assert!(
(rebase.elevation(400.0) - -7.0).abs() < 1e-3,
"elevation: {}",
rebase.elevation(400.0)
);
}
#[test]
fn the_plan_flip_reverses_the_northing_axis() {
let rebase = model_rtc(OFFSET);
let south = rebase.plan(12_000.0, -14_600.0).1;
let north = rebase.plan(12_000.0, -14_400.0).1;
assert!(
south > north,
"expected the flip to reverse northing, got south={south} north={north}"
);
}
#[test]
fn a_raw_ifc_frame_is_not_rebased() {
let rebase = RenderFrameRebase::from_frame(MeshFrame::RawIfc);
assert_eq!(rebase, RenderFrameRebase::default());
let (x, y) = rebase.plan(3.5, -7.25);
assert!((x - 3.5).abs() < 1e-6, "x: {x}");
assert!((y - 7.25).abs() < 1e-6, "y2d: {y}");
assert!((rebase.elevation(2.75) - 2.75).abs() < 1e-6);
}
#[test]
fn a_sub_threshold_anchor_is_subtracted() {
let rebase = model_rtc((8_500.0, 0.0, 0.0));
let (x, _) = rebase.plan(2_000.0, 0.0);
assert!((x - -6_500.0).abs() < 1e-3, "x: {x}");
}
#[test]
fn every_anchor_component_is_subtracted() {
let rebase = model_rtc((12_050.0, 30.0, 7.0));
let (_, y) = rebase.plan(0.0, 0.0);
assert!((y - 30.0).abs() < 1e-3, "y2d: {y}");
assert!((rebase.elevation(0.0) - -7.0).abs() < 1e-3);
}
#[test]
fn plan_does_not_emit_negative_zero_for_a_zero_northing() {
let identity = RenderFrameRebase::from_frame(MeshFrame::RawIfc);
let (_, y) = identity.plan(3.5, 0.0);
assert_eq!(y, 0.0);
assert!(
!y.is_sign_negative(),
"a zero northing produced -0.0; the pinned symbolic goldens distinguish it",
);
let (_, flipped) = identity.plan(0.0, 4.0);
assert_eq!(flipped, -4.0);
}