#[cfg(feature = "serde")]
use serde::{de::DeserializeOwned, Serialize};
mod impl_array;
#[cfg(feature = "cgmath")]
mod impl_cgmath;
#[cfg(feature = "glam")]
mod impl_glam;
#[cfg(feature = "mint")]
mod impl_mint;
mod impl_nalgebra;
pub trait Point: Sized + Copy + Sync + Send + core::fmt::Debug + PartialEq {
#[cfg(feature = "serde")]
type Serde: Serialize + DeserializeOwned;
#[must_use]
fn new(x: f32, y: f32, z: f32) -> Self;
#[must_use]
fn x(&self) -> f32;
#[must_use]
fn y(&self) -> f32;
#[must_use]
fn z(&self) -> f32;
fn x_mut(&mut self) -> &mut f32;
fn y_mut(&mut self) -> &mut f32;
fn z_mut(&mut self) -> &mut f32;
#[must_use]
fn get(&self, i: usize) -> f32 {
match i {
0 => self.x(),
1 => self.y(),
2 => self.z(),
_ => panic!("Index out of bounds"),
}
}
#[must_use]
fn add(&self, other: &Self) -> Self {
Self::new(
self.x() + other.x(),
self.y() + other.y(),
self.z() + other.z(),
)
}
#[must_use]
fn sub(&self, other: &Self) -> Self {
Self::new(
self.x() - other.x(),
self.y() - other.y(),
self.z() - other.z(),
)
}
#[must_use]
fn dot(&self, other: &Self) -> f32 {
self.x() * other.x() + self.y() * other.y() + self.z() * other.z()
}
#[must_use]
fn cross(&self, other: &Self) -> Self {
Self::new(
self.y() * other.z() - self.z() * other.y(),
self.z() * other.x() - self.x() * other.z(),
self.x() * other.y() - self.y() * other.x(),
)
}
#[must_use]
fn length(&self) -> f32 {
self.dot(self).sqrt()
}
#[must_use]
fn dist(&self, other: &Self) -> f32 {
self.sub(other).length()
}
#[must_use]
fn dist2(&self, other: &Self) -> f32 {
let diff = self.sub(other);
diff.dot(&diff)
}
#[must_use]
fn fmul(&self, other: f32) -> Self {
Self::new(self.x() * other, self.y() * other, self.z() * other)
}
#[must_use]
fn comp_div(&self, other: &Self) -> Self {
Self::new(
self.x() / other.x(),
self.y() / other.y(),
self.z() / other.z(),
)
}
}