diff --git a/Cargo.toml b/Cargo.toml index 07491d3..9b6355c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,11 +47,11 @@ typenum = "^1.17.0" # Integrations. [dependencies.cgmath] -version = "^0.17.0" +version = "^0.18.0" optional = true [dependencies.glam] -version = "^0.9.0" +version = "^0.29.0" optional = true [dependencies.mint] @@ -59,11 +59,11 @@ version = "^0.5.0" optional = true [dependencies.nalgebra] -version = "^0.22.0" +version = "^0.33.0" optional = true [dependencies.ultraviolet] -version = "^0.6.0" +version = "^0.9.0" optional = true # Platform-specific features. @@ -78,4 +78,4 @@ features = ["intel-mkl-static"] optional = true [dev-dependencies] -nalgebra = "^0.22.0" +nalgebra = "^0.33.0" diff --git a/src/integration/glam.rs b/src/integration/glam.rs index e4c005a..f863261 100644 --- a/src/integration/glam.rs +++ b/src/integration/glam.rs @@ -93,11 +93,7 @@ impl Basis for Vec2 { } fn canonical_basis_component(index: usize) -> Option { - match index { - 0 => Some(Self::unit_x()), - 1 => Some(Self::unit_y()), - _ => None, - } + Self::AXES.get(index).copied() } } @@ -113,12 +109,7 @@ impl Basis for Vec3 { } fn canonical_basis_component(index: usize) -> Option { - match index { - 0 => Some(Self::unit_x()), - 1 => Some(Self::unit_y()), - 2 => Some(Self::unit_z()), - _ => None, - } + Self::AXES.get(index).copied() } } @@ -134,12 +125,7 @@ impl Basis for Vec3A { } fn canonical_basis_component(index: usize) -> Option { - match index { - 0 => Some(Self::unit_x()), - 1 => Some(Self::unit_y()), - 2 => Some(Self::unit_z()), - _ => None, - } + Self::AXES.get(index).copied() } } @@ -156,13 +142,7 @@ impl Basis for Vec4 { } fn canonical_basis_component(index: usize) -> Option { - match index { - 0 => Some(Self::unit_x()), - 1 => Some(Self::unit_y()), - 2 => Some(Self::unit_z()), - 3 => Some(Self::unit_w()), - _ => None, - } + Self::AXES.get(index).copied() } } @@ -488,14 +468,14 @@ impl Truncate for Vec3A { impl Truncate for Vec4 { fn truncate(self) -> (Vec3, Self::Item) { let z = self.z(); - (self.truncate().into(), z) + (self.truncate(), z) } } impl Truncate for Vec4 { fn truncate(self) -> (Vec3A, Self::Item) { let z = self.z(); - (self.truncate(), z) + (self.truncate().into(), z) } } @@ -515,7 +495,7 @@ impl VectorSpace for Vec2 { } fn zero() -> Self { - Self::zero() + Self::ZERO } } @@ -536,7 +516,7 @@ impl VectorSpace for Vec3 { } fn zero() -> Self { - Self::zero() + Self::ZERO } } @@ -557,7 +537,7 @@ impl VectorSpace for Vec3A { } fn zero() -> Self { - Self::zero() + Self::ZERO } } @@ -565,17 +545,18 @@ impl VectorSpace for Vec4 { type Scalar = f32; fn scalar_component(&self, index: usize) -> Option { + let [x, y, z, w] = self.to_array(); match index { - 0 => Some(self.x()), - 1 => Some(self.y()), - 2 => Some(self.z()), - 3 => Some(self.w()), + 0 => Some(x), + 1 => Some(y), + 2 => Some(z), + 3 => Some(w), _ => None, } } fn zero() -> Self { - Self::zero() + Self::ZERO } } diff --git a/src/integration/nalgebra.rs b/src/integration/nalgebra.rs index 2d76318..6efb038 100644 --- a/src/integration/nalgebra.rs +++ b/src/integration/nalgebra.rs @@ -6,12 +6,12 @@ use nalgebra::base::allocator::Allocator; use nalgebra::base::default_allocator::DefaultAllocator; use nalgebra::base::dimension::{ DimName, DimNameAdd, DimNameDiff, DimNameMax, DimNameMaximum, DimNameMin, DimNameSub, - DimNameSum, U1, + DimNameSum, ToTypenum, U1, }; use nalgebra::base::{ - Matrix2, Matrix3, MatrixMN, RowVector2, RowVector3, Scalar, Vector2, Vector3, Vector4, VectorN, + Matrix2, Matrix3, OMatrix, OVector, RowVector2, RowVector3, Scalar, Vector2, Vector3, Vector4, }; -use nalgebra::geometry::{Point, Point2, Point3}; +use nalgebra::geometry::{OPoint, Point2, Point3}; use num::traits::real::Real; use num::traits::{Num, NumCast, One, Zero}; use std::ops::{AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; @@ -27,21 +27,21 @@ use crate::space::{ }; use crate::{AsPosition, AsPositionMut}; -impl Adjunct for MatrixMN +impl Adjunct for OMatrix where T: Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Item = T; } -impl Basis for VectorN +impl Basis for OVector where T: One + Scalar + Zero, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, Self: FiniteDimensional, { type Bases = Vec; @@ -68,12 +68,12 @@ where } } -impl Converged for MatrixMN +impl Converged for OMatrix where T: Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn converged(value: Self::Item) -> Self { Self::from_element(value) @@ -99,11 +99,11 @@ where } } -impl Dot for VectorN +impl Dot for OVector where T: AddAssign + MulAssign + Num + Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Output = T; @@ -112,51 +112,52 @@ where } } -impl DualSpace for MatrixMN +impl DualSpace for OMatrix where T: AbsDiffEq + AddAssign + MulAssign + NumCast + Real + Scalar, R: DimName + DimNameMin, C: DimName + DimNameMin, - DefaultAllocator: Allocator + Allocator, - MatrixMN: Copy + FiniteDimensional::N>, + DefaultAllocator: Allocator + Allocator, + OMatrix: Copy + FiniteDimensional::N>, Self: Copy + FiniteDimensional, { - type Dual = MatrixMN; + type Dual = OMatrix; fn transpose(self) -> Self::Dual { nalgebra::Matrix::transpose(&self) } } -impl Extend>> for VectorN +impl Extend>> for OVector where T: AddAssign + MulAssign + Real + Scalar, D: DimName + DimNameAdd, - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - fn extend(self, x: T) -> VectorN> { - VectorN::<_, DimNameSum>::from_iterator(self.into_iter().cloned().chain(Some(x))) + fn extend(self, x: T) -> OVector> { + OVector::<_, DimNameSum>::from_iterator(self.into_iter().cloned().chain(Some(x))) } } -impl FiniteDimensional for MatrixMN +impl FiniteDimensional for OMatrix where T: Scalar, R: DimName + DimNameMax + DimNameMin, - as DimName>::Value: NonZero, C: DimName, - DefaultAllocator: Allocator, + DimNameMaximum: ToTypenum, + as ToTypenum>::Typenum: NonZero, + DefaultAllocator: Allocator, { - type N = as DimName>::Value; + type N = as ToTypenum>::Typenum; } -impl Fold for MatrixMN +impl Fold for OMatrix where // TODO: Re-examine adjunct traits that take items by value. T: Clone + Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn fold(self, mut seed: U, mut f: F) -> U where @@ -169,12 +170,12 @@ where } } -impl FromItems for MatrixMN +impl FromItems for OMatrix where T: Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn from_items(items: I) -> Option where @@ -198,26 +199,26 @@ where type ProjectiveSpace = Vector4; } -impl InnerSpace for VectorN +impl InnerSpace for OVector where T: AbsDiffEq + AddAssign + MulAssign + NumCast + Real + Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, Self: Copy, { } -impl Interpolate for MatrixMN +impl Interpolate for OMatrix where T: Num + NumCast + Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Output = Self; fn lerp(self, other: Self, f: R64) -> Self::Output { - MatrixMN::::zip_map(&self, &other, |a, b| crate::lerp(a, b, f)) + OMatrix::::zip_map(&self, &other, |a, b| crate::lerp(a, b, f)) } } @@ -245,21 +246,21 @@ where } } -impl Map for MatrixMN +impl Map for OMatrix where T: Scalar, U: Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator, { - type Output = MatrixMN; + type Output = OMatrix; fn map(self, f: F) -> Self::Output where F: FnMut(Self::Item) -> U, { - MatrixMN::::map(&self, f) + OMatrix::::map(&self, f) } } @@ -367,29 +368,29 @@ where } } -impl Truncate>> for VectorN +impl Truncate>> for OVector where T: Real + Scalar, D: DimName + DimNameSub, - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - fn truncate(self) -> (VectorN>, T) { + fn truncate(self) -> (OVector>, T) { let n = self.len(); let x = *self.get(n - 1).unwrap(); ( - VectorN::<_, DimNameDiff>::from_iterator(self.into_iter().take(n - 1).cloned()), + OVector::<_, DimNameDiff>::from_iterator(self.into_iter().take(n - 1).cloned()), x, ) } } // TODO: This is too general. Only "linear" types should implement this. -impl VectorSpace for MatrixMN +impl VectorSpace for OMatrix where T: AbsDiffEq + AddAssign + MulAssign + NumCast + Real + Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, Self: Copy, { type Scalar = T; @@ -399,49 +400,49 @@ where } } -impl ZipMap for MatrixMN +impl ZipMap for OMatrix where T: Scalar, U: Scalar, R: DimName, C: DimName, - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator, { - type Output = MatrixMN; + type Output = OMatrix; fn zip_map(self, other: Self, f: F) -> Self::Output where F: FnMut(Self::Item, Self::Item) -> U, { - MatrixMN::::zip_map(&self, &other, f) + OMatrix::::zip_map(&self, &other, f) } } -impl Adjunct for Point +impl Adjunct for OPoint where T: Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Item = T; } -impl AffineSpace for Point +impl AffineSpace for OPoint where T: AbsDiffEq + AddAssign + MulAssign + NumCast + Real + Scalar + SubAssign, D: DimName, - DefaultAllocator: Allocator, - >::Buffer: Copy, + DefaultAllocator: Allocator, + >::Buffer: Copy, { - type Translation = VectorN; + type Translation = OVector; } -impl AsPosition for Point +impl AsPosition for OPoint where Self: EuclideanSpace, T: Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Position = Self; @@ -450,54 +451,54 @@ where } } -impl AsPositionMut for Point +impl AsPositionMut for OPoint where Self: EuclideanSpace, T: Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn as_position_mut(&mut self) -> &mut Self::Position { self } } -impl Converged for Point +impl Converged for OPoint where T: Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn converged(value: Self::Item) -> Self { - Point::from(VectorN::::converged(value)) + OPoint::from(OVector::::converged(value)) } } -impl Extend>> for Point +impl Extend>> for OPoint where T: Scalar, D: DimName + DimNameAdd, - DefaultAllocator: Allocator + Allocator>, - VectorN: Adjunct + Extend>>, + DefaultAllocator: Allocator + Allocator>, + OVector: Adjunct + Extend>>, { - fn extend(self, x: T) -> Point> { + fn extend(self, x: T) -> OPoint> { self.coords.extend(x).into() } } -impl EuclideanSpace for Point +impl EuclideanSpace for OPoint where T: AbsDiffEq + AddAssign + MulAssign + NumCast + Real + Scalar + SubAssign, - D: DimName, - D::Value: NonZero, - DefaultAllocator: Allocator, - >::Buffer: Copy, - VectorN: FiniteDimensional, + D: DimName + ToTypenum, + D::Typenum: NonZero, + DefaultAllocator: Allocator, + >::Buffer: Copy, + OVector: FiniteDimensional, { - type CoordinateSpace = VectorN; + type CoordinateSpace = OVector; fn origin() -> Self { - Point::::origin() + OPoint::::origin() } fn into_coordinates(self) -> Self::CoordinateSpace { @@ -505,21 +506,21 @@ where } } -impl FiniteDimensional for Point +impl FiniteDimensional for OPoint where T: Scalar, - D: DimName, - D::Value: NonZero, - DefaultAllocator: Allocator, + D: DimName + ToTypenum, + D::Typenum: NonZero, + DefaultAllocator: Allocator, { - type N = D::Value; + type N = D::Typenum; } -impl Fold for Point +impl Fold for OPoint where T: Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn fold(self, seed: U, f: F) -> U where @@ -529,30 +530,30 @@ where } } -impl FromItems for Point +impl FromItems for OPoint where T: Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { fn from_items(items: I) -> Option where I: IntoIterator, { - Some(Point::from(VectorN::from_iterator(items))) + Some(OPoint::from(OVector::from_iterator(items))) } } -impl Interpolate for Point +impl Interpolate for OPoint where T: Num + NumCast + Scalar, D: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Output = Self; fn lerp(self, other: Self, f: R64) -> Self::Output { - Point::from(self.coords.lerp(other.coords, f)) + OPoint::from(self.coords.lerp(other.coords, f)) } } @@ -580,49 +581,49 @@ where } } -impl Map for Point +impl Map for OPoint where T: Scalar, U: Scalar, D: DimName, - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator, { - type Output = Point; + type Output = OPoint; fn map(self, f: F) -> Self::Output where F: FnMut(Self::Item) -> U, { - Point::from(self.coords.map(f)) + OPoint::from(self.coords.map(f)) } } -impl Truncate>> for Point +impl Truncate>> for OPoint where T: Scalar, D: DimName + DimNameSub, - DefaultAllocator: Allocator + Allocator>, - VectorN: Adjunct + Truncate>>, + DefaultAllocator: Allocator + Allocator>, + OVector: Adjunct + Truncate>>, { - fn truncate(self) -> (Point>, T) { + fn truncate(self) -> (OPoint>, T) { let (vector, x) = self.coords.truncate(); (vector.into(), x) } } -impl ZipMap for Point +impl ZipMap for OPoint where T: Scalar, U: Scalar, D: DimName, - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator, { - type Output = Point; + type Output = OPoint; fn zip_map(self, other: Self, f: F) -> Self::Output where F: FnMut(Self::Item, Self::Item) -> U, { - Point::from(self.coords.zip_map(other.coords, f)) + OPoint::from(self.coords.zip_map(other.coords, f)) } }