use crate::{constants::*, XyzGeodetic};
#[derive(Clone, Copy, Debug, Default)]
#[allow(clippy::upper_case_acronyms)]
pub struct ENH {
pub e: f64,
pub n: f64,
pub h: f64,
}
impl ENH {
pub fn to_xyz(self, latitude_rad: f64) -> XyzGeodetic {
let (s_lat, c_lat) = latitude_rad.sin_cos();
Self::to_xyz_inner(self, s_lat, c_lat)
}
pub fn to_xyz_inner(self, sin_latitude: f64, cos_latitude: f64) -> XyzGeodetic {
XyzGeodetic {
x: -self.n * sin_latitude + self.h * cos_latitude,
y: self.e,
z: self.n * cos_latitude + self.h * sin_latitude,
}
}
pub fn to_xyz_mwa(self) -> XyzGeodetic {
self.to_xyz(MWA_LAT_RAD)
}
}
#[cfg(test)]
mod tests {
use super::*;
use approx::*;
#[test]
fn convert_enh_to_xyz_test() {
let enh = ENH {
n: -101.530,
e: -585.675,
h: 375.212,
};
let xyz = ENH::to_xyz_mwa(enh);
assert_abs_diff_eq!(xyz.x, 289.56928486613185, epsilon = 1e-10);
assert_abs_diff_eq!(xyz.y, -585.675, epsilon = 1e-10);
assert_abs_diff_eq!(xyz.z, -259.3106536687549, epsilon = 1e-10);
}
}