use bone_types::{Length, Parameter, Point2};

#[derive(Copy, Clone, Debug, PartialEq)]
pub struct ClosestPoint2 {
    parameter: Parameter,
    point: Point2,
    distance: Length,
}

impl ClosestPoint2 {
    #[must_use]
    pub const fn new(parameter: Parameter, point: Point2, distance: Length) -> Self {
        Self {
            parameter,
            point,
            distance,
        }
    }

    #[must_use]
    pub const fn parameter(self) -> Parameter {
        self.parameter
    }

    #[must_use]
    pub const fn point(self) -> Point2 {
        self.point
    }

    #[must_use]
    pub const fn distance(self) -> Length {
        self.distance
    }
}

impl core::fmt::Display for ClosestPoint2 {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        use uom::si::length::millimeter;
        write!(
            f,
            "closest{{ t={}, p={}, d={} mm }}",
            self.parameter.value(),
            self.point,
            self.distance.get::<millimeter>(),
        )
    }
}
