From 165e095a5744d893159d80ff5c82fa40f2c2a88a Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 2 Apr 2015 04:11:15 -0400 Subject: [PATCH] Remove use of num::cast Signed-off-by: Anders Kaseorg --- src/structs/ortho.rs | 13 ++++++------- src/structs/quat.rs | 7 +++---- src/traits/structure.rs | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/structs/ortho.rs b/src/structs/ortho.rs index 19b38e84..39a15181 100644 --- a/src/structs/ortho.rs +++ b/src/structs/ortho.rs @@ -1,5 +1,4 @@ -use std::num; -use traits::structure::BaseFloat; +use traits::structure::{BaseFloat, Cast}; use structs::{Pnt3, Vec3, Mat4}; #[cfg(feature="arbitrary")] @@ -162,13 +161,13 @@ impl OrthoMat3 { /// The width of the view cuboid. #[inline] pub fn width(&self) -> N { - num::cast::(2.0).unwrap() / self.mat.m11 + >::from(2.0) / self.mat.m11 } /// The height of the view cuboid. #[inline] pub fn height(&self) -> N { - num::cast::(2.0).unwrap() / self.mat.m22 + >::from(2.0) / self.mat.m22 } /// The near plane offset of the view cuboid. @@ -187,14 +186,14 @@ impl OrthoMat3 { #[inline] pub fn set_width(&mut self, width: N) { assert!(!::is_zero(&width)); - self.mat.m11 = num::cast::(2.0).unwrap() / width; + self.mat.m11 = >::from(2.0) / width; } /// Sets the height of the view cuboid. #[inline] pub fn set_height(&mut self, height: N) { assert!(!::is_zero(&height)); - self.mat.m22 = num::cast::(2.0).unwrap() / height; + self.mat.m22 = >::from(2.0) / height; } /// Sets the near plane offset of the view cuboid. @@ -215,7 +214,7 @@ impl OrthoMat3 { #[inline] pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) { assert!(!::is_zero(&(zfar - znear))); - self.mat.m33 = -num::cast::(2.0).unwrap() / (zfar - znear); + self.mat.m33 = ->::from(2.0) / (zfar - znear); self.mat.m34 = -(zfar + znear) / (zfar - znear); } diff --git a/src/structs/quat.rs b/src/structs/quat.rs index 509c42f1..c1fe1a00 100644 --- a/src/structs/quat.rs +++ b/src/structs/quat.rs @@ -3,7 +3,6 @@ #![allow(missing_docs)] // we allow missing to avoid having to document the dispatch trait. use std::mem; -use std::num; use std::slice::{Iter, IterMut}; use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut}; use std::iter::{FromIterator, IntoIterator}; @@ -176,7 +175,7 @@ impl UnitQuat { } else { let ang = sqang.sqrt(); - let (s, c) = (ang / num::cast(2.0f64).unwrap()).sin_cos(); + let (s, c) = (ang / Cast::from(2.0)).sin_cos(); let s_ang = s / ang; @@ -205,7 +204,7 @@ impl UnitQuat { /// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw. #[inline] pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> UnitQuat { - let _0_5: N = num::cast(0.5f64).unwrap(); + let _0_5: N = Cast::from(0.5); let (sr, cr) = (roll * _0_5).sin_cos(); let (sp, cp) = (pitch * _0_5).sin_cos(); let (sy, cy) = (yaw * _0_5).sin_cos(); @@ -223,7 +222,7 @@ impl UnitQuat { /// Builds a rotation matrix from this quaternion. pub fn to_rot(&self) -> Rot3 { - let _2: N = num::cast(2.0f64).unwrap(); + let _2: N = Cast::from(2.0); let ww = self.q.w * self.q.w; let ii = self.q.i * self.q.i; let jj = self.q.j * self.q.j; diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 7547c957..fde314c1 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -16,7 +16,7 @@ pub trait BaseNum: Copy + Zero + One + } /// Basic floating-point number numeric trait. -pub trait BaseFloat: Float + BaseNum { +pub trait BaseFloat: Float + Cast + BaseNum { /// Archimedes' constant. fn pi() -> Self; /// 2.0 * pi.