oxiproj-transformations 0.1.2

Datum transformations and coordinate conversions for OxiProj.
Documentation
//! `noop` pass-through conversion. Ported from PROJ src/conversions/noop.cpp.

use crate::{TransBuild, TransParams};
use oxiproj_core::{Coord, IoUnits, Operation, ProjResult};

/// The no-op operation: passes every coordinate through unchanged.
#[derive(Debug)]
struct Noop;

impl Operation for Noop {
    fn forward_4d(&self, c: Coord) -> ProjResult<Coord> {
        Ok(c)
    }
    fn inverse_4d(&self, c: Coord) -> ProjResult<Coord> {
        Ok(c)
    }
    fn has_inverse(&self) -> bool {
        true
    }
}

/// Construct the `noop` conversion.
pub fn new(_p: &TransParams) -> ProjResult<TransBuild> {
    Ok(TransBuild::new(
        Box::new(Noop),
        IoUnits::Whatever,
        IoUnits::Whatever,
    ))
}

#[cfg(test)]
mod tests {
    use super::*;
    use oxiproj_core::Coord;

    #[test]
    fn noop_passes_through() -> ProjResult<()> {
        let op = Noop;
        let c = Coord::new(1.0, 2.0, 3.0, 4.0);
        let f = op.forward_4d(c)?;
        assert_eq!(f.v(), [1.0, 2.0, 3.0, 4.0]);
        let r = op.inverse_4d(f)?;
        assert_eq!(r.v(), [1.0, 2.0, 3.0, 4.0]);
        Ok(())
    }
}