base_2 0.1.0

Exact fixed-point geometry. Float in, float out, zero drift inside.
Documentation
//! Exact 2D and 3D point types.

use crate::coord::{Coord, CoordInt};

/// A point in 3D space. Three exact coordinates, no approximation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Point3<T: CoordInt> {
    /// X coordinate.
    pub x: Coord<T>,
    /// Y coordinate.
    pub y: Coord<T>,
    /// Z coordinate.
    pub z: Coord<T>,
}

/// A point in 2D space.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Point2<T: CoordInt> {
    /// X coordinate.
    pub x: Coord<T>,
    /// Y coordinate.
    pub y: Coord<T>,
}

impl<T: CoordInt> Point3<T> {
    /// Construct a point from three exact coordinates.
    pub const fn new(x: Coord<T>, y: Coord<T>, z: Coord<T>) -> Self {
        Self { x, y, z }
    }

    /// The origin — (0, 0, 0).
    #[must_use]
    pub const fn origin() -> Self {
        Self { x: Coord::ZERO, y: Coord::ZERO, z: Coord::ZERO }
    }
}

impl<T: CoordInt> Point2<T> {
    /// Construct a point from two exact coordinates.
    pub const fn new(x: Coord<T>, y: Coord<T>) -> Self {
        Self { x, y }
    }

    /// The origin — (0, 0).
    #[must_use]
    pub const fn origin() -> Self {
        Self { x: Coord::ZERO, y: Coord::ZERO }
    }
}