Skip to content

Commit fb205c0

Browse files
Rémi Lauzierkvark
authored andcommitted
Fix some clippy warnings
1 parent 7a0ebdf commit fb205c0

File tree

5 files changed

+50
-54
lines changed

5 files changed

+50
-54
lines changed

src/euler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<A> Euler<A> {
9999
/// * `y` - The angle to apply around the _y_ axis. Also known at the _yaw_.
100100
/// * `z` - The angle to apply around the _z_ axis. Also known at the _roll_.
101101
pub const fn new(x: A, y: A, z: A) -> Euler<A> {
102-
Euler { x: x, y: y, z: z }
102+
Euler { x, y, z }
103103
}
104104
}
105105

src/matrix.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ impl<S: BaseFloat> Matrix4<S> {
354354

355355
#[cfg_attr(rustfmt, rustfmt_skip)]
356356
Matrix4::new(
357-
s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(),
358-
s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(),
359-
s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(),
357+
s.x, u.x, -f.x, S::zero(),
358+
s.y, u.y, -f.y, S::zero(),
359+
s.z, u.z, -f.z, S::zero(),
360360
-eye.dot(s), -eye.dot(u), eye.dot(f), S::one(),
361361
)
362362
}
@@ -370,9 +370,9 @@ impl<S: BaseFloat> Matrix4<S> {
370370

371371
#[cfg_attr(rustfmt, rustfmt_skip)]
372372
Matrix4::new(
373-
s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(),
374-
s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(),
375-
s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(),
373+
s.x, u.x, -f.x, S::zero(),
374+
s.y, u.y, -f.y, S::zero(),
375+
s.z, u.z, -f.z, S::zero(),
376376
-eye.dot(s), -eye.dot(u), eye.dot(f), S::one(),
377377
)
378378
}

src/projection.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub fn perspective<S: BaseFloat, A: Into<Rad<S>>>(
3535
) -> Matrix4<S> {
3636
PerspectiveFov {
3737
fovy: fovy.into(),
38-
aspect: aspect,
39-
near: near,
40-
far: far,
38+
aspect,
39+
near,
40+
far,
4141
}
4242
.into()
4343
}
@@ -49,12 +49,12 @@ pub fn perspective<S: BaseFloat, A: Into<Rad<S>>>(
4949
/// [`glFrustum`]: http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml
5050
pub fn frustum<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4<S> {
5151
Perspective {
52-
left: left,
53-
right: right,
54-
bottom: bottom,
55-
top: top,
56-
near: near,
57-
far: far,
52+
left,
53+
right,
54+
bottom,
55+
top,
56+
near,
57+
far,
5858
}
5959
.into()
6060
}
@@ -66,12 +66,12 @@ pub fn frustum<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far:
6666
/// [`glOrtho`]: http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
6767
pub fn ortho<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4<S> {
6868
Ortho {
69-
left: left,
70-
right: right,
71-
bottom: bottom,
72-
top: top,
73-
near: near,
74-
far: far,
69+
left,
70+
right,
71+
bottom,
72+
top,
73+
near,
74+
far,
7575
}
7676
.into()
7777
}
@@ -99,8 +99,8 @@ impl<S: BaseFloat> PerspectiveFov<S> {
9999
right: xmax,
100100
bottom: -ymax,
101101
top: ymax,
102-
near: self.near.clone(),
103-
far: self.far.clone(),
102+
near: self.near,
103+
far: self.far,
104104
}
105105
}
106106
}

src/quaternion.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// limitations under the License.
1515

1616
use std::iter;
17-
use std::mem;
1817
use std::ops::*;
1918

2019
use num_traits::{cast, NumCast};
@@ -34,6 +33,7 @@ use num::BaseFloat;
3433
use point::Point3;
3534
use rotation::{Basis3, Rotation, Rotation3};
3635
use vector::Vector3;
36+
use quaternion;
3737

3838
#[cfg(feature = "mint")]
3939
use mint;
@@ -63,7 +63,7 @@ impl<S> Quaternion<S> {
6363
/// Construct a new quaternion from a scalar and a vector.
6464
#[inline]
6565
pub const fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S> {
66-
Quaternion { s: s, v: v }
66+
Quaternion { v, s }
6767
}
6868
}
6969

@@ -541,23 +541,22 @@ impl<S: BaseFloat> Rotation3 for Quaternion<S> {
541541
impl<S: BaseFloat> From<Quaternion<S>> for [S; 4] {
542542
#[inline]
543543
fn from(v: Quaternion<S>) -> Self {
544-
match v.into() {
545-
(xi, yj, zk, w) => [xi, yj, zk, w],
546-
}
544+
let (xi, yj, zk, w) = v.into();
545+
[xi, yj, zk, w]
547546
}
548547
}
549548

550549
impl<S: BaseFloat> AsRef<[S; 4]> for Quaternion<S> {
551550
#[inline]
552551
fn as_ref(&self) -> &[S; 4] {
553-
unsafe { mem::transmute(self) }
552+
unsafe { &*(self as *const quaternion::Quaternion<S> as *const [S; 4]) }
554553
}
555554
}
556555

557556
impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S> {
558557
#[inline]
559558
fn as_mut(&mut self) -> &mut [S; 4] {
560-
unsafe { mem::transmute(self) }
559+
unsafe { &mut *(self as *mut quaternion::Quaternion<S> as *mut [S; 4]) }
561560
}
562561
}
563562

@@ -571,63 +570,61 @@ impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
571570
impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S> {
572571
#[inline]
573572
fn from(v: &'a [S; 4]) -> &'a Quaternion<S> {
574-
unsafe { mem::transmute(v) }
573+
unsafe { &*(v as *const [S; 4] as *const quaternion::Quaternion<S>) }
575574
}
576575
}
577576

578577
impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S> {
579578
#[inline]
580579
fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion<S> {
581-
unsafe { mem::transmute(v) }
580+
unsafe { &mut *(v as *mut [S; 4] as *mut quaternion::Quaternion<S>) }
582581
}
583582
}
584583

585584
impl<S: BaseFloat> From<Quaternion<S>> for (S, S, S, S) {
586585
#[inline]
587586
fn from(v: Quaternion<S>) -> Self {
588-
match v {
589-
Quaternion {
587+
let Quaternion {
590588
s,
591589
v: Vector3 { x, y, z },
592-
} => (x, y, z, s),
593-
}
590+
} = v;
591+
(x, y, z, s)
594592
}
595593
}
596594

597595
impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S> {
598596
#[inline]
599597
fn as_ref(&self) -> &(S, S, S, S) {
600-
unsafe { mem::transmute(self) }
598+
unsafe { &*(self as *const quaternion::Quaternion<S> as *const (S, S, S, S)) }
601599
}
602600
}
603601

604602
impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S> {
605603
#[inline]
606604
fn as_mut(&mut self) -> &mut (S, S, S, S) {
607-
unsafe { mem::transmute(self) }
605+
unsafe { &mut *(self as *mut quaternion::Quaternion<S> as *mut (S, S, S, S)) }
608606
}
609607
}
610608

611609
impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S> {
612610
#[inline]
613611
fn from(v: (S, S, S, S)) -> Quaternion<S> {
614-
match v {
615-
(xi, yj, zk, w) => Quaternion::new(w, xi, yj, zk),
616-
}
612+
let (xi, yj, zk, w) = v;
613+
Quaternion::new(w, xi, yj, zk)
617614
}
618615
}
619616

620617
impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S> {
621618
#[inline]
622619
fn from(v: &'a (S, S, S, S)) -> &'a Quaternion<S> {
623-
unsafe { mem::transmute(v) }
620+
unsafe { &*(v as *const (S, S, S, S) as *const quaternion::Quaternion<S>) }
624621
}
625622
}
626623

627624
impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S> {
628625
#[inline]
629626
fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion<S> {
630-
unsafe { mem::transmute(v) }
627+
unsafe { &mut *(v as *mut (S, S, S, S) as *mut quaternion::Quaternion<S>) }
631628
}
632629
}
633630

src/transform.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ pub trait Transform<P: EuclideanSpace>: Sized + One {
4646

4747
/// Inverse transform a vector using this transform
4848
fn inverse_transform_vector(&self, vec: P::Diff) -> Option<P::Diff> {
49-
self.inverse_transform()
50-
.and_then(|inverse| Some(inverse.transform_vector(vec)))
49+
self.inverse_transform().map(|inverse| inverse.transform_vector(vec))
5150
}
5251

5352
/// Transform a point using this transform.
@@ -117,8 +116,8 @@ where
117116
let disp = rot.rotate_vector(P::origin() - eye);
118117
Decomposed {
119118
scale: P::Scalar::one(),
120-
rot: rot,
121-
disp: disp,
119+
rot,
120+
disp,
122121
}
123122
}
124123

@@ -128,8 +127,8 @@ where
128127
let disp = rot.rotate_vector(P::origin() - eye);
129128
Decomposed {
130129
scale: P::Scalar::one(),
131-
rot: rot,
132-
disp: disp,
130+
rot,
131+
disp,
133132
}
134133
}
135134

@@ -139,8 +138,8 @@ where
139138
let disp = rot.rotate_vector(P::origin() - eye);
140139
Decomposed {
141140
scale: P::Scalar::one(),
142-
rot: rot,
143-
disp: disp,
141+
rot,
142+
disp,
144143
}
145144
}
146145

@@ -201,7 +200,7 @@ pub trait Transform3:
201200
impl<S: BaseFloat, R: Rotation2<Scalar = S>> From<Decomposed<Vector2<S>, R>> for Matrix3<S> {
202201
fn from(dec: Decomposed<Vector2<S>, R>) -> Matrix3<S> {
203202
let m: Matrix2<_> = dec.rot.into();
204-
let mut m: Matrix3<_> = (&m * dec.scale).into();
203+
let mut m: Matrix3<_> = (m * dec.scale).into();
205204
m.z = dec.disp.extend(S::one());
206205
m
207206
}
@@ -210,7 +209,7 @@ impl<S: BaseFloat, R: Rotation2<Scalar = S>> From<Decomposed<Vector2<S>, R>> for
210209
impl<S: BaseFloat, R: Rotation3<Scalar = S>> From<Decomposed<Vector3<S>, R>> for Matrix4<S> {
211210
fn from(dec: Decomposed<Vector3<S>, R>) -> Matrix4<S> {
212211
let m: Matrix3<_> = dec.rot.into();
213-
let mut m: Matrix4<_> = (&m * dec.scale).into();
212+
let mut m: Matrix4<_> = (m * dec.scale).into();
214213
m.w = dec.disp.extend(S::one());
215214
m
216215
}

0 commit comments

Comments
 (0)