#[cfg(feature = "lin")]
use crate::Vector;
use crate::{Point, Point2d, Point3d, Points};
#[rustfmt::skip]
impl<T, const D: usize> Point<T, D> {
pub const fn new(coords: [T; D]) -> Self { Self { coords } }
#[must_use] #[cfg(feature = "lin")] #[cfg_attr(nightly_doc, doc(cfg(feature = "lin")))]
pub fn into_vector(self) -> Vector<T, D> { Vector::new(self.coords) }
#[must_use] #[cfg(feature = "lin")] #[cfg_attr(nightly_doc, doc(cfg(feature = "lin")))]
pub const fn to_vector(self) -> Vector<T, D> where T: Copy { Vector::new(self.coords) }
#[cfg(feature = "lin")] #[cfg_attr(nightly_doc, doc(cfg(feature = "lin")))]
pub fn from_vector(v: Vector<T, D>) -> Self { Self::new(v.coords) }
#[cfg(feature = "lin")] #[cfg_attr(nightly_doc, doc(cfg(feature = "lin")))]
pub const fn from_vector_const(v: Vector<T, D>) -> Self where T: Copy { Self::new(v.coords) }
}
#[rustfmt::skip]
impl<T> Point2d<T> {
#[must_use] pub const fn x(self) -> T where T: Copy { self.coords[0] }
#[must_use] pub const fn y(self) -> T where T: Copy { self.coords[1] }
#[must_use] pub const fn x_ref(&self) -> &T { &self.coords[0] }
#[must_use] pub const fn y_ref(&self) -> &T { &self.coords[1] }
#[must_use] pub const fn x_mut(&mut self) -> &mut T { &mut self.coords[0] }
#[must_use] pub const fn y_mut(&mut self) -> &mut T { &mut self.coords[1] }
}
#[rustfmt::skip]
impl<T> Point3d<T> {
#[must_use] pub const fn x(self) -> T where T: Copy { self.coords[0] }
#[must_use] pub const fn y(self) -> T where T: Copy { self.coords[1] }
#[must_use] pub const fn z(self) -> T where T: Copy { self.coords[2] }
#[must_use] pub const fn x_ref(&self) -> &T { &self.coords[0] }
#[must_use] pub const fn y_ref(&self) -> &T { &self.coords[1] }
#[must_use] pub const fn z_ref(&self) -> &T { &self.coords[2] }
#[must_use] pub const fn x_mut(&mut self) -> &mut T { &mut self.coords[0] }
#[must_use] pub const fn y_mut(&mut self) -> &mut T { &mut self.coords[1] }
#[must_use] pub const fn z_mut(&mut self) -> &mut T { &mut self.coords[2] }
}
macro_rules! impl_point {
() => {
impl_point![sint i8, i16, i32, i64, i128, isize];
impl_point![uint u8, u16, u32, u64, u128, usize];
impl_point![float f32, f64];
};
(int $($t:ty),+) => { $( impl_point![@int $t]; )+ };
(@int $t:ty) => {
impl<const D: usize> Point<$t, D> {
#[cfg(feature = "lin")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "lin")))]
pub const fn c_add_vector(self, v: Vector<$t, D>) -> Self {
Self { coords: Vector::new(self.coords).c_add(v).coords }
}
}
};
(sint $($t:ty),+) => { $( impl_point![@sint $t]; )+ };
(@sint $t:ty) => {
impl_point![int $t];
};
(uint $($t:ty),+) => { $( impl_point![@uint $t]; )+ };
(@uint $t:ty) => {
impl_point![int $t];
};
(float $( $f:ty),+) => { $( impl_point![@float $f]; )+ };
(@float $f:ty) => {
impl<const D: usize> Point<$f, D> {
}
};
}
impl_point!();
#[rustfmt::skip]
impl<T, const D: usize, const N: usize> Points<T, D, N> {
pub const fn new(points: [Point<T, D>; N]) -> Self { Self { array: points } }
}