From af127633cc097504792836e129fc4a52687547f0 Mon Sep 17 00:00:00 2001 From: Shane Pearman Date: Sun, 25 Jul 2021 06:22:06 -0700 Subject: [PATCH] Replace use of BaseFloat/Float with BaseNum/Num where possible --- src/angle.rs | 24 ++++++++++++------------ src/matrix.rs | 14 +++++++------- src/point.rs | 2 +- src/quaternion.rs | 36 ++++++++++++++++++------------------ src/rotation.rs | 4 ++-- src/structure.rs | 6 +++--- src/vector.rs | 4 ++-- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/angle.rs b/src/angle.rs index 9f08422..18e9f01 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -30,7 +30,7 @@ use rand::{ use structure::*; use approx; -use num::BaseFloat; +use num::{BaseFloat, BaseNum}; /// An angle, in radians. /// @@ -138,38 +138,38 @@ macro_rules! impl_angle { } } - impl_operator!( Add<$Angle > for $Angle { + impl_operator!( Add<$Angle > for $Angle { fn add(lhs, rhs) -> $Angle { $Angle(lhs.0 + rhs.0) } }); - impl_operator!( Sub<$Angle > for $Angle { + impl_operator!( Sub<$Angle > for $Angle { fn sub(lhs, rhs) -> $Angle { $Angle(lhs.0 - rhs.0) } }); - impl_operator!( Div<$Angle > for $Angle { + impl_operator!( Div<$Angle > for $Angle { fn div(lhs, rhs) -> S { lhs.0 / rhs.0 } }); - impl_operator!( Rem<$Angle > for $Angle { + impl_operator!( Rem<$Angle > for $Angle { fn rem(lhs, rhs) -> $Angle { $Angle(lhs.0 % rhs.0) } }); - impl_assignment_operator!( AddAssign<$Angle > for $Angle { + impl_assignment_operator!( AddAssign<$Angle > for $Angle { fn add_assign(&mut self, other) { self.0 += other.0; } }); - impl_assignment_operator!( SubAssign<$Angle > for $Angle { + impl_assignment_operator!( SubAssign<$Angle > for $Angle { fn sub_assign(&mut self, other) { self.0 -= other.0; } }); - impl_assignment_operator!( RemAssign<$Angle > for $Angle { + impl_assignment_operator!( RemAssign<$Angle > for $Angle { fn rem_assign(&mut self, other) { self.0 %= other.0; } }); - impl_operator!( Mul for $Angle { + impl_operator!( Mul for $Angle { fn mul(lhs, scalar) -> $Angle { $Angle(lhs.0 * scalar) } }); - impl_operator!( Div for $Angle { + impl_operator!( Div for $Angle { fn div(lhs, scalar) -> $Angle { $Angle(lhs.0 / scalar) } }); - impl_assignment_operator!( MulAssign for $Angle { + impl_assignment_operator!( MulAssign for $Angle { fn mul_assign(&mut self, scalar) { self.0 *= scalar; } }); - impl_assignment_operator!( DivAssign for $Angle { + impl_assignment_operator!( DivAssign for $Angle { fn div_assign(&mut self, scalar) { self.0 /= scalar; } }); diff --git a/src/matrix.rs b/src/matrix.rs index 7a591be..90e2a2b 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -30,7 +30,7 @@ use structure::*; use angle::Rad; use approx; use euler::Euler; -use num::BaseFloat; +use num::{BaseFloat, BaseNum}; use point::{Point2, Point3}; use quaternion::Quaternion; use transform::{Transform, Transform2, Transform3}; @@ -1569,7 +1569,7 @@ mint_conversions!(Matrix3 { x, y, z }, ColumnMatrix3); #[cfg(feature = "mint")] mint_conversions!(Matrix4 { x, y, z, w }, ColumnMatrix4); -impl From> for Matrix3 { +impl From> for Matrix3 { /// Clone the elements of a 2-dimensional matrix into the top-left corner /// of a 3-dimensional identity matrix. fn from(m: Matrix2) -> Matrix3 { @@ -1582,7 +1582,7 @@ impl From> for Matrix3 { } } -impl From> for Matrix4 { +impl From> for Matrix4 { /// Clone the elements of a 2-dimensional matrix into the top-left corner /// of a 4-dimensional identity matrix. fn from(m: Matrix2) -> Matrix4 { @@ -1596,7 +1596,7 @@ impl From> for Matrix4 { } } -impl From> for Matrix4 { +impl From> for Matrix4 { /// Clone the elements of a 3-dimensional matrix into the top-left corner /// of a 4-dimensional identity matrix. fn from(m: Matrix3) -> Matrix4 { @@ -1678,7 +1678,7 @@ impl fmt::Debug for Matrix4 { impl Distribution> for Standard where Standard: Distribution>, - S: BaseFloat, + S: BaseNum, { #[inline] fn sample(&self, rng: &mut R) -> Matrix2 { @@ -1693,7 +1693,7 @@ where impl Distribution> for Standard where Standard: Distribution>, - S: BaseFloat, + S: BaseNum, { #[inline] fn sample(&self, rng: &mut R) -> Matrix3 { @@ -1709,7 +1709,7 @@ where impl Distribution> for Standard where Standard: Distribution>, - S: BaseFloat, + S: BaseNum, { #[inline] fn sample(&self, rng: &mut R) -> Matrix4 { diff --git a/src/point.rs b/src/point.rs index f8ffbc7..b65c334 100644 --- a/src/point.rs +++ b/src/point.rs @@ -154,7 +154,7 @@ macro_rules! impl_point { } } - impl MetricSpace for $PointN { + impl MetricSpace for $PointN { type Metric = S; #[inline] diff --git a/src/quaternion.rs b/src/quaternion.rs index 3ab37ee..036bf23 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -29,7 +29,7 @@ use angle::Rad; use approx; use euler::Euler; use matrix::{Matrix3, Matrix4}; -use num::BaseFloat; +use num::{BaseFloat, BaseNum}; use point::Point3; use quaternion; use rotation::{Basis3, Rotation, Rotation3}; @@ -410,7 +410,7 @@ impl approx::UlpsEq for Quaternion { } } -impl From> for Matrix3 { +impl From> for Matrix3 { /// Convert the quaternion to a 3 x 3 rotation matrix. fn from(quat: Quaternion) -> Matrix3 { let x2 = quat.v.x + quat.v.x; @@ -438,7 +438,7 @@ impl From> for Matrix3 { } } -impl From> for Matrix4 { +impl From> for Matrix4 { /// Convert the quaternion to a 4 x 4 rotation matrix. fn from(quat: Quaternion) -> Matrix4 { let x2 = quat.v.x + quat.v.x; @@ -534,7 +534,7 @@ impl Rotation3 for Quaternion { } } -impl From> for [S; 4] { +impl From> for [S; 4] { #[inline] fn from(v: Quaternion) -> Self { let (xi, yj, zk, w) = v.into(); @@ -542,42 +542,42 @@ impl From> for [S; 4] { } } -impl AsRef<[S; 4]> for Quaternion { +impl AsRef<[S; 4]> for Quaternion { #[inline] fn as_ref(&self) -> &[S; 4] { unsafe { &*(self as *const quaternion::Quaternion as *const [S; 4]) } } } -impl AsMut<[S; 4]> for Quaternion { +impl AsMut<[S; 4]> for Quaternion { #[inline] fn as_mut(&mut self) -> &mut [S; 4] { unsafe { &mut *(self as *mut quaternion::Quaternion as *mut [S; 4]) } } } -impl From<[S; 4]> for Quaternion { +impl From<[S; 4]> for Quaternion { #[inline] fn from(v: [S; 4]) -> Quaternion { Quaternion::new(v[3], v[0], v[1], v[2]) } } -impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion { +impl<'a, S: BaseNum> From<&'a [S; 4]> for &'a Quaternion { #[inline] fn from(v: &'a [S; 4]) -> &'a Quaternion { unsafe { &*(v as *const [S; 4] as *const quaternion::Quaternion) } } } -impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion { +impl<'a, S: BaseNum> From<&'a mut [S; 4]> for &'a mut Quaternion { #[inline] fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion { unsafe { &mut *(v as *mut [S; 4] as *mut quaternion::Quaternion) } } } -impl From> for (S, S, S, S) { +impl From> for (S, S, S, S) { #[inline] fn from(v: Quaternion) -> Self { let Quaternion { @@ -588,21 +588,21 @@ impl From> for (S, S, S, S) { } } -impl AsRef<(S, S, S, S)> for Quaternion { +impl AsRef<(S, S, S, S)> for Quaternion { #[inline] fn as_ref(&self) -> &(S, S, S, S) { unsafe { &*(self as *const quaternion::Quaternion as *const (S, S, S, S)) } } } -impl AsMut<(S, S, S, S)> for Quaternion { +impl AsMut<(S, S, S, S)> for Quaternion { #[inline] fn as_mut(&mut self) -> &mut (S, S, S, S) { unsafe { &mut *(self as *mut quaternion::Quaternion as *mut (S, S, S, S)) } } } -impl From<(S, S, S, S)> for Quaternion { +impl From<(S, S, S, S)> for Quaternion { #[inline] fn from(v: (S, S, S, S)) -> Quaternion { let (xi, yj, zk, w) = v; @@ -610,14 +610,14 @@ impl From<(S, S, S, S)> for Quaternion { } } -impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion { +impl<'a, S: BaseNum> From<&'a (S, S, S, S)> for &'a Quaternion { #[inline] fn from(v: &'a (S, S, S, S)) -> &'a Quaternion { unsafe { &*(v as *const (S, S, S, S) as *const quaternion::Quaternion) } } } -impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion { +impl<'a, S: BaseNum> From<&'a mut (S, S, S, S)> for &'a mut Quaternion { #[inline] fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion { unsafe { &mut *(v as *mut (S, S, S, S) as *mut quaternion::Quaternion) } @@ -626,7 +626,7 @@ impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion { macro_rules! index_operators { ($S:ident, $Output:ty, $I:ty) => { - impl<$S: BaseFloat> Index<$I> for Quaternion<$S> { + impl<$S: BaseNum> Index<$I> for Quaternion<$S> { type Output = $Output; #[inline] @@ -636,7 +636,7 @@ macro_rules! index_operators { } } - impl<$S: BaseFloat> IndexMut<$I> for Quaternion<$S> { + impl<$S: BaseNum> IndexMut<$I> for Quaternion<$S> { #[inline] fn index_mut<'a>(&'a mut self, i: $I) -> &'a mut $Output { let v: &mut [$S; 4] = self.as_mut(); @@ -657,7 +657,7 @@ impl Distribution> for Standard where Standard: Distribution, Standard: Distribution>, - S: BaseFloat, + S: BaseNum, { #[inline] fn sample(&self, rng: &mut R) -> Quaternion { diff --git a/src/rotation.rs b/src/rotation.rs index ae5a7d5..e3f2b60 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -23,7 +23,7 @@ use angle::Rad; use approx; use euler::Euler; use matrix::{Matrix2, Matrix3}; -use num::BaseFloat; +use num::{BaseFloat, BaseNum}; use point::{Point2, Point3}; use quaternion::Quaternion; use vector::{Vector2, Vector3}; @@ -36,7 +36,7 @@ where Self: approx::AbsDiffEq::Space as EuclideanSpace>::Scalar>, Self: approx::RelativeEq::Space as EuclideanSpace>::Scalar>, Self: approx::UlpsEq::Space as EuclideanSpace>::Scalar>, - ::Scalar: BaseFloat, + ::Scalar: BaseNum, Self: iter::Product, { type Space: EuclideanSpace; diff --git a/src/structure.rs b/src/structure.rs index 06e08cb..29b5740 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -25,7 +25,7 @@ use approx; use angle::Rad; use num::{BaseFloat, BaseNum}; -pub use num_traits::{Bounded, NumCast, One, Zero}; +pub use num_traits::{Bounded, Num, NumCast, One, Zero}; /// An array containing elements of type `Element` pub trait Array @@ -441,7 +441,7 @@ where /// see `SquareMatrix`. pub trait Matrix: VectorSpace where - Self::Scalar: Float, + Self::Scalar: Num, // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 Self: Index::Column>, @@ -493,7 +493,7 @@ where /// A column-major major matrix where the rows and column vectors are of the same dimensions. pub trait SquareMatrix where - Self::Scalar: Float, + Self::Scalar: Num, Self: One, Self: iter::Product, diff --git a/src/vector.rs b/src/vector.rs index 231fc16..92a59f9 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -254,7 +254,7 @@ macro_rules! impl_vector { #[cfg(feature = "rand")] impl Distribution<$VectorN> for Standard where Standard: Distribution, - S: BaseFloat { + S: BaseNum { #[inline] fn sample(&self, rng: &mut R) -> $VectorN { $VectorN { $($field: rng.gen()),+ } @@ -520,7 +520,7 @@ impl Vector4 { #[inline] pub fn dot(a: V, b: V) -> V::Scalar where - V::Scalar: BaseFloat, + V::Scalar: BaseNum, { V::dot(a, b) }