diff --git a/src/euler.rs b/src/euler.rs index 9c05fc0..264271a 100644 --- a/src/euler.rs +++ b/src/euler.rs @@ -99,7 +99,7 @@ impl Euler { /// * `y` - The angle to apply around the _y_ axis. Also known at the _yaw_. /// * `z` - The angle to apply around the _z_ axis. Also known at the _roll_. pub const fn new(x: A, y: A, z: A) -> Euler { - Euler { x: x, y: y, z: z } + Euler { x, y, z } } } diff --git a/src/matrix.rs b/src/matrix.rs index 65e9f48..e61eac3 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -354,9 +354,9 @@ impl Matrix4 { #[cfg_attr(rustfmt, rustfmt_skip)] Matrix4::new( - s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(), - s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(), - s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(), + s.x, u.x, -f.x, S::zero(), + s.y, u.y, -f.y, S::zero(), + s.z, u.z, -f.z, S::zero(), -eye.dot(s), -eye.dot(u), eye.dot(f), S::one(), ) } @@ -370,9 +370,9 @@ impl Matrix4 { #[cfg_attr(rustfmt, rustfmt_skip)] Matrix4::new( - s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(), - s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(), - s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(), + s.x, u.x, -f.x, S::zero(), + s.y, u.y, -f.y, S::zero(), + s.z, u.z, -f.z, S::zero(), -eye.dot(s), -eye.dot(u), eye.dot(f), S::one(), ) } diff --git a/src/projection.rs b/src/projection.rs index 8ba3dc0..a11c439 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -35,9 +35,9 @@ pub fn perspective>>( ) -> Matrix4 { PerspectiveFov { fovy: fovy.into(), - aspect: aspect, - near: near, - far: far, + aspect, + near, + far, } .into() } @@ -49,12 +49,12 @@ pub fn perspective>>( /// [`glFrustum`]: http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4 { Perspective { - left: left, - right: right, - bottom: bottom, - top: top, - near: near, - far: far, + left, + right, + bottom, + top, + near, + far, } .into() } @@ -66,12 +66,12 @@ pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: /// [`glOrtho`]: http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4 { Ortho { - left: left, - right: right, - bottom: bottom, - top: top, - near: near, - far: far, + left, + right, + bottom, + top, + near, + far, } .into() } @@ -99,8 +99,8 @@ impl PerspectiveFov { right: xmax, bottom: -ymax, top: ymax, - near: self.near.clone(), - far: self.far.clone(), + near: self.near, + far: self.far, } } } diff --git a/src/quaternion.rs b/src/quaternion.rs index 210c755..059e5d8 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -14,7 +14,6 @@ // limitations under the License. use std::iter; -use std::mem; use std::ops::*; use num_traits::{cast, NumCast}; @@ -34,6 +33,7 @@ use num::BaseFloat; use point::Point3; use rotation::{Basis3, Rotation, Rotation3}; use vector::Vector3; +use quaternion; #[cfg(feature = "mint")] use mint; @@ -63,7 +63,7 @@ impl Quaternion { /// Construct a new quaternion from a scalar and a vector. #[inline] pub const fn from_sv(s: S, v: Vector3) -> Quaternion { - Quaternion { s: s, v: v } + Quaternion { v, s } } } @@ -541,23 +541,22 @@ impl Rotation3 for Quaternion { impl From> for [S; 4] { #[inline] fn from(v: Quaternion) -> Self { - match v.into() { - (xi, yj, zk, w) => [xi, yj, zk, w], - } + let (xi, yj, zk, w) = v.into(); + [xi, yj, zk, w] } } impl AsRef<[S; 4]> for Quaternion { #[inline] fn as_ref(&self) -> &[S; 4] { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const quaternion::Quaternion as *const [S; 4]) } } } impl AsMut<[S; 4]> for Quaternion { #[inline] fn as_mut(&mut self) -> &mut [S; 4] { - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut quaternion::Quaternion as *mut [S; 4]) } } } @@ -571,63 +570,61 @@ impl From<[S; 4]> for Quaternion { impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion { #[inline] fn from(v: &'a [S; 4]) -> &'a Quaternion { - unsafe { mem::transmute(v) } + unsafe { &*(v as *const [S; 4] as *const quaternion::Quaternion) } } } impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion { #[inline] fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion { - unsafe { mem::transmute(v) } + unsafe { &mut *(v as *mut [S; 4] as *mut quaternion::Quaternion) } } } impl From> for (S, S, S, S) { #[inline] fn from(v: Quaternion) -> Self { - match v { - Quaternion { + let Quaternion { s, v: Vector3 { x, y, z }, - } => (x, y, z, s), - } + } = v; + (x, y, z, s) } } impl AsRef<(S, S, S, S)> for Quaternion { #[inline] fn as_ref(&self) -> &(S, S, S, S) { - unsafe { mem::transmute(self) } + unsafe { &*(self as *const quaternion::Quaternion as *const (S, S, S, S)) } } } impl AsMut<(S, S, S, S)> for Quaternion { #[inline] fn as_mut(&mut self) -> &mut (S, S, S, S) { - unsafe { mem::transmute(self) } + unsafe { &mut *(self as *mut quaternion::Quaternion as *mut (S, S, S, S)) } } } impl From<(S, S, S, S)> for Quaternion { #[inline] fn from(v: (S, S, S, S)) -> Quaternion { - match v { - (xi, yj, zk, w) => Quaternion::new(w, xi, yj, zk), - } + let (xi, yj, zk, w) = v; + Quaternion::new(w, xi, yj, zk) } } impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion { #[inline] fn from(v: &'a (S, S, S, S)) -> &'a Quaternion { - unsafe { mem::transmute(v) } + 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 { #[inline] fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion { - unsafe { mem::transmute(v) } + unsafe { &mut *(v as *mut (S, S, S, S) as *mut quaternion::Quaternion) } } } diff --git a/src/transform.rs b/src/transform.rs index 151bf3d..f6bdd15 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -46,8 +46,7 @@ pub trait Transform: Sized + One { /// Inverse transform a vector using this transform fn inverse_transform_vector(&self, vec: P::Diff) -> Option { - self.inverse_transform() - .and_then(|inverse| Some(inverse.transform_vector(vec))) + self.inverse_transform().map(|inverse| inverse.transform_vector(vec)) } /// Transform a point using this transform. @@ -117,8 +116,8 @@ where let disp = rot.rotate_vector(P::origin() - eye); Decomposed { scale: P::Scalar::one(), - rot: rot, - disp: disp, + rot, + disp, } } @@ -128,8 +127,8 @@ where let disp = rot.rotate_vector(P::origin() - eye); Decomposed { scale: P::Scalar::one(), - rot: rot, - disp: disp, + rot, + disp, } } @@ -139,8 +138,8 @@ where let disp = rot.rotate_vector(P::origin() - eye); Decomposed { scale: P::Scalar::one(), - rot: rot, - disp: disp, + rot, + disp, } } @@ -201,7 +200,7 @@ pub trait Transform3: impl> From, R>> for Matrix3 { fn from(dec: Decomposed, R>) -> Matrix3 { let m: Matrix2<_> = dec.rot.into(); - let mut m: Matrix3<_> = (&m * dec.scale).into(); + let mut m: Matrix3<_> = (m * dec.scale).into(); m.z = dec.disp.extend(S::one()); m } @@ -210,7 +209,7 @@ impl> From, R>> for impl> From, R>> for Matrix4 { fn from(dec: Decomposed, R>) -> Matrix4 { let m: Matrix3<_> = dec.rot.into(); - let mut m: Matrix4<_> = (&m * dec.scale).into(); + let mut m: Matrix4<_> = (m * dec.scale).into(); m.w = dec.disp.extend(S::one()); m }