use crate::{TransBuild, TransParams};
use oxiproj_core::{IoUnits, Lp, Operation, ProjResult, Xy};
#[derive(Debug)]
struct Geocent;
impl Operation for Geocent {
fn forward_2d(&self, lp: Lp) -> ProjResult<Xy> {
Ok(Xy::new(lp.lam, lp.phi))
}
fn inverse_2d(&self, xy: Xy) -> ProjResult<Lp> {
Ok(Lp::new(xy.x, xy.y))
}
fn has_inverse(&self) -> bool {
true
}
}
pub fn new(_p: &TransParams) -> ProjResult<TransBuild> {
Ok(TransBuild::new(
Box::new(Geocent),
IoUnits::Radians,
IoUnits::Cartesian,
))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::TransParamLookup;
use oxiproj_core::Ellipsoid;
struct NoParams;
impl TransParamLookup for NoParams {
fn get_dms(&self, _key: &str) -> Option<f64> {
None
}
fn get_f64(&self, _key: &str) -> Option<f64> {
None
}
fn get_int(&self, _key: &str) -> Option<i64> {
None
}
fn get_str(&self, _key: &str) -> Option<&str> {
None
}
fn get_bool(&self, _key: &str) -> bool {
false
}
fn exists(&self, _key: &str) -> bool {
false
}
}
#[test]
fn geocent_stub_round_trip() {
let op = Geocent;
let xy = op.forward_2d(Lp::new(0.2, 0.3)).unwrap();
assert!(xy.x == 0.2 && xy.y == 0.3);
let lp = op.inverse_2d(xy).unwrap();
assert!(lp.lam == 0.2 && lp.phi == 0.3);
}
#[test]
fn geocent_build_units() {
let ell = Ellipsoid::named("WGS84").unwrap();
let np = NoParams;
let tp = TransParams {
ellipsoid: &ell,
params: &np,
registry: None,
};
let b = new(&tp);
assert!(b.is_ok());
}
}