building_blocks_core/
point.rs1#[macro_use]
2pub mod point_traits;
3
4#[cfg(feature = "glam")]
5mod glam_conversions;
6#[cfg(feature = "mint")]
7mod mint_conversions;
8#[cfg(feature = "nalgebra")]
9mod nalgebra_conversions;
10#[cfg(feature = "sdfu")]
11mod sdfu_integration;
12
13mod point2;
14mod point3;
15
16pub use point2::*;
17pub use point3::*;
18
19use point_traits::*;
20
21use core::ops::{Add, AddAssign, Neg, Sub, SubAssign};
22use num::{Signed, Zero};
23use serde::{Deserialize, Serialize};
24
25#[derive(Copy, Clone, Debug, Deserialize, Default, Eq, Hash, PartialEq, Serialize)]
70pub struct PointN<N>(pub N);
71
72impl<N> PointN<N>
73where
74 Self: MapComponents,
75{
76 #[inline]
77 pub fn signum(self) -> Self
78 where
79 <Self as MapComponents>::Scalar: Signed,
80 {
81 self.map_components_unary(|c| c.signum())
82 }
83}
84
85impl<N> Abs for PointN<N>
86where
87 Self: MapComponents,
88 <Self as MapComponents>::Scalar: Signed,
89{
90 #[inline]
91 fn abs(self) -> Self {
92 self.map_components_unary(|c| c.abs())
93 }
94}
95
96impl<N> Neg for PointN<N>
97where
98 Self: Copy + Sub<Output = Self> + Zero,
99{
100 type Output = Self;
101
102 #[inline]
103 fn neg(self) -> Self::Output {
104 Self::zero() - self
105 }
106}
107
108impl<N, T> Add for PointN<N>
109where
110 Self: MapComponents<Scalar = T>,
111 T: Add<Output = T>,
112{
113 type Output = Self;
114
115 #[inline]
116 fn add(self, rhs: Self) -> Self::Output {
117 self.map_components_binary(rhs, |c1, c2| c1 + c2)
118 }
119}
120
121impl<N, T> Sub for PointN<N>
122where
123 Self: MapComponents<Scalar = T>,
124 T: Sub<Output = T>,
125{
126 type Output = Self;
127
128 #[inline]
129 fn sub(self, rhs: Self) -> Self::Output {
130 self.map_components_binary(rhs, |c1, c2| c1 - c2)
131 }
132}
133
134impl<N> AddAssign for PointN<N>
135where
136 Self: Copy + Add<Output = Self>,
137{
138 #[inline]
139 fn add_assign(&mut self, rhs: Self) {
140 *self = *self + rhs;
141 }
142}
143
144impl<N> SubAssign for PointN<N>
145where
146 Self: Copy + Sub<Output = Self>,
147{
148 #[inline]
149 fn sub_assign(&mut self, rhs: Self) {
150 *self = *self - rhs;
151 }
152}
153
154impl<N> Zero for PointN<N>
155where
156 Self: Point + ConstZero,
157{
158 #[inline]
159 fn zero() -> Self {
160 Self::ZERO
161 }
162
163 #[inline]
164 fn is_zero(&self) -> bool {
165 *self == Self::zero()
166 }
167}