use std::fmt::Debug;
use std::hash::Hash;
use std::ops::{Add, Sub};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Serialize, Deserialize)]
pub struct Point2d<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> {
pub x: T,
pub y: T,
}
impl Hash for Point2d<f64> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
let xbits = if self.x.is_nan() {
f64::NAN.to_bits()
} else {
self.x.to_bits()
};
let ybits = if self.y.is_nan() {
f64::NAN.to_bits()
} else {
self.y.to_bits()
};
xbits.hash(state);
ybits.hash(state);
}
}
#[derive(
Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash, Serialize, Deserialize,
)]
pub struct Point3d<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> {
pub x: T,
pub y: T,
pub z: T,
}
impl<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> Point2d<T> {
pub const fn new(x: T, y: T) -> Self {
Self { x, y }
}
pub const fn x(&self) -> T {
self.x
}
pub const fn y(&self) -> T {
self.y
}
}
impl<T: Copy + PartialOrd + PartialEq + Debug + Add + Sub> Point3d<T> {
pub const fn new(x: T, y: T, z: T) -> Self {
Self { x, y, z }
}
pub const fn x(&self) -> T {
self.x
}
pub const fn y(&self) -> T {
self.y
}
pub const fn z(&self) -> T {
self.z
}
}