oxiproj-core 0.1.2

Foundation types for OxiProj: coordinates, errors, ellipsoids, datums, and units.
Documentation
//! Internal complex number type mirroring PROJ's `COMPLEX` struct.
//!
//! PROJ declares `typedef struct { double r, i; } COMPLEX;` in
//! `src/proj_internal.h`. This module provides a Pure-Rust equivalent so the
//! ecosystem can avoid the `num-complex` dependency. Only the fields and the
//! constructor required by the ported PROJ algorithms are exposed here;
//! arithmetic is added incrementally by the projection modules that need it.

/// Complex number with real part `r` and imaginary part `i`.
///
/// Mirrors PROJ's `COMPLEX { double r, i; }` (declared in
/// `src/proj_internal.h`).
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Complex {
    /// Real part.
    pub r: f64,
    /// Imaginary part.
    pub i: f64,
}

impl Complex {
    /// Construct a complex number `r + i*j`. Mirrors PROJ's `COMPLEX { double r, i; }`.
    pub const fn new(r: f64, i: f64) -> Complex {
        Complex { r, i }
    }
}

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

    #[test]
    fn new_sets_real_and_imaginary() {
        let z = Complex::new(1.0, 2.0);
        assert!(z.r == 1.0);
        assert!(z.i == 2.0);
    }
}