Skip to content

Commit af12763

Browse files
spearmankvark
authored andcommitted
Replace use of BaseFloat/Float with BaseNum/Num where possible
1 parent 41fb64c commit af12763

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

src/angle.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rand::{
3030
use structure::*;
3131

3232
use approx;
33-
use num::BaseFloat;
33+
use num::{BaseFloat, BaseNum};
3434

3535
/// An angle, in radians.
3636
///
@@ -138,38 +138,38 @@ macro_rules! impl_angle {
138138
}
139139
}
140140

141-
impl_operator!(<S: BaseFloat> Add<$Angle<S> > for $Angle<S> {
141+
impl_operator!(<S: BaseNum> Add<$Angle<S> > for $Angle<S> {
142142
fn add(lhs, rhs) -> $Angle<S> { $Angle(lhs.0 + rhs.0) }
143143
});
144-
impl_operator!(<S: BaseFloat> Sub<$Angle<S> > for $Angle<S> {
144+
impl_operator!(<S: BaseNum> Sub<$Angle<S> > for $Angle<S> {
145145
fn sub(lhs, rhs) -> $Angle<S> { $Angle(lhs.0 - rhs.0) }
146146
});
147-
impl_operator!(<S: BaseFloat> Div<$Angle<S> > for $Angle<S> {
147+
impl_operator!(<S: BaseNum> Div<$Angle<S> > for $Angle<S> {
148148
fn div(lhs, rhs) -> S { lhs.0 / rhs.0 }
149149
});
150-
impl_operator!(<S: BaseFloat> Rem<$Angle<S> > for $Angle<S> {
150+
impl_operator!(<S: BaseNum> Rem<$Angle<S> > for $Angle<S> {
151151
fn rem(lhs, rhs) -> $Angle<S> { $Angle(lhs.0 % rhs.0) }
152152
});
153-
impl_assignment_operator!(<S: BaseFloat> AddAssign<$Angle<S> > for $Angle<S> {
153+
impl_assignment_operator!(<S: BaseNum> AddAssign<$Angle<S> > for $Angle<S> {
154154
fn add_assign(&mut self, other) { self.0 += other.0; }
155155
});
156-
impl_assignment_operator!(<S: BaseFloat> SubAssign<$Angle<S> > for $Angle<S> {
156+
impl_assignment_operator!(<S: BaseNum> SubAssign<$Angle<S> > for $Angle<S> {
157157
fn sub_assign(&mut self, other) { self.0 -= other.0; }
158158
});
159-
impl_assignment_operator!(<S: BaseFloat> RemAssign<$Angle<S> > for $Angle<S> {
159+
impl_assignment_operator!(<S: BaseNum> RemAssign<$Angle<S> > for $Angle<S> {
160160
fn rem_assign(&mut self, other) { self.0 %= other.0; }
161161
});
162162

163-
impl_operator!(<S: BaseFloat> Mul<S> for $Angle<S> {
163+
impl_operator!(<S: BaseNum> Mul<S> for $Angle<S> {
164164
fn mul(lhs, scalar) -> $Angle<S> { $Angle(lhs.0 * scalar) }
165165
});
166-
impl_operator!(<S: BaseFloat> Div<S> for $Angle<S> {
166+
impl_operator!(<S: BaseNum> Div<S> for $Angle<S> {
167167
fn div(lhs, scalar) -> $Angle<S> { $Angle(lhs.0 / scalar) }
168168
});
169-
impl_assignment_operator!(<S: BaseFloat> MulAssign<S> for $Angle<S> {
169+
impl_assignment_operator!(<S: BaseNum> MulAssign<S> for $Angle<S> {
170170
fn mul_assign(&mut self, scalar) { self.0 *= scalar; }
171171
});
172-
impl_assignment_operator!(<S: BaseFloat> DivAssign<S> for $Angle<S> {
172+
impl_assignment_operator!(<S: BaseNum> DivAssign<S> for $Angle<S> {
173173
fn div_assign(&mut self, scalar) { self.0 /= scalar; }
174174
});
175175

src/matrix.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use structure::*;
3030
use angle::Rad;
3131
use approx;
3232
use euler::Euler;
33-
use num::BaseFloat;
33+
use num::{BaseFloat, BaseNum};
3434
use point::{Point2, Point3};
3535
use quaternion::Quaternion;
3636
use transform::{Transform, Transform2, Transform3};
@@ -1569,7 +1569,7 @@ mint_conversions!(Matrix3 { x, y, z }, ColumnMatrix3);
15691569
#[cfg(feature = "mint")]
15701570
mint_conversions!(Matrix4 { x, y, z, w }, ColumnMatrix4);
15711571

1572-
impl<S: BaseFloat> From<Matrix2<S>> for Matrix3<S> {
1572+
impl<S: BaseNum> From<Matrix2<S>> for Matrix3<S> {
15731573
/// Clone the elements of a 2-dimensional matrix into the top-left corner
15741574
/// of a 3-dimensional identity matrix.
15751575
fn from(m: Matrix2<S>) -> Matrix3<S> {
@@ -1582,7 +1582,7 @@ impl<S: BaseFloat> From<Matrix2<S>> for Matrix3<S> {
15821582
}
15831583
}
15841584

1585-
impl<S: BaseFloat> From<Matrix2<S>> for Matrix4<S> {
1585+
impl<S: BaseNum> From<Matrix2<S>> for Matrix4<S> {
15861586
/// Clone the elements of a 2-dimensional matrix into the top-left corner
15871587
/// of a 4-dimensional identity matrix.
15881588
fn from(m: Matrix2<S>) -> Matrix4<S> {
@@ -1596,7 +1596,7 @@ impl<S: BaseFloat> From<Matrix2<S>> for Matrix4<S> {
15961596
}
15971597
}
15981598

1599-
impl<S: BaseFloat> From<Matrix3<S>> for Matrix4<S> {
1599+
impl<S: BaseNum> From<Matrix3<S>> for Matrix4<S> {
16001600
/// Clone the elements of a 3-dimensional matrix into the top-left corner
16011601
/// of a 4-dimensional identity matrix.
16021602
fn from(m: Matrix3<S>) -> Matrix4<S> {
@@ -1678,7 +1678,7 @@ impl<S: fmt::Debug> fmt::Debug for Matrix4<S> {
16781678
impl<S> Distribution<Matrix2<S>> for Standard
16791679
where
16801680
Standard: Distribution<Vector2<S>>,
1681-
S: BaseFloat,
1681+
S: BaseNum,
16821682
{
16831683
#[inline]
16841684
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Matrix2<S> {
@@ -1693,7 +1693,7 @@ where
16931693
impl<S> Distribution<Matrix3<S>> for Standard
16941694
where
16951695
Standard: Distribution<Vector3<S>>,
1696-
S: BaseFloat,
1696+
S: BaseNum,
16971697
{
16981698
#[inline]
16991699
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Matrix3<S> {
@@ -1709,7 +1709,7 @@ where
17091709
impl<S> Distribution<Matrix4<S>> for Standard
17101710
where
17111711
Standard: Distribution<Vector4<S>>,
1712-
S: BaseFloat,
1712+
S: BaseNum,
17131713
{
17141714
#[inline]
17151715
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Matrix4<S> {

src/point.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ macro_rules! impl_point {
154154
}
155155
}
156156

157-
impl<S: BaseFloat> MetricSpace for $PointN<S> {
157+
impl<S: BaseNum> MetricSpace for $PointN<S> {
158158
type Metric = S;
159159

160160
#[inline]

src/quaternion.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use angle::Rad;
2929
use approx;
3030
use euler::Euler;
3131
use matrix::{Matrix3, Matrix4};
32-
use num::BaseFloat;
32+
use num::{BaseFloat, BaseNum};
3333
use point::Point3;
3434
use quaternion;
3535
use rotation::{Basis3, Rotation, Rotation3};
@@ -410,7 +410,7 @@ impl<S: BaseFloat> approx::UlpsEq for Quaternion<S> {
410410
}
411411
}
412412

413-
impl<S: BaseFloat> From<Quaternion<S>> for Matrix3<S> {
413+
impl<S: BaseNum> From<Quaternion<S>> for Matrix3<S> {
414414
/// Convert the quaternion to a 3 x 3 rotation matrix.
415415
fn from(quat: Quaternion<S>) -> Matrix3<S> {
416416
let x2 = quat.v.x + quat.v.x;
@@ -438,7 +438,7 @@ impl<S: BaseFloat> From<Quaternion<S>> for Matrix3<S> {
438438
}
439439
}
440440

441-
impl<S: BaseFloat> From<Quaternion<S>> for Matrix4<S> {
441+
impl<S: BaseNum> From<Quaternion<S>> for Matrix4<S> {
442442
/// Convert the quaternion to a 4 x 4 rotation matrix.
443443
fn from(quat: Quaternion<S>) -> Matrix4<S> {
444444
let x2 = quat.v.x + quat.v.x;
@@ -534,50 +534,50 @@ impl<S: BaseFloat> Rotation3 for Quaternion<S> {
534534
}
535535
}
536536

537-
impl<S: BaseFloat> From<Quaternion<S>> for [S; 4] {
537+
impl<S: BaseNum> From<Quaternion<S>> for [S; 4] {
538538
#[inline]
539539
fn from(v: Quaternion<S>) -> Self {
540540
let (xi, yj, zk, w) = v.into();
541541
[xi, yj, zk, w]
542542
}
543543
}
544544

545-
impl<S: BaseFloat> AsRef<[S; 4]> for Quaternion<S> {
545+
impl<S: BaseNum> AsRef<[S; 4]> for Quaternion<S> {
546546
#[inline]
547547
fn as_ref(&self) -> &[S; 4] {
548548
unsafe { &*(self as *const quaternion::Quaternion<S> as *const [S; 4]) }
549549
}
550550
}
551551

552-
impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S> {
552+
impl<S: BaseNum> AsMut<[S; 4]> for Quaternion<S> {
553553
#[inline]
554554
fn as_mut(&mut self) -> &mut [S; 4] {
555555
unsafe { &mut *(self as *mut quaternion::Quaternion<S> as *mut [S; 4]) }
556556
}
557557
}
558558

559-
impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
559+
impl<S: BaseNum> From<[S; 4]> for Quaternion<S> {
560560
#[inline]
561561
fn from(v: [S; 4]) -> Quaternion<S> {
562562
Quaternion::new(v[3], v[0], v[1], v[2])
563563
}
564564
}
565565

566-
impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S> {
566+
impl<'a, S: BaseNum> From<&'a [S; 4]> for &'a Quaternion<S> {
567567
#[inline]
568568
fn from(v: &'a [S; 4]) -> &'a Quaternion<S> {
569569
unsafe { &*(v as *const [S; 4] as *const quaternion::Quaternion<S>) }
570570
}
571571
}
572572

573-
impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S> {
573+
impl<'a, S: BaseNum> From<&'a mut [S; 4]> for &'a mut Quaternion<S> {
574574
#[inline]
575575
fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion<S> {
576576
unsafe { &mut *(v as *mut [S; 4] as *mut quaternion::Quaternion<S>) }
577577
}
578578
}
579579

580-
impl<S: BaseFloat> From<Quaternion<S>> for (S, S, S, S) {
580+
impl<S: BaseNum> From<Quaternion<S>> for (S, S, S, S) {
581581
#[inline]
582582
fn from(v: Quaternion<S>) -> Self {
583583
let Quaternion {
@@ -588,36 +588,36 @@ impl<S: BaseFloat> From<Quaternion<S>> for (S, S, S, S) {
588588
}
589589
}
590590

591-
impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S> {
591+
impl<S: BaseNum> AsRef<(S, S, S, S)> for Quaternion<S> {
592592
#[inline]
593593
fn as_ref(&self) -> &(S, S, S, S) {
594594
unsafe { &*(self as *const quaternion::Quaternion<S> as *const (S, S, S, S)) }
595595
}
596596
}
597597

598-
impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S> {
598+
impl<S: BaseNum> AsMut<(S, S, S, S)> for Quaternion<S> {
599599
#[inline]
600600
fn as_mut(&mut self) -> &mut (S, S, S, S) {
601601
unsafe { &mut *(self as *mut quaternion::Quaternion<S> as *mut (S, S, S, S)) }
602602
}
603603
}
604604

605-
impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S> {
605+
impl<S: BaseNum> From<(S, S, S, S)> for Quaternion<S> {
606606
#[inline]
607607
fn from(v: (S, S, S, S)) -> Quaternion<S> {
608608
let (xi, yj, zk, w) = v;
609609
Quaternion::new(w, xi, yj, zk)
610610
}
611611
}
612612

613-
impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S> {
613+
impl<'a, S: BaseNum> From<&'a (S, S, S, S)> for &'a Quaternion<S> {
614614
#[inline]
615615
fn from(v: &'a (S, S, S, S)) -> &'a Quaternion<S> {
616616
unsafe { &*(v as *const (S, S, S, S) as *const quaternion::Quaternion<S>) }
617617
}
618618
}
619619

620-
impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S> {
620+
impl<'a, S: BaseNum> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S> {
621621
#[inline]
622622
fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion<S> {
623623
unsafe { &mut *(v as *mut (S, S, S, S) as *mut quaternion::Quaternion<S>) }
@@ -626,7 +626,7 @@ impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S> {
626626

627627
macro_rules! index_operators {
628628
($S:ident, $Output:ty, $I:ty) => {
629-
impl<$S: BaseFloat> Index<$I> for Quaternion<$S> {
629+
impl<$S: BaseNum> Index<$I> for Quaternion<$S> {
630630
type Output = $Output;
631631

632632
#[inline]
@@ -636,7 +636,7 @@ macro_rules! index_operators {
636636
}
637637
}
638638

639-
impl<$S: BaseFloat> IndexMut<$I> for Quaternion<$S> {
639+
impl<$S: BaseNum> IndexMut<$I> for Quaternion<$S> {
640640
#[inline]
641641
fn index_mut<'a>(&'a mut self, i: $I) -> &'a mut $Output {
642642
let v: &mut [$S; 4] = self.as_mut();
@@ -657,7 +657,7 @@ impl<S> Distribution<Quaternion<S>> for Standard
657657
where
658658
Standard: Distribution<S>,
659659
Standard: Distribution<Vector3<S>>,
660-
S: BaseFloat,
660+
S: BaseNum,
661661
{
662662
#[inline]
663663
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Quaternion<S> {

src/rotation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use angle::Rad;
2323
use approx;
2424
use euler::Euler;
2525
use matrix::{Matrix2, Matrix3};
26-
use num::BaseFloat;
26+
use num::{BaseFloat, BaseNum};
2727
use point::{Point2, Point3};
2828
use quaternion::Quaternion;
2929
use vector::{Vector2, Vector3};
@@ -36,7 +36,7 @@ where
3636
Self: approx::AbsDiffEq<Epsilon = <<Self as Rotation>::Space as EuclideanSpace>::Scalar>,
3737
Self: approx::RelativeEq<Epsilon = <<Self as Rotation>::Space as EuclideanSpace>::Scalar>,
3838
Self: approx::UlpsEq<Epsilon = <<Self as Rotation>::Space as EuclideanSpace>::Scalar>,
39-
<Self::Space as EuclideanSpace>::Scalar: BaseFloat,
39+
<Self::Space as EuclideanSpace>::Scalar: BaseNum,
4040
Self: iter::Product<Self>,
4141
{
4242
type Space: EuclideanSpace;

src/structure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use approx;
2525
use angle::Rad;
2626
use num::{BaseFloat, BaseNum};
2727

28-
pub use num_traits::{Bounded, NumCast, One, Zero};
28+
pub use num_traits::{Bounded, Num, NumCast, One, Zero};
2929

3030
/// An array containing elements of type `Element`
3131
pub trait Array
@@ -441,7 +441,7 @@ where
441441
/// see `SquareMatrix`.
442442
pub trait Matrix: VectorSpace
443443
where
444-
Self::Scalar: Float,
444+
Self::Scalar: Num,
445445

446446
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
447447
Self: Index<usize, Output = <Self as Matrix>::Column>,
@@ -493,7 +493,7 @@ where
493493
/// A column-major major matrix where the rows and column vectors are of the same dimensions.
494494
pub trait SquareMatrix
495495
where
496-
Self::Scalar: Float,
496+
Self::Scalar: Num,
497497

498498
Self: One,
499499
Self: iter::Product<Self>,

src/vector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ macro_rules! impl_vector {
254254
#[cfg(feature = "rand")]
255255
impl<S> Distribution<$VectorN<S>> for Standard
256256
where Standard: Distribution<S>,
257-
S: BaseFloat {
257+
S: BaseNum {
258258
#[inline]
259259
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $VectorN<S> {
260260
$VectorN { $($field: rng.gen()),+ }
@@ -520,7 +520,7 @@ impl<S: BaseNum> Vector4<S> {
520520
#[inline]
521521
pub fn dot<V: InnerSpace>(a: V, b: V) -> V::Scalar
522522
where
523-
V::Scalar: BaseFloat,
523+
V::Scalar: BaseNum,
524524
{
525525
V::dot(a, b)
526526
}

0 commit comments

Comments
 (0)