Simplify impl bounds

All the useful functions are implemented for BaseFloat, so it seems reasonable to not require such fine-grained impls. This should also make the generated documentation easier to read.
This commit is contained in:
Brendan Zabarauskas 2015-12-06 19:52:03 +11:00
parent 4f0aabb164
commit 1a291c720c

View file

@ -28,7 +28,7 @@ use rust_num::traits::cast;
use angle::{Rad, sin, cos, sin_cos};
use approx::ApproxEq;
use array::Array;
use num::{BaseFloat, BaseNum};
use num::BaseFloat;
use point::{Point, Point3};
use quaternion::Quaternion;
use vector::{Vector, EuclideanVector};
@ -47,7 +47,7 @@ pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S>
pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> }
impl<S> Matrix2<S> {
impl<S: BaseFloat> Matrix2<S> {
/// Create a new matrix, providing values for each index.
#[inline]
pub fn new(c0r0: S, c0r1: S,
@ -61,9 +61,7 @@ impl<S> Matrix2<S> {
pub fn from_cols(c0: Vector2<S>, c1: Vector2<S>) -> Matrix2<S> {
Matrix2 { x: c0, y: c1 }
}
}
impl<S: BaseFloat> Matrix2<S> {
/// Create a transformation matrix that will cause a vector to point at
/// `dir`, using `up` for orientation.
pub fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Matrix2<S> {
@ -90,7 +88,7 @@ impl<S: Copy + Neg<Output = S>> Matrix2<S> {
}
}
impl<S> Matrix3<S> {
impl<S: BaseFloat> Matrix3<S> {
/// Create a new matrix, providing values for each index.
#[inline]
pub fn new(c0r0:S, c0r1:S, c0r2:S,
@ -106,9 +104,7 @@ impl<S> Matrix3<S> {
pub fn from_cols(c0: Vector3<S>, c1: Vector3<S>, c2: Vector3<S>) -> Matrix3<S> {
Matrix3 { x: c0, y: c1, z: c2 }
}
}
impl<S: BaseFloat> Matrix3<S> {
/// Create a rotation matrix that will cause a vector to point at
/// `dir`, using `up` for orientation.
pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
@ -193,7 +189,7 @@ impl<S: Copy + Neg<Output = S>> Matrix3<S> {
}
}
impl<S> Matrix4<S> {
impl<S: BaseFloat> Matrix4<S> {
/// Create a new matrix, providing values for each index.
#[inline]
pub fn new(c0r0: S, c0r1: S, c0r2: S, c0r3: S,
@ -211,9 +207,7 @@ impl<S> Matrix4<S> {
pub fn from_cols(c0: Vector4<S>, c1: Vector4<S>, c2: Vector4<S>, c3: Vector4<S>) -> Matrix4<S> {
Matrix4 { x: c0, y: c1, z: c2, w: c3 }
}
}
impl<S: BaseNum> Matrix4<S> {
/// Create a homogeneous transformation matrix from a translation vector.
#[inline]
pub fn from_translation(v: Vector3<S>) -> Matrix4<S> {
@ -222,9 +216,7 @@ impl<S: BaseNum> Matrix4<S> {
S::zero(), S::zero(), S::one(), S::zero(),
v.x, v.y, v.z, S::one())
}
}
impl<S: BaseFloat> Matrix4<S> {
/// Create a homogeneous transformation matrix from a set of scale values.
#[inline]
pub fn from_scale(x: S, y: S, z: S) -> Matrix4<S> {
@ -1342,7 +1334,7 @@ impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S> {
}
}
impl<S: BaseNum> fmt::Debug for Matrix2<S> {
impl<S: BaseFloat> fmt::Debug for Matrix2<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{:?}, {:?}], [{:?}, {:?}]]",
self[0][0], self[0][1],
@ -1350,7 +1342,7 @@ impl<S: BaseNum> fmt::Debug for Matrix2<S> {
}
}
impl<S: BaseNum> fmt::Debug for Matrix3<S> {
impl<S: BaseFloat> fmt::Debug for Matrix3<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}]]",
self[0][0], self[0][1], self[0][2],
@ -1359,7 +1351,7 @@ impl<S: BaseNum> fmt::Debug for Matrix3<S> {
}
}
impl<S: BaseNum> fmt::Debug for Matrix4<S> {
impl<S: BaseFloat> fmt::Debug for Matrix4<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}]]",
self[0][0], self[0][1], self[0][2], self[0][3],