Fix some clippy warnings

This commit is contained in:
Rémi Lauzier 2021-06-14 19:05:10 -04:00 committed by Dzmitry Malyshau
parent 7a0ebdf1e6
commit fb205c0fc9
5 changed files with 50 additions and 54 deletions

View file

@ -99,7 +99,7 @@ impl<A> Euler<A> {
/// * `y` - The angle to apply around the _y_ axis. Also known at the _yaw_. /// * `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_. /// * `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<A> { pub const fn new(x: A, y: A, z: A) -> Euler<A> {
Euler { x: x, y: y, z: z } Euler { x, y, z }
} }
} }

View file

@ -354,9 +354,9 @@ impl<S: BaseFloat> Matrix4<S> {
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]
Matrix4::new( Matrix4::new(
s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(), s.x, u.x, -f.x, S::zero(),
s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(), s.y, u.y, -f.y, S::zero(),
s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(), s.z, u.z, -f.z, S::zero(),
-eye.dot(s), -eye.dot(u), eye.dot(f), S::one(), -eye.dot(s), -eye.dot(u), eye.dot(f), S::one(),
) )
} }
@ -370,9 +370,9 @@ impl<S: BaseFloat> Matrix4<S> {
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]
Matrix4::new( Matrix4::new(
s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(), s.x, u.x, -f.x, S::zero(),
s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(), s.y, u.y, -f.y, S::zero(),
s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(), s.z, u.z, -f.z, S::zero(),
-eye.dot(s), -eye.dot(u), eye.dot(f), S::one(), -eye.dot(s), -eye.dot(u), eye.dot(f), S::one(),
) )
} }

View file

@ -35,9 +35,9 @@ pub fn perspective<S: BaseFloat, A: Into<Rad<S>>>(
) -> Matrix4<S> { ) -> Matrix4<S> {
PerspectiveFov { PerspectiveFov {
fovy: fovy.into(), fovy: fovy.into(),
aspect: aspect, aspect,
near: near, near,
far: far, far,
} }
.into() .into()
} }
@ -49,12 +49,12 @@ pub fn perspective<S: BaseFloat, A: Into<Rad<S>>>(
/// [`glFrustum`]: http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml /// [`glFrustum`]: http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml
pub fn frustum<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4<S> { pub fn frustum<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4<S> {
Perspective { Perspective {
left: left, left,
right: right, right,
bottom: bottom, bottom,
top: top, top,
near: near, near,
far: far, far,
} }
.into() .into()
} }
@ -66,12 +66,12 @@ pub fn frustum<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far:
/// [`glOrtho`]: http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml /// [`glOrtho`]: http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
pub fn ortho<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4<S> { pub fn ortho<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4<S> {
Ortho { Ortho {
left: left, left,
right: right, right,
bottom: bottom, bottom,
top: top, top,
near: near, near,
far: far, far,
} }
.into() .into()
} }
@ -99,8 +99,8 @@ impl<S: BaseFloat> PerspectiveFov<S> {
right: xmax, right: xmax,
bottom: -ymax, bottom: -ymax,
top: ymax, top: ymax,
near: self.near.clone(), near: self.near,
far: self.far.clone(), far: self.far,
} }
} }
} }

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
use std::iter; use std::iter;
use std::mem;
use std::ops::*; use std::ops::*;
use num_traits::{cast, NumCast}; use num_traits::{cast, NumCast};
@ -34,6 +33,7 @@ use num::BaseFloat;
use point::Point3; use point::Point3;
use rotation::{Basis3, Rotation, Rotation3}; use rotation::{Basis3, Rotation, Rotation3};
use vector::Vector3; use vector::Vector3;
use quaternion;
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
use mint; use mint;
@ -63,7 +63,7 @@ impl<S> Quaternion<S> {
/// Construct a new quaternion from a scalar and a vector. /// Construct a new quaternion from a scalar and a vector.
#[inline] #[inline]
pub const fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S> { pub const fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S> {
Quaternion { s: s, v: v } Quaternion { v, s }
} }
} }
@ -541,23 +541,22 @@ impl<S: BaseFloat> Rotation3 for Quaternion<S> {
impl<S: BaseFloat> From<Quaternion<S>> for [S; 4] { impl<S: BaseFloat> From<Quaternion<S>> for [S; 4] {
#[inline] #[inline]
fn from(v: Quaternion<S>) -> Self { fn from(v: Quaternion<S>) -> Self {
match v.into() { let (xi, yj, zk, w) = v.into();
(xi, yj, zk, w) => [xi, yj, zk, w], [xi, yj, zk, w]
}
} }
} }
impl<S: BaseFloat> AsRef<[S; 4]> for Quaternion<S> { impl<S: BaseFloat> AsRef<[S; 4]> for Quaternion<S> {
#[inline] #[inline]
fn as_ref(&self) -> &[S; 4] { fn as_ref(&self) -> &[S; 4] {
unsafe { mem::transmute(self) } unsafe { &*(self as *const quaternion::Quaternion<S> as *const [S; 4]) }
} }
} }
impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S> { impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S> {
#[inline] #[inline]
fn as_mut(&mut self) -> &mut [S; 4] { fn as_mut(&mut self) -> &mut [S; 4] {
unsafe { mem::transmute(self) } unsafe { &mut *(self as *mut quaternion::Quaternion<S> as *mut [S; 4]) }
} }
} }
@ -571,63 +570,61 @@ impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S> { impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S> {
#[inline] #[inline]
fn from(v: &'a [S; 4]) -> &'a Quaternion<S> { fn from(v: &'a [S; 4]) -> &'a Quaternion<S> {
unsafe { mem::transmute(v) } unsafe { &*(v as *const [S; 4] as *const quaternion::Quaternion<S>) }
} }
} }
impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S> { impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S> {
#[inline] #[inline]
fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion<S> { fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion<S> {
unsafe { mem::transmute(v) } unsafe { &mut *(v as *mut [S; 4] as *mut quaternion::Quaternion<S>) }
} }
} }
impl<S: BaseFloat> From<Quaternion<S>> for (S, S, S, S) { impl<S: BaseFloat> From<Quaternion<S>> for (S, S, S, S) {
#[inline] #[inline]
fn from(v: Quaternion<S>) -> Self { fn from(v: Quaternion<S>) -> Self {
match v { let Quaternion {
Quaternion {
s, s,
v: Vector3 { x, y, z }, v: Vector3 { x, y, z },
} => (x, y, z, s), } = v;
} (x, y, z, s)
} }
} }
impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S> { impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S> {
#[inline] #[inline]
fn as_ref(&self) -> &(S, S, S, S) { fn as_ref(&self) -> &(S, S, S, S) {
unsafe { mem::transmute(self) } unsafe { &*(self as *const quaternion::Quaternion<S> as *const (S, S, S, S)) }
} }
} }
impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S> { impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S> {
#[inline] #[inline]
fn as_mut(&mut self) -> &mut (S, S, S, S) { fn as_mut(&mut self) -> &mut (S, S, S, S) {
unsafe { mem::transmute(self) } unsafe { &mut *(self as *mut quaternion::Quaternion<S> as *mut (S, S, S, S)) }
} }
} }
impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S> { impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S> {
#[inline] #[inline]
fn from(v: (S, S, S, S)) -> Quaternion<S> { fn from(v: (S, S, S, S)) -> Quaternion<S> {
match v { let (xi, yj, zk, w) = v;
(xi, yj, zk, w) => Quaternion::new(w, xi, yj, zk), Quaternion::new(w, xi, yj, zk)
}
} }
} }
impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S> { impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S> {
#[inline] #[inline]
fn from(v: &'a (S, S, S, S)) -> &'a Quaternion<S> { fn from(v: &'a (S, S, S, S)) -> &'a Quaternion<S> {
unsafe { mem::transmute(v) } unsafe { &*(v as *const (S, S, S, S) as *const quaternion::Quaternion<S>) }
} }
} }
impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S> { impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S> {
#[inline] #[inline]
fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion<S> { fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion<S> {
unsafe { mem::transmute(v) } unsafe { &mut *(v as *mut (S, S, S, S) as *mut quaternion::Quaternion<S>) }
} }
} }

View file

@ -46,8 +46,7 @@ pub trait Transform<P: EuclideanSpace>: Sized + One {
/// Inverse transform a vector using this transform /// Inverse transform a vector using this transform
fn inverse_transform_vector(&self, vec: P::Diff) -> Option<P::Diff> { fn inverse_transform_vector(&self, vec: P::Diff) -> Option<P::Diff> {
self.inverse_transform() self.inverse_transform().map(|inverse| inverse.transform_vector(vec))
.and_then(|inverse| Some(inverse.transform_vector(vec)))
} }
/// Transform a point using this transform. /// Transform a point using this transform.
@ -117,8 +116,8 @@ where
let disp = rot.rotate_vector(P::origin() - eye); let disp = rot.rotate_vector(P::origin() - eye);
Decomposed { Decomposed {
scale: P::Scalar::one(), scale: P::Scalar::one(),
rot: rot, rot,
disp: disp, disp,
} }
} }
@ -128,8 +127,8 @@ where
let disp = rot.rotate_vector(P::origin() - eye); let disp = rot.rotate_vector(P::origin() - eye);
Decomposed { Decomposed {
scale: P::Scalar::one(), scale: P::Scalar::one(),
rot: rot, rot,
disp: disp, disp,
} }
} }
@ -139,8 +138,8 @@ where
let disp = rot.rotate_vector(P::origin() - eye); let disp = rot.rotate_vector(P::origin() - eye);
Decomposed { Decomposed {
scale: P::Scalar::one(), scale: P::Scalar::one(),
rot: rot, rot,
disp: disp, disp,
} }
} }
@ -201,7 +200,7 @@ pub trait Transform3:
impl<S: BaseFloat, R: Rotation2<Scalar = S>> From<Decomposed<Vector2<S>, R>> for Matrix3<S> { impl<S: BaseFloat, R: Rotation2<Scalar = S>> From<Decomposed<Vector2<S>, R>> for Matrix3<S> {
fn from(dec: Decomposed<Vector2<S>, R>) -> Matrix3<S> { fn from(dec: Decomposed<Vector2<S>, R>) -> Matrix3<S> {
let m: Matrix2<_> = dec.rot.into(); 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.z = dec.disp.extend(S::one());
m m
} }
@ -210,7 +209,7 @@ impl<S: BaseFloat, R: Rotation2<Scalar = S>> From<Decomposed<Vector2<S>, R>> for
impl<S: BaseFloat, R: Rotation3<Scalar = S>> From<Decomposed<Vector3<S>, R>> for Matrix4<S> { impl<S: BaseFloat, R: Rotation3<Scalar = S>> From<Decomposed<Vector3<S>, R>> for Matrix4<S> {
fn from(dec: Decomposed<Vector3<S>, R>) -> Matrix4<S> { fn from(dec: Decomposed<Vector3<S>, R>) -> Matrix4<S> {
let m: Matrix3<_> = dec.rot.into(); 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.w = dec.disp.extend(S::one());
m m
} }