#[macro_use]
pub mod point_traits;
#[cfg(feature = "glam")]
mod glam_conversions;
#[cfg(feature = "mint")]
mod mint_conversions;
#[cfg(feature = "nalgebra")]
mod nalgebra_conversions;
#[cfg(feature = "sdfu")]
mod sdfu_integration;
mod point2;
mod point3;
pub use point2::*;
pub use point3::*;
use point_traits::*;
use core::ops::{Add, AddAssign, Neg, Sub, SubAssign};
use num::{Signed, Zero};
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, Deserialize, Default, Eq, Hash, PartialEq, Serialize)]
pub struct PointN<N>(pub N);
impl<N> PointN<N>
where
Self: MapComponents,
{
#[inline]
pub fn signum(self) -> Self
where
<Self as MapComponents>::Scalar: Signed,
{
self.map_components_unary(|c| c.signum())
}
}
impl<N> Abs for PointN<N>
where
Self: MapComponents,
<Self as MapComponents>::Scalar: Signed,
{
#[inline]
fn abs(self) -> Self {
self.map_components_unary(|c| c.abs())
}
}
impl<N> Neg for PointN<N>
where
Self: Copy + Sub<Output = Self> + Zero,
{
type Output = Self;
#[inline]
fn neg(self) -> Self::Output {
Self::zero() - self
}
}
impl<N, T> Add for PointN<N>
where
Self: MapComponents<Scalar = T>,
T: Add<Output = T>,
{
type Output = Self;
#[inline]
fn add(self, rhs: Self) -> Self::Output {
self.map_components_binary(rhs, |c1, c2| c1 + c2)
}
}
impl<N, T> Sub for PointN<N>
where
Self: MapComponents<Scalar = T>,
T: Sub<Output = T>,
{
type Output = Self;
#[inline]
fn sub(self, rhs: Self) -> Self::Output {
self.map_components_binary(rhs, |c1, c2| c1 - c2)
}
}
impl<N> AddAssign for PointN<N>
where
Self: Copy + Add<Output = Self>,
{
#[inline]
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs;
}
}
impl<N> SubAssign for PointN<N>
where
Self: Copy + Sub<Output = Self>,
{
#[inline]
fn sub_assign(&mut self, rhs: Self) {
*self = *self - rhs;
}
}
impl<N> Zero for PointN<N>
where
Self: Point + ConstZero,
{
#[inline]
fn zero() -> Self {
Self::ZERO
}
#[inline]
fn is_zero(&self) -> bool {
*self == Self::zero()
}
}