diff --git a/CHANGELOG.md b/CHANGELOG.md index 956ba534..f8058703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ documented here. This project adheres to [Semantic Versioning](https://semver.org/). +## [0.28.0] +### Modified +- The `Point::new` constructors are no longer const-fn. This is due to some limitations in const-fn + not allowing custom trait-bounds. Use the `point!` macro instead to build points in const environments. + ## [0.27.1] ### Fixed - Fixed a bug in the conversion from `glam::Vec2` or `glam::DVec2` to `Isometry2`. diff --git a/src/geometry/point.rs b/src/geometry/point.rs index d25b4d7c..d4d9dbfc 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -17,7 +17,7 @@ use simba::simd::SimdPartialOrd; use crate::base::allocator::Allocator; use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use crate::base::iter::{MatrixIter, MatrixIterMut}; -use crate::base::{Const, DefaultAllocator, OVector, SVector, Scalar}; +use crate::base::{Const, DefaultAllocator, OVector, Scalar}; /// A point in an euclidean space. /// @@ -40,35 +40,53 @@ use crate::base::{Const, DefaultAllocator, OVector, SVector, Scalar}; /// of said transformations for details. #[repr(C)] #[derive(Debug, Clone)] -pub struct Point { +pub struct OPoint +where + DefaultAllocator: Allocator, +{ /// The coordinates of this point, i.e., the shift from the origin. - pub coords: SVector, + pub coords: OVector, } -impl hash::Hash for Point { +impl hash::Hash for OPoint +where + DefaultAllocator: Allocator, +{ fn hash(&self, state: &mut H) { self.coords.hash(state) } } -impl Copy for Point {} - -#[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Point where - SVector: bytemuck::Zeroable +impl Copy for OPoint +where + DefaultAllocator: Allocator, + OVector: Copy, { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Point +unsafe impl bytemuck::Zeroable for OPoint +where + OVector: bytemuck::Zeroable, + DefaultAllocator: Allocator, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for OPoint where T: Copy, - SVector: bytemuck::Pod, + OVector: bytemuck::Pod, + DefaultAllocator: Allocator, { } #[cfg(feature = "serde-serialize-no-std")] -impl Serialize for Point { +impl Serialize for OPoint +where + DefaultAllocator: Allocator, + >::Buffer: Serialize, +{ fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -78,22 +96,27 @@ impl Serialize for Point { } #[cfg(feature = "serde-serialize-no-std")] -impl<'a, T: Scalar + Deserialize<'a>, const D: usize> Deserialize<'a> for Point { +impl<'a, T: Scalar + Deserialize<'a>, D: DimName> Deserialize<'a> for OPoint +where + DefaultAllocator: Allocator, + >::Buffer: Deserialize<'a>, +{ fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let coords = SVector::::deserialize(deserializer)?; + let coords = OVector::::deserialize(deserializer)?; Ok(Self::from(coords)) } } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Point +impl Abomonation for OPoint where T: Scalar, - SVector: Abomonation, + OVector: Abomonation, + DefaultAllocator: Allocator, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -108,7 +131,10 @@ where } } -impl Point { +impl OPoint +where + DefaultAllocator: Allocator, +{ /// Returns a point containing the result of `f` applied to each of its entries. /// /// # Example @@ -123,7 +149,10 @@ impl Point { /// ``` #[inline] #[must_use] - pub fn map T2>(&self, f: F) -> Point { + pub fn map T2>(&self, f: F) -> OPoint + where + DefaultAllocator: Allocator, + { self.coords.map(f).into() } @@ -163,20 +192,21 @@ impl Point { /// ``` #[inline] #[must_use] - pub fn to_homogeneous(&self) -> OVector, U1>> + pub fn to_homogeneous(&self) -> OVector> where T: One, - Const: DimNameAdd, - DefaultAllocator: Allocator, U1>>, + D: DimNameAdd, + DefaultAllocator: Allocator>, { let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!( - , U1> as DimName>::name(), + as DimName>::name(), Const::<1> ) }; - res.fixed_slice_mut::(0, 0).copy_from(&self.coords); - res[(D, 0)] = T::one(); + res.generic_slice_mut((0, 0), (D::name(), Const::<1>)) + .copy_from(&self.coords); + res[(D::dim(), 0)] = T::one(); res } @@ -184,7 +214,7 @@ impl Point { /// Creates a new point with the given coordinates. #[deprecated(note = "Use Point::from(vector) instead.")] #[inline] - pub fn from_coordinates(coords: SVector) -> Self { + pub fn from_coordinates(coords: OVector) -> Self { Self { coords } } @@ -243,8 +273,7 @@ impl Point { #[inline] pub fn iter( &self, - ) -> MatrixIter, Const<1>, >>::Buffer> - { + ) -> MatrixIter, >::Buffer> { self.coords.iter() } @@ -270,8 +299,7 @@ impl Point { #[inline] pub fn iter_mut( &mut self, - ) -> MatrixIterMut, Const<1>, >>::Buffer> - { + ) -> MatrixIterMut, >::Buffer> { self.coords.iter_mut() } @@ -289,9 +317,10 @@ impl Point { } } -impl AbsDiffEq for Point +impl AbsDiffEq for OPoint where T::Epsilon: Copy, + DefaultAllocator: Allocator, { type Epsilon = T::Epsilon; @@ -306,9 +335,10 @@ where } } -impl RelativeEq for Point +impl RelativeEq for OPoint where T::Epsilon: Copy, + DefaultAllocator: Allocator, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -327,9 +357,10 @@ where } } -impl UlpsEq for Point +impl UlpsEq for OPoint where T::Epsilon: Copy, + DefaultAllocator: Allocator, { #[inline] fn default_max_ulps() -> u32 { @@ -342,16 +373,22 @@ where } } -impl Eq for Point {} +impl Eq for OPoint where DefaultAllocator: Allocator {} -impl PartialEq for Point { +impl PartialEq for OPoint +where + DefaultAllocator: Allocator, +{ #[inline] fn eq(&self, right: &Self) -> bool { self.coords == right.coords } } -impl PartialOrd for Point { +impl PartialOrd for OPoint +where + DefaultAllocator: Allocator, +{ #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.coords.partial_cmp(&other.coords) @@ -381,25 +418,28 @@ impl PartialOrd for Point { /* * inf/sup */ -impl Point { +impl OPoint +where + DefaultAllocator: Allocator, +{ /// Computes the infimum (aka. componentwise min) of two points. #[inline] #[must_use] - pub fn inf(&self, other: &Self) -> Point { + pub fn inf(&self, other: &Self) -> OPoint { self.coords.inf(&other.coords).into() } /// Computes the supremum (aka. componentwise max) of two points. #[inline] #[must_use] - pub fn sup(&self, other: &Self) -> Point { + pub fn sup(&self, other: &Self) -> OPoint { self.coords.sup(&other.coords).into() } /// Computes the (infimum, supremum) of two points. #[inline] #[must_use] - pub fn inf_sup(&self, other: &Self) -> (Point, Point) { + pub fn inf_sup(&self, other: &Self) -> (OPoint, OPoint) { let (inf, sup) = self.coords.inf_sup(&other.coords); (inf.into(), sup.into()) } @@ -410,7 +450,10 @@ impl Point { * Display * */ -impl fmt::Display for Point { +impl fmt::Display for OPoint +where + DefaultAllocator: Allocator, +{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{{")?; diff --git a/src/geometry/point_alias.rs b/src/geometry/point_alias.rs index 54441b09..f5f855c9 100644 --- a/src/geometry/point_alias.rs +++ b/src/geometry/point_alias.rs @@ -1,4 +1,8 @@ -use crate::geometry::Point; +use crate::geometry::OPoint; +use crate::Const; + +/// A point with `D` elements. +pub type Point = OPoint>; /// A statically sized 1-dimensional column point. /// diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 7e34137c..0ffbf4d8 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -10,22 +10,26 @@ use rand::{ use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{DefaultAllocator, SVector, Scalar}; +use crate::base::{DefaultAllocator, Scalar}; use crate::{ - Const, OVector, Point1, Point2, Point3, Point4, Point5, Point6, Vector1, Vector2, Vector3, - Vector4, Vector5, Vector6, + Const, DimName, OPoint, OVector, Point1, Point2, Point3, Point4, Point5, Point6, Vector1, + Vector2, Vector3, Vector4, Vector5, Vector6, }; use simba::scalar::{ClosedDiv, SupersetOf}; use crate::geometry::Point; /// # Other construction methods -impl Point { +impl OPoint +where + DefaultAllocator: Allocator, +{ /// Creates a new point with uninitialized coordinates. #[inline] pub unsafe fn new_uninitialized() -> Self { Self::from(crate::unimplemented_or_uninitialized_generic!( - Const::, Const::<1> + D::name(), + Const::<1> )) } @@ -49,7 +53,7 @@ impl Point { where T: Zero, { - Self::from(SVector::from_element(T::zero())) + Self::from(OVector::from_element(T::zero())) } /// Creates a new point from a slice. @@ -68,7 +72,7 @@ impl Point { /// ``` #[inline] pub fn from_slice(components: &[T]) -> Self { - Self::from(SVector::from_row_slice(components)) + Self::from(OVector::from_row_slice(components)) } /// Creates a new point from its homogeneous vector representation. @@ -102,14 +106,15 @@ impl Point { /// assert_eq!(pt, Some(Point2::new(1.0, 2.0))); /// ``` #[inline] - pub fn from_homogeneous(v: OVector, U1>>) -> Option + pub fn from_homogeneous(v: OVector>) -> Option where T: Scalar + Zero + One + ClosedDiv, - Const: DimNameAdd, - DefaultAllocator: Allocator, U1>>, + D: DimNameAdd, + DefaultAllocator: Allocator>, { - if !v[D].is_zero() { - let coords = v.fixed_slice::(0, 0) / v[D].inlined_clone(); + if !v[D::dim()].is_zero() { + let coords = + v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].inlined_clone(); Some(Self::from(coords)) } else { None @@ -125,9 +130,10 @@ impl Point { /// let pt2 = pt.cast::(); /// assert_eq!(pt2, Point2::new(1.0f32, 2.0)); /// ``` - pub fn cast(self) -> Point + pub fn cast(self) -> OPoint where - Point: SupersetOf, + OPoint: SupersetOf, + DefaultAllocator: Allocator, { crate::convert(self) } @@ -138,38 +144,43 @@ impl Point { * Traits that build points. * */ -impl Bounded for Point { +impl Bounded for OPoint +where + DefaultAllocator: Allocator, +{ #[inline] fn max_value() -> Self { - Self::from(SVector::max_value()) + Self::from(OVector::max_value()) } #[inline] fn min_value() -> Self { - Self::from(SVector::min_value()) + Self::from(OVector::min_value()) } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where Standard: Distribution, + DefaultAllocator: Allocator, { /// Generate a `Point` where each coordinate is an independent variate from `[0, 1)`. #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Point { - Point::from(rng.gen::>()) + fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> OPoint { + OPoint::from(rng.gen::>()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Point +impl Arbitrary for OPoint where - >>::Buffer: Send, + >::Buffer: Send, + DefaultAllocator: Allocator, { #[inline] fn arbitrary(g: &mut Gen) -> Self { - Self::from(SVector::arbitrary(g)) + Self::from(OVector::arbitrary(g)) } } @@ -181,7 +192,7 @@ where // NOTE: the impl for Point1 is not with the others so that we // can add a section with the impl block comment. /// # Construction from individual components -impl Point1 { +impl Point1 { /// Initializes this point from its components. /// /// # Example @@ -192,7 +203,7 @@ impl Point1 { /// assert_eq!(p.x, 1.0); /// ``` #[inline] - pub const fn new(x: T) -> Self { + pub fn new(x: T) -> Self { Point { coords: Vector1::new(x), } @@ -200,13 +211,13 @@ impl Point1 { } macro_rules! componentwise_constructors_impl( ($($doc: expr; $Point: ident, $Vector: ident, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl $Point { + impl $Point { #[doc = "Initializes this point from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] #[inline] - pub const fn new($($args: T),*) -> Self { + pub fn new($($args: T),*) -> Self { Point { coords: $Vector::new($($args),*) } } } diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index e5ab8272..f35a9fc6 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -7,6 +7,7 @@ use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::{Const, DefaultAllocator, Matrix, OVector, Scalar}; use crate::geometry::Point; +use crate::{DimName, OPoint}; /* * This file provides the following conversions: @@ -16,67 +17,69 @@ use crate::geometry::Point; * Point -> Vector (homogeneous) */ -impl SubsetOf> for Point +impl SubsetOf> for OPoint where T1: Scalar, T2: Scalar + SupersetOf, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn to_superset(&self) -> Point { - Point::from(self.coords.to_superset()) + fn to_superset(&self) -> OPoint { + OPoint::from(self.coords.to_superset()) } #[inline] - fn is_in_subset(m: &Point) -> bool { + fn is_in_subset(m: &OPoint) -> bool { // TODO: is there a way to reuse the `.is_in_subset` from the matrix implementation of // SubsetOf? m.iter().all(|e| e.is_in_subset()) } #[inline] - fn from_superset_unchecked(m: &Point) -> Self { + fn from_superset_unchecked(m: &OPoint) -> Self { Self::from(Matrix::from_superset_unchecked(&m.coords)) } } -impl SubsetOf, U1>>> for Point +impl SubsetOf>> for OPoint where - Const: DimNameAdd, + D: DimNameAdd, T1: Scalar, T2: Scalar + Zero + One + ClosedDiv + SupersetOf, - DefaultAllocator: - Allocator, U1>> + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator> + + Allocator>, // + Allocator // + Allocator, { #[inline] - fn to_superset(&self) -> OVector, U1>> { - let p: Point = self.to_superset(); + fn to_superset(&self) -> OVector> { + let p: OPoint = self.to_superset(); p.to_homogeneous() } #[inline] - fn is_in_subset(v: &OVector, U1>>) -> bool { - crate::is_convertible::<_, OVector, U1>>>(v) && !v[D].is_zero() + fn is_in_subset(v: &OVector>) -> bool { + crate::is_convertible::<_, OVector>>(v) && !v[D::dim()].is_zero() } #[inline] - fn from_superset_unchecked(v: &OVector, U1>>) -> Self { - let coords = v.fixed_slice::(0, 0) / v[D].inlined_clone(); + fn from_superset_unchecked(v: &OVector>) -> Self { + let coords = v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].inlined_clone(); Self { coords: crate::convert_unchecked(coords), } } } -impl From> - for OVector, U1>> +impl From> for OVector> where - Const: DimNameAdd, - DefaultAllocator: Allocator, U1>>, + D: DimNameAdd, + DefaultAllocator: Allocator> + Allocator, { #[inline] - fn from(t: Point) -> Self { + fn from(t: OPoint) -> Self { t.to_homogeneous() } } @@ -97,10 +100,13 @@ impl From> for [T; D] { } } -impl From>> for Point { +impl From> for OPoint +where + DefaultAllocator: Allocator, +{ #[inline] - fn from(coords: OVector>) -> Self { - Point { coords } + fn from(coords: OVector) -> Self { + OPoint { coords } } } diff --git a/src/geometry/point_coordinates.rs b/src/geometry/point_coordinates.rs index 8d9e9ccc..984a2fae 100644 --- a/src/geometry/point_coordinates.rs +++ b/src/geometry/point_coordinates.rs @@ -1,9 +1,9 @@ use std::ops::{Deref, DerefMut}; use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB}; -use crate::base::Scalar; +use crate::base::{Scalar, U1, U2, U3, U4, U5, U6}; -use crate::geometry::Point; +use crate::geometry::OPoint; /* * @@ -12,8 +12,8 @@ use crate::geometry::Point; */ macro_rules! deref_impl( - ($D: expr, $Target: ident $(, $comps: ident)*) => { - impl Deref for Point + ($D: ty, $Target: ident $(, $comps: ident)*) => { + impl Deref for OPoint { type Target = $Target; @@ -23,7 +23,7 @@ macro_rules! deref_impl( } } - impl DerefMut for Point + impl DerefMut for OPoint { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { @@ -33,9 +33,9 @@ macro_rules! deref_impl( } ); -deref_impl!(1, X, x); -deref_impl!(2, XY, x, y); -deref_impl!(3, XYZ, x, y, z); -deref_impl!(4, XYZW, x, y, z, w); -deref_impl!(5, XYZWA, x, y, z, w, a); -deref_impl!(6, XYZWAB, x, y, z, w, a, b); +deref_impl!(U1, X, x); +deref_impl!(U2, XY, x, y); +deref_impl!(U3, XYZ, x, y, z); +deref_impl!(U4, XYZW, x, y, z, w); +deref_impl!(U5, XYZWA, x, y, z, w, a); +deref_impl!(U6, XYZWAB, x, y, z, w, a, b); diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index 576028cc..5b019a9d 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -8,18 +8,23 @@ use simba::scalar::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub}; use crate::base::constraint::{ AreMultipliable, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint, }; -use crate::base::dimension::{Dim, U1}; +use crate::base::dimension::{Dim, DimName, U1}; use crate::base::storage::Storage; -use crate::base::{Const, Matrix, SVector, Scalar, Vector}; +use crate::base::{Const, Matrix, OVector, Scalar, Vector}; -use crate::geometry::Point; +use crate::allocator::Allocator; +use crate::geometry::{OPoint, Point}; +use crate::DefaultAllocator; /* * * Indexing. * */ -impl Index for Point { +impl Index for OPoint +where + DefaultAllocator: Allocator, +{ type Output = T; #[inline] @@ -28,7 +33,10 @@ impl Index for Point { } } -impl IndexMut for Point { +impl IndexMut for OPoint +where + DefaultAllocator: Allocator, +{ #[inline] fn index_mut(&mut self, i: usize) -> &mut Self::Output { &mut self.coords[i] @@ -40,7 +48,10 @@ impl IndexMut for Point { * Neg. * */ -impl Neg for Point { +impl Neg for OPoint +where + DefaultAllocator: Allocator, +{ type Output = Self; #[inline] @@ -49,8 +60,11 @@ impl Neg for Point { } } -impl<'a, T: Scalar + ClosedNeg, const D: usize> Neg for &'a Point { - type Output = Point; +impl<'a, T: Scalar + ClosedNeg, D: DimName> Neg for &'a OPoint +where + DefaultAllocator: Allocator, +{ + type Output = OPoint; #[inline] fn neg(self) -> Self::Output { @@ -66,102 +80,103 @@ impl<'a, T: Scalar + ClosedNeg, const D: usize> Neg for &'a Point { // Point - Point add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) -> (Const, U1) - const D; for; where; - self: &'a Point, right: &'b Point, Output = SVector; + (D, U1), (D, U1) -> (D, U1) + const; for D; where D: DimName, DefaultAllocator: Allocator; + self: &'a OPoint, right: &'b OPoint, Output = OVector; &self.coords - &right.coords; 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) -> (Const, U1) - const D; for; where; - self: &'a Point, right: Point, Output = SVector; + (D, U1), (D, U1) -> (D, U1) + const; for D; where D: DimName, DefaultAllocator: Allocator; + self: &'a OPoint, right: OPoint, Output = OVector; &self.coords - right.coords; 'a); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) -> (Const, U1) - const D; for; where; - self: Point, right: &'b Point, Output = SVector; + (D, U1), (D, U1) -> (D, U1) + const; for D; where D: DimName, DefaultAllocator: Allocator; + self: OPoint, right: &'b OPoint, Output = OVector; self.coords - &right.coords; 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (Const, U1) -> (Const, U1) - const D; for; where; - self: Point, right: Point, Output = SVector; + (D, U1), (D, U1) -> (D, U1) + const; for D; where D: DimName, DefaultAllocator: Allocator; + self: OPoint, right: OPoint, Output = OVector; self.coords - right.coords; ); // Point - Vector add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: &'b Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: &'a OPoint, right: &'b Vector, Output = OPoint; Self::Output::from(&self.coords - right); 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: &'a OPoint, right: Vector, Output = OPoint; Self::Output::from(&self.coords - &right); 'a); // TODO: should not be a ref to `right`. add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: &'b Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: OPoint, right: &'b Vector, Output = OPoint; Self::Output::from(self.coords - right); 'b); add_sub_impl!(Sub, sub, ClosedSub; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: OPoint, right: Vector, Output = OPoint; Self::Output::from(self.coords - right); ); // Point + Vector add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: &'b Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: &'a OPoint, right: &'b Vector, Output = OPoint; Self::Output::from(&self.coords + right); 'a, 'b); add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: &'a OPoint, right: Vector, Output = OPoint; Self::Output::from(&self.coords + &right); 'a); // TODO: should not be a ref to `right`. add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: &'b Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: OPoint, right: &'b Vector, Output = OPoint; Self::Output::from(self.coords + right); 'b); add_sub_impl!(Add, add, ClosedAdd; - (Const, U1), (D2, U1) -> (Const, U1) - const D1; - for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: Vector, Output = Point; + (D1, U1), (D2, U1) -> (D1, U1) + const; + for D1, D2, SB; + where D1: DimName, D2: Dim, SB: Storage, DefaultAllocator: Allocator; + self: OPoint, right: Vector, Output = OPoint; Self::Output::from(self.coords + right); ); // TODO: replace by the shared macro: add_sub_assign_impl? macro_rules! op_assign_impl( ($($TraitAssign: ident, $method_assign: ident, $bound: ident);* $(;)*) => {$( - impl<'b, T, D2: Dim, SB, const D1: usize> $TraitAssign<&'b Vector> for Point + impl<'b, T, D1: DimName, D2: Dim, SB> $TraitAssign<&'b Vector> for OPoint where T: Scalar + $bound, SB: Storage, - ShapeConstraint: SameNumberOfRows, D2> { + ShapeConstraint: SameNumberOfRows, + DefaultAllocator: Allocator { #[inline] fn $method_assign(&mut self, right: &'b Vector) { @@ -169,10 +184,11 @@ macro_rules! op_assign_impl( } } - impl $TraitAssign> for Point + impl $TraitAssign> for OPoint where T: Scalar + $bound, SB: Storage, - ShapeConstraint: SameNumberOfRows, D2> { + ShapeConstraint: SameNumberOfRows, + DefaultAllocator: Allocator { #[inline] fn $method_assign(&mut self, right: Vector) { @@ -214,28 +230,30 @@ md_impl_all!( macro_rules! componentwise_scalarop_impl( ($Trait: ident, $method: ident, $bound: ident; $TraitAssign: ident, $method_assign: ident) => { - impl $Trait for Point + impl $Trait for OPoint + where DefaultAllocator: Allocator { - type Output = Point; + type Output = OPoint; #[inline] fn $method(self, right: T) -> Self::Output { - Point::from(self.coords.$method(right)) + OPoint::from(self.coords.$method(right)) } } - impl<'a, T: Scalar + $bound, const D: usize> $Trait for &'a Point + impl<'a, T: Scalar + $bound, D: DimName> $Trait for &'a OPoint + where DefaultAllocator: Allocator { - type Output = Point; + type Output = OPoint; #[inline] fn $method(self, right: T) -> Self::Output { - Point::from((&self.coords).$method(right)) + OPoint::from((&self.coords).$method(right)) } } - impl $TraitAssign for Point - /* where DefaultAllocator: Allocator */ + impl $TraitAssign for OPoint + where DefaultAllocator: Allocator { #[inline] fn $method_assign(&mut self, right: T) { @@ -250,23 +268,25 @@ componentwise_scalarop_impl!(Div, div, ClosedDiv; DivAssign, div_assign); macro_rules! left_scalar_mul_impl( ($($T: ty),* $(,)*) => {$( - impl Mul> for $T + impl Mul> for $T + where DefaultAllocator: Allocator<$T, D> { - type Output = Point<$T, D>; + type Output = OPoint<$T, D>; #[inline] - fn mul(self, right: Point<$T, D>) -> Self::Output { - Point::from(self * right.coords) + fn mul(self, right: OPoint<$T, D>) -> Self::Output { + OPoint::from(self * right.coords) } } - impl<'b, const D: usize> Mul<&'b Point<$T, D>> for $T + impl<'b, D: DimName> Mul<&'b OPoint<$T, D>> for $T + where DefaultAllocator: Allocator<$T, D> { - type Output = Point<$T, D>; + type Output = OPoint<$T, D>; #[inline] - fn mul(self, right: &'b Point<$T, D>) -> Self::Output { - Point::from(self * &right.coords) + fn mul(self, right: &'b OPoint<$T, D>) -> Self::Output { + OPoint::from(self * &right.coords) } } )*}