use std::fmt;
#[allow(unused_imports)]
use crate::axis::plot::{Plot2D, PlotKey};
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct Coordinate2D {
pub x: f64,
pub y: f64,
pub error_x: Option<f64>,
pub error_y: Option<f64>,
}
impl fmt::Display for Coordinate2D {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({},{})", self.x, self.y)?;
if self.error_x.is_some() || self.error_y.is_some() {
let error_x = self.error_x.unwrap_or(0.0);
let error_y = self.error_y.unwrap_or(0.0);
write!(f, "\t+- ({error_x},{error_y})")?;
}
Ok(())
}
}
impl From<(f64, f64)> for Coordinate2D {
fn from(coordinate: (f64, f64)) -> Self {
Coordinate2D {
x: coordinate.0,
y: coordinate.1,
error_x: None,
error_y: None,
}
}
}
impl From<(f64, f64, Option<f64>, Option<f64>)> for Coordinate2D {
fn from(coordinate: (f64, f64, Option<f64>, Option<f64>)) -> Self {
Coordinate2D {
x: coordinate.0,
y: coordinate.1,
error_x: coordinate.2,
error_y: coordinate.3,
}
}
}
#[cfg(test)]
mod tests;