diff --git a/src/cgmath/matrix.rs b/src/cgmath/matrix.rs index c4fac4f..e6e5751 100644 --- a/src/cgmath/matrix.rs +++ b/src/cgmath/matrix.rs @@ -38,7 +38,7 @@ approx_eq!(impl Mat2) approx_eq!(impl Mat3) approx_eq!(impl Mat4) -impl Mat2 { +impl Mat2 { #[inline] pub fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Mat2 { @@ -68,7 +68,7 @@ impl Mat2 { } } -impl Mat2 { +impl Mat2 { #[inline] pub fn from_angle(theta: Rad) -> Mat2 { let cos_theta = cos(theta.clone()); @@ -79,7 +79,7 @@ impl Mat2 { } } -impl Mat3 { +impl Mat3 { #[inline] pub fn new(c0r0:S, c0r1:S, c0r2:S, c1r0:S, c1r1:S, c1r2:S, @@ -112,7 +112,7 @@ impl Mat3 { } } -impl Mat3 { +impl Mat3 { pub fn look_at(dir: &Vec3, up: &Vec3) -> Mat3 { let dir = dir.normalize(); let side = dir.cross(&up.normalize()); @@ -122,7 +122,7 @@ impl Mat3 { } } -impl Mat4 { +impl Mat4 { #[inline] pub fn new(c0r0: S, c0r1: S, c0r2: S, c0r3: S, c1r0: S, c1r1: S, c1r2: S, c1r3: S, @@ -158,9 +158,9 @@ impl Mat4 { } } -impl One for Mat2 { #[inline] fn one() -> Mat2 { Mat2::ident() } } -impl One for Mat3 { #[inline] fn one() -> Mat3 { Mat3::ident() } } -impl One for Mat4 { #[inline] fn one() -> Mat4 { Mat4::ident() } } +impl One for Mat2 { #[inline] fn one() -> Mat2 { Mat2::ident() } } +impl One for Mat3 { #[inline] fn one() -> Mat3 { Mat3::ident() } } +impl One for Mat4 { #[inline] fn one() -> Mat4 { Mat4::ident() } } array!(impl Mat2 -> [Vec2, ..2] _2) array!(impl Mat3 -> [Vec3, ..3] _3) @@ -168,7 +168,7 @@ array!(impl Mat4 -> [Vec4, ..4] _4) pub trait Matrix < - S: Clone + Float, Slice, + S: Float, Slice, V: Clone + Vector + Array, VSlice > : Array @@ -280,11 +280,11 @@ pub trait Matrix fn is_symmetric(&self) -> bool; } -impl Neg> for Mat2 { #[inline] fn neg(&self) -> Mat2 { build(|i| self.i(i).neg()) } } -impl Neg> for Mat3 { #[inline] fn neg(&self) -> Mat3 { build(|i| self.i(i).neg()) } } -impl Neg> for Mat4 { #[inline] fn neg(&self) -> Mat4 { build(|i| self.i(i).neg()) } } +impl Neg> for Mat2 { #[inline] fn neg(&self) -> Mat2 { build(|i| self.i(i).neg()) } } +impl Neg> for Mat3 { #[inline] fn neg(&self) -> Mat3 { build(|i| self.i(i).neg()) } } +impl Neg> for Mat4 { #[inline] fn neg(&self) -> Mat4 { build(|i| self.i(i).neg()) } } -impl +impl Matrix, ..2], Vec2, [S, ..2]> for Mat2 { @@ -333,7 +333,7 @@ for Mat2 } } -impl +impl Matrix, ..3], Vec3, [S, ..3]> for Mat3 { @@ -394,7 +394,7 @@ for Mat3 } } -impl +impl Matrix, ..4], Vec4, [S, ..4]> for Mat4 { @@ -523,11 +523,11 @@ for Mat4 } // Conversion traits -pub trait ToMat2 { fn to_mat2(&self) -> Mat2; } -pub trait ToMat3 { fn to_mat3(&self) -> Mat3; } -pub trait ToMat4 { fn to_mat4(&self) -> Mat4; } +pub trait ToMat2 { fn to_mat2(&self) -> Mat2; } +pub trait ToMat3 { fn to_mat3(&self) -> Mat3; } +pub trait ToMat4 { fn to_mat4(&self) -> Mat4; } -impl ToMat3 for Mat2 { +impl ToMat3 for Mat2 { /// Clone the elements of a 2-dimensional matrix into the top corner of a /// 3-dimensional identity matrix. fn to_mat3(&self) -> Mat3 { @@ -537,7 +537,7 @@ impl ToMat3 for Mat2 { } } -impl ToMat4 for Mat2 { +impl ToMat4 for Mat2 { /// Clone the elements of a 2-dimensional matrix into the top corner of a /// 4-dimensional identity matrix. fn to_mat4(&self) -> Mat4 { @@ -548,7 +548,7 @@ impl ToMat4 for Mat2 { } } -impl ToMat4 for Mat3 { +impl ToMat4 for Mat3 { /// Clone the elements of a 3-dimensional matrix into the top corner of a /// 4-dimensional identity matrix. fn to_mat4(&self) -> Mat4 { @@ -559,7 +559,7 @@ impl ToMat4 for Mat3 { } } -impl ToQuat for Mat3 { +impl ToQuat for Mat3 { /// Convert the matrix to a quaternion fn to_quat(&self) -> Quat { // Implemented using a mix of ideas from jMonkeyEngine and Ken Shoemake's diff --git a/src/cgmath/plane.rs b/src/cgmath/plane.rs index 3eaf638..1f1cde5 100644 --- a/src/cgmath/plane.rs +++ b/src/cgmath/plane.rs @@ -35,19 +35,19 @@ pub struct Plane { distance: S, } -impl Intersect>> for (Plane, Ray3) { +impl Intersect>> for (Plane, Ray3) { fn intersection(&self) -> Option> { fail!("Not yet implemented"); } } -impl Intersect>> for (Plane, Plane) { +impl Intersect>> for (Plane, Plane) { fn intersection(&self) -> Option> { fail!("Not yet implemented"); } } -impl Intersect>> for (Plane, Plane, Plane) { +impl Intersect>> for (Plane, Plane, Plane) { fn intersection(&self) -> Option> { fail!("Not yet implemented"); } diff --git a/src/cgmath/point.rs b/src/cgmath/point.rs index 7de5392..ec68b56 100644 --- a/src/cgmath/point.rs +++ b/src/cgmath/point.rs @@ -56,7 +56,7 @@ impl Point3 { /// Specifies the numeric operations for point types. pub trait Point < - S: Clone + Num, + S: Primitive, V: Vector, Slice > @@ -79,8 +79,8 @@ pub trait Point array!(impl Point2 -> [S, ..2] _2) array!(impl Point3 -> [S, ..3] _3) -impl Point, [S, ..2]> for Point2; -impl Point, [S, ..3]> for Point3; +impl Point, [S, ..2]> for Point2; +impl Point, [S, ..3]> for Point3; impl ToStr for Point2 { fn to_str(&self) -> ~str { diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index a5e95ad..846f38f 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -27,11 +27,11 @@ pub struct Quat { s: S, v: Vec3 } array!(impl Quat -> [S, ..4] _4) approx_eq!(impl Quat) -pub trait ToQuat { +pub trait ToQuat { fn to_quat(&self) -> Quat; } -impl Quat { +impl Quat { /// Construct a new quaternion from one scalar component and three /// imaginary components #[inline] @@ -174,7 +174,7 @@ impl Quat { } } -impl Quat { +impl Quat { /// Spherical Linear Intoperlation /// /// Perform a spherical linear interpolation between the quaternion and @@ -219,7 +219,7 @@ impl Quat { } } -impl ToMat3 for Quat { +impl ToMat3 for Quat { /// Convert the quaternion to a 3 x 3 rotation matrix fn to_mat3(&self) -> Mat3 { let x2 = self.v.x + self.v.x; @@ -244,7 +244,7 @@ impl ToMat3 for Quat { } } -impl Neg> for Quat { +impl Neg> for Quat { #[inline] fn neg(&self) -> Quat { Quat::from_sv(-self.s, -self.v) diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index 99d5118..1996539 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -31,14 +31,14 @@ pub struct Vec3 { x: S, y: S, z: S } pub struct Vec4 { x: S, y: S, z: S, w: S } // Conversion traits -pub trait ToVec2 { fn to_vec2(&self) -> Vec2; } -pub trait ToVec3 { fn to_vec3(&self) -> Vec3; } -pub trait ToVec4 { fn to_vec4(&self) -> Vec4; } +pub trait ToVec2 { fn to_vec2(&self) -> Vec2; } +pub trait ToVec3 { fn to_vec3(&self) -> Vec3; } +pub trait ToVec4 { fn to_vec4(&self) -> Vec4; } // Utility macro for generating associated functions for the vectors macro_rules! vec( (impl $Self:ident <$S:ident> { $($field:ident),+ }) => ( - impl<$S: Clone + Num + Ord> $Self<$S> { + impl<$S: Primitive> $Self<$S> { #[inline] pub fn new($($field: $S),+) -> $Self<$S> { $Self { $($field: $field),+ } @@ -65,18 +65,18 @@ vec!(impl Vec2 { x, y }) vec!(impl Vec3 { x, y, z }) vec!(impl Vec4 { x, y, z, w }) -impl Vec2 { +impl Vec2 { #[inline] pub fn unit_x() -> Vec2 { Vec2::new(one(), zero()) } #[inline] pub fn unit_y() -> Vec2 { Vec2::new(zero(), one()) } } -impl Vec3 { +impl Vec3 { #[inline] pub fn unit_x() -> Vec3 { Vec3::new(one(), zero(), zero()) } #[inline] pub fn unit_y() -> Vec3 { Vec3::new(zero(), one(), zero()) } #[inline] pub fn unit_z() -> Vec3 { Vec3::new(zero(), zero(), one()) } } -impl Vec4 { +impl Vec4 { #[inline] pub fn unit_x() -> Vec4 { Vec4::new(one(), zero(), zero(), zero()) } #[inline] pub fn unit_y() -> Vec4 { Vec4::new(zero(), one(), zero(), zero()) } #[inline] pub fn unit_z() -> Vec4 { Vec4::new(zero(), zero(), one(), zero()) } @@ -96,7 +96,7 @@ approx_eq!(impl Vec4) /// for pragmatic reasons. pub trait Vector < - S: Clone + Num + Ord, + S: Primitive, Slice > : Array @@ -145,19 +145,19 @@ pub trait Vector #[inline] fn comp_max(&self) -> S { self.iter().max().unwrap().clone() } } -#[inline] fn dot>(a: V, b: V) -> S { a.dot(&b) } +#[inline] fn dot>(a: V, b: V) -> S { a.dot(&b) } -impl One for Vec2 { #[inline] fn one() -> Vec2 { Vec2::ident() } } -impl One for Vec3 { #[inline] fn one() -> Vec3 { Vec3::ident() } } -impl One for Vec4 { #[inline] fn one() -> Vec4 { Vec4::ident() } } +impl One for Vec2 { #[inline] fn one() -> Vec2 { Vec2::ident() } } +impl One for Vec3 { #[inline] fn one() -> Vec3 { Vec3::ident() } } +impl One for Vec4 { #[inline] fn one() -> Vec4 { Vec4::ident() } } -impl Neg> for Vec2 { #[inline] fn neg(&self) -> Vec2 { build(|i| self.i(i).neg()) } } -impl Neg> for Vec3 { #[inline] fn neg(&self) -> Vec3 { build(|i| self.i(i).neg()) } } -impl Neg> for Vec4 { #[inline] fn neg(&self) -> Vec4 { build(|i| self.i(i).neg()) } } +impl Neg> for Vec2 { #[inline] fn neg(&self) -> Vec2 { build(|i| self.i(i).neg()) } } +impl Neg> for Vec3 { #[inline] fn neg(&self) -> Vec3 { build(|i| self.i(i).neg()) } } +impl Neg> for Vec4 { #[inline] fn neg(&self) -> Vec4 { build(|i| self.i(i).neg()) } } macro_rules! vector( (impl $Self:ident <$S:ident> $Slice:ty { $x:ident, $($xs:ident),+ }) => ( - impl<$S: Clone + Num + Ord> Vector<$S, $Slice> for $Self<$S>; + impl<$S: Primitive> Vector<$S, $Slice> for $Self<$S>; ) ) @@ -166,7 +166,7 @@ vector!(impl Vec3 [S, ..3] { x, y, z }) vector!(impl Vec4 [S, ..4] { x, y, z, w }) /// Operations specific to numeric two-dimensional vectors. -impl Vec2 { +impl Vec2 { /// The perpendicular dot product of the vector and `other`. #[inline] pub fn perp_dot(&self, other: &Vec2) -> S { @@ -175,7 +175,7 @@ impl Vec2 { } /// Operations specific to numeric three-dimensional vectors. -impl Vec3 { +impl Vec3 { /// Returns the cross product of the vector and `other`. #[inline] pub fn cross(&self, other: &Vec3) -> Vec3 { @@ -196,7 +196,7 @@ impl Vec3 { /// 2-dimensional and 3-dimensional vectors. pub trait EuclideanVector < - S: Clone + Float, + S: Float, Slice > : Vector @@ -267,21 +267,21 @@ pub trait EuclideanVector } } -impl EuclideanVector for Vec2 { +impl EuclideanVector for Vec2 { #[inline] fn angle(&self, other: &Vec2) -> Rad { atan2(self.perp_dot(other), self.dot(other)) } } -impl EuclideanVector for Vec3 { +impl EuclideanVector for Vec3 { #[inline] fn angle(&self, other: &Vec3) -> Rad { atan2(self.cross(other).length(), self.dot(other)) } } -impl EuclideanVector for Vec4 { +impl EuclideanVector for Vec4 { #[inline] fn angle(&self, other: &Vec4) -> Rad { acos(self.dot(other) / (self.length() * other.length()))