#![allow(dead_code)]
use mgrs_convert::UtmUps;
pub fn read_tsv(name: &str) -> Vec<Vec<String>> {
let path = format!("{}/tests/vectors/{name}", env!("CARGO_MANIFEST_DIR"));
let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {path}: {e}"));
text.lines()
.filter(|l| !l.starts_with('#') && !l.is_empty())
.map(|l| l.split('\t').map(str::to_owned).collect())
.collect()
}
pub fn parse_utm_triplet(s: &str) -> (u8, bool, f64, f64) {
let toks: Vec<&str> = s.split_whitespace().collect();
assert_eq!(toks.len(), 3, "not a UTM/UPS triplet: {s}");
let zh = toks[0];
let north = zh.ends_with('n');
let zone: u8 = zh[..zh.len() - 1].parse().unwrap_or(0);
(
zone,
north,
toks[1].parse().expect("easting"),
toks[2].parse().expect("northing"),
)
}
pub fn utmups_from_input(s: &str) -> Result<UtmUps, mgrs_convert::Error> {
let (zone, north, e, n) = parse_utm_triplet(s);
if zone == 0 {
UtmUps::ups(north, e, n)
} else {
UtmUps::utm(zone, north, e, n)
}
}
pub fn ground_distance_m(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 {
let dlat = lat1 - lat2;
let mut dlon = (lon1 - lon2).rem_euclid(360.0);
if dlon > 180.0 {
dlon -= 360.0;
}
let dlon_scaled = dlon * lat1.to_radians().cos();
dlat.hypot(dlon_scaled) * 111_700.0
}