use super::*;
#[test]
fn test_georef_local_to_map() {
let mut georef = GeoReference::new();
georef.eastings = 500000.0;
georef.northings = 5000000.0;
georef.orthogonal_height = 100.0;
let (e, n, h) = georef.local_to_map(10.0, 20.0, 5.0);
assert!((e - 500010.0).abs() < 1e-10);
assert!((n - 5000020.0).abs() < 1e-10);
assert!((h - 105.0).abs() < 1e-10);
}
#[test]
fn test_georef_map_to_local() {
let mut georef = GeoReference::new();
georef.eastings = 500000.0;
georef.northings = 5000000.0;
georef.orthogonal_height = 100.0;
let (x, y, z) = georef.map_to_local(500010.0, 5000020.0, 105.0);
assert!((x - 10.0).abs() < 1e-10);
assert!((y - 20.0).abs() < 1e-10);
assert!((z - 5.0).abs() < 1e-10);
}
#[test]
fn test_georef_with_rotation() {
let mut georef = GeoReference::new();
georef.eastings = 0.0;
georef.northings = 0.0;
georef.x_axis_abscissa = 0.0;
georef.x_axis_ordinate = 1.0;
let (e, n, _) = georef.local_to_map(10.0, 0.0, 0.0);
assert!(e.abs() < 1e-10);
assert!((n - 10.0).abs() < 1e-10);
}
#[test]
fn test_georef_local_to_map_rotation_sign_is_a_true_rotation() {
let mut georef = GeoReference::new();
georef.eastings = 0.0;
georef.northings = 0.0;
let c = std::f64::consts::FRAC_1_SQRT_2;
georef.x_axis_abscissa = c;
georef.x_axis_ordinate = c;
let (e, n, _) = georef.local_to_map(10.0, 4.0, 0.0);
assert!((e - c * 6.0).abs() < 1e-10, "e = cos*x - sin*y, got {e}");
assert!((n - c * 14.0).abs() < 1e-10, "n = sin*x + cos*y, got {n}");
}
#[test]
fn test_georef_map_to_local_with_rotation_round_trips_local_to_map() {
let mut georef = GeoReference::new();
georef.eastings = 500000.0;
georef.northings = 4000000.0;
georef.orthogonal_height = 50.0;
georef.scale = 2.0;
let angle = std::f64::consts::FRAC_PI_6; georef.x_axis_abscissa = angle.cos();
georef.x_axis_ordinate = angle.sin();
let (lx, ly, lz) = (12.0, -7.0, 3.0);
let (e, n, h) = georef.local_to_map(lx, ly, lz);
let (x, y, z) = georef.map_to_local(e, n, h);
assert!((x - lx).abs() < 1e-9, "map_to_local must invert local_to_map (x), got {x}");
assert!((y - ly).abs() < 1e-9, "map_to_local must invert local_to_map (y), got {y}");
assert!((z - lz).abs() < 1e-9, "map_to_local must invert local_to_map (z), got {z}");
}
#[test]
fn test_rtc_offset() {
let positions = vec![
500000.0f32,
5000000.0,
0.0,
500010.0,
5000010.0,
10.0,
500020.0,
5000020.0,
20.0,
];
let offset = RtcOffset::from_positions(&positions);
assert!(offset.is_significant());
assert!((offset.x - 500010.0).abs() < 1.0);
assert!((offset.y - 5000010.0).abs() < 1.0);
}
#[test]
fn test_rtc_apply() {
let mut positions = vec![500000.0f32, 5000000.0, 0.0, 500010.0, 5000010.0, 10.0];
let offset = RtcOffset {
x: 500000.0,
y: 5000000.0,
z: 0.0,
};
offset.apply(&mut positions);
assert!((positions[0] - 0.0).abs() < 1e-5);
assert!((positions[1] - 0.0).abs() < 1e-5);
assert!((positions[3] - 10.0).abs() < 1e-5);
assert!((positions[4] - 10.0).abs() < 1e-5);
}
#[test]
fn test_rtc_apply_z_channel_uses_z_offset() {
let mut positions = vec![100.0f32, 200.0, 300.0];
let offset = RtcOffset {
x: 10.0,
y: 20.0,
z: 30.0,
};
offset.apply(&mut positions);
assert!((positions[0] - 90.0).abs() < 1e-5);
assert!((positions[1] - 180.0).abs() < 1e-5);
assert!((positions[2] - 270.0).abs() < 1e-5);
}