diff --git a/src/cgmath/transform.rs b/src/cgmath/transform.rs index b3cc9ac..123f8d4 100644 --- a/src/cgmath/transform.rs +++ b/src/cgmath/transform.rs @@ -13,9 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{fmt,num}; - -use std::num::one; +use std::{fmt, num}; use approx::ApproxEq; use matrix::{Matrix, Matrix4, ToMatrix4}; @@ -23,7 +21,6 @@ use num::{BaseNum, BaseFloat}; use point::{Point, Point3}; use ray::Ray; use rotation::{Rotation, Rotation3}; -use quaternion::Quaternion; use vector::{Vector, Vector3}; /// A trait representing an [affine @@ -47,13 +44,13 @@ pub trait Transform, P: Point> { /// Transform a ray using this transform. #[inline] fn transform_ray(&self, ray: &Ray) -> Ray { - Ray::new( self.transform_point(&ray.origin), self.transform_vector(&ray.direction) ) + Ray::new(self.transform_point(&ray.origin), self.transform_vector(&ray.direction)) } /// Transform a vector as a point using this transform. #[inline] fn transform_as_point(&self, vec: &V) -> V { - self.transform_point( &Point::from_vec(vec) ).to_vec() + self.transform_point(&Point::from_vec(vec)).to_vec() } /// Combine this transform with another, yielding a new transformation @@ -79,15 +76,15 @@ pub trait Transform, P: Point> { /// A generic transformation consisting of a rotation, /// displacement vector and scale amount. -pub struct Decomposed { +pub struct Decomposed { pub scale: S, pub rot: R, pub disp: V, } -impl, P: Point, R: Rotation> Transform for Decomposed { +impl, P: Point, R: Rotation> Transform for Decomposed { #[inline] - fn identity() -> Decomposed { + fn identity() -> Decomposed { Decomposed { scale: num::one(), rot: Rotation::identity(), @@ -96,10 +93,10 @@ impl, P: Point, R: Rotation> Transform } #[inline] - fn look_at(eye: &P, center: &P, up: &V) -> Decomposed { - let origin :P = Point::origin(); - let rot :R = Rotation::look_at( ¢er.sub_p(eye), up ); - let disp :V = rot.rotate_vector( &origin.sub_p(eye) ); + fn look_at(eye: &P, center: &P, up: &V) -> Decomposed { + let origin: P = Point::origin(); + let rot: R = Rotation::look_at(¢er.sub_p(eye), up); + let disp: V = rot.rotate_vector(&origin.sub_p(eye)); Decomposed { scale: num::one(), rot: rot, @@ -109,31 +106,30 @@ impl, P: Point, R: Rotation> Transform #[inline] fn transform_vector(&self, vec: &V) -> V { - self.rot.rotate_vector( &vec.mul_s( self.scale.clone() )) + self.rot.rotate_vector(&vec.mul_s(self.scale.clone())) } #[inline] fn transform_point(&self, point: &P) -> P { - self.rot.rotate_point( &point.mul_s( self.scale.clone() )).add_v( &self.disp ) + self.rot.rotate_point(&point.mul_s(self.scale.clone())).add_v(&self.disp) } - fn concat(&self, other: &Decomposed) -> Decomposed { + fn concat(&self, other: &Decomposed) -> Decomposed { Decomposed { scale: self.scale * other.scale, - rot: self.rot.concat( &other.rot ), - disp: self.transform_as_point( &other.disp ), + rot: self.rot.concat(&other.rot), + disp: self.transform_as_point(&other.disp), } } - fn invert(&self) -> Option> { - if self.scale.approx_eq( &num::zero() ) { + fn invert(&self) -> Option> { + if self.scale.approx_eq(&num::zero()) { None - }else { - let _1 : S = num::one(); - let s = _1 / self.scale; + } else { + let s = num::one::() / self.scale; let r = self.rot.invert(); - let d = r.rotate_vector( &self.disp ).mul_s( -s ); - Some( Decomposed { + let d = r.rotate_vector(&self.disp).mul_s(-s); + Some(Decomposed { scale: s, rot: r, disp: d, @@ -146,8 +142,8 @@ pub trait Transform3: Transform, Point3>+ ToMatrix4 {} impl> ToMatrix4 for Decomposed, R> { fn to_matrix4(&self) -> Matrix4 { - let mut m = self.rot.to_matrix3().mul_s( self.scale.clone() ).to_matrix4(); - m.w = self.disp.extend( num::one() ); + let mut m = self.rot.to_matrix3().mul_s(self.scale.clone()).to_matrix4(); + m.w = self.disp.extend(num::one()); m } } @@ -161,7 +157,6 @@ impl> fmt::Show for Decomposed { pub mat: Matrix4, @@ -180,17 +175,17 @@ impl Transform, Point3> for AffineMatrix3 { #[inline] fn transform_vector(&self, vec: &Vector3) -> Vector3 { - self.mat.mul_v( &vec.extend(num::zero()) ).truncate() + self.mat.mul_v(&vec.extend(num::zero())).truncate() } #[inline] fn transform_point(&self, point: &Point3) -> Point3 { - Point3::from_homogeneous( &self.mat.mul_v( &point.to_homogeneous() )) + Point3::from_homogeneous(&self.mat.mul_v(&point.to_homogeneous())) } #[inline] fn concat(&self, other: &AffineMatrix3) -> AffineMatrix3 { - AffineMatrix3 { mat: self.mat.mul_m( &other.mat ) } + AffineMatrix3 { mat: self.mat.mul_m(&other.mat) } } #[inline]