From b429d91fcf1a8a7315fd772759d9b3e0d099aace Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 13 Dec 2012 11:10:53 +1000 Subject: [PATCH] Remove num::cast::cast function and num::cast::NumCast::from method --- src/angle.rs | 21 +++++------ src/funs/triganomic.rs | 25 +++++++----- src/mat.rs | 86 +++++++++++++++--------------------------- src/num/conv.rs | 36 ------------------ src/num/types.rs | 54 +++++++++++++------------- src/quat.rs | 4 +- 6 files changed, 83 insertions(+), 143 deletions(-) diff --git a/src/angle.rs b/src/angle.rs index 98090f2..c69ae83 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -4,7 +4,6 @@ use std::cmp::FuzzyEq; use funs::triganomic::{cos, sin}; use mat::{Mat3, Mat4}; -use num::conv::cast; use num::types::{Float, Number}; use quat::Quat; use vec::Vec3; @@ -50,11 +49,11 @@ pub impl Radians: Angle { #[inline(always)] static pure fn zero() -> Radians { Radians(Number::zero()) } #[inline(always)] pure fn to_radians(&self) -> Radians { *self } - #[inline(always)] pure fn to_degrees(&self) -> Degrees { Degrees(**self * cast(180.0 / Float::pi())) } + #[inline(always)] pure fn to_degrees(&self) -> Degrees { Degrees(**self * Number::from(180.0 / Float::pi())) } #[inline(always)] pure fn wrap(&self) -> Radians { - let theta = (*self) % cast(2.0 * Float::pi()); + let theta = (*self) % Number::from(2.0 * Float::pi()); // keep in the domain of 0 to 1 rad if theta >= Angle::zero() { @@ -150,19 +149,19 @@ pub impl Radians: ToStr { pub enum Degrees = T; pub impl Degrees: Angle { - #[inline(always)] static pure fn full_turn() -> Degrees { Degrees(cast(360.0)) } - #[inline(always)] static pure fn half_turn() -> Degrees { Degrees(cast(180.0)) } - #[inline(always)] static pure fn quadrant() -> Degrees { Degrees(cast(90.0)) } - #[inline(always)] static pure fn sextant() -> Degrees { Degrees(cast(60.0)) } - #[inline(always)] static pure fn octant() -> Degrees { Degrees(cast(45.0)) } - #[inline(always)] static pure fn zero() -> Degrees { Degrees(cast(0.0)) } + #[inline(always)] static pure fn full_turn() -> Degrees { Degrees(Number::from(360.0)) } + #[inline(always)] static pure fn half_turn() -> Degrees { Degrees(Number::from(180.0)) } + #[inline(always)] static pure fn quadrant() -> Degrees { Degrees(Number::from(90.0)) } + #[inline(always)] static pure fn sextant() -> Degrees { Degrees(Number::from(60.0)) } + #[inline(always)] static pure fn octant() -> Degrees { Degrees(Number::from(45.0)) } + #[inline(always)] static pure fn zero() -> Degrees { Degrees(Number::from(0.0)) } - #[inline(always)] pure fn to_radians(&self) -> Radians { Radians(**self * cast(Float::pi::() / 180.0)) } + #[inline(always)] pure fn to_radians(&self) -> Radians { Radians(**self * Number::from(Float::pi::() / 180.0)) } #[inline(always)] pure fn to_degrees(&self) -> Degrees { *self } #[inline(always)] pure fn wrap(&self) -> Degrees { - let theta = (*self) % cast(360); + let theta = (*self) % Number::from(360); // keep in the domain of 0 to 360 degrees if theta >= Angle::zero() { diff --git a/src/funs/triganomic.rs b/src/funs/triganomic.rs index af8e920..08822d6 100644 --- a/src/funs/triganomic.rs +++ b/src/funs/triganomic.rs @@ -4,9 +4,8 @@ * This module corresponds to Section 8.1 of the [GLSL 4.30.6 specification] * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). */ -use angle::Radians; -use num::conv::cast; -use num::types::Number; +use angle::{Radians, Degrees}; +use num::types::{Number, Float}; use vec::{Vec3, Vec2, Vec4}; /** @@ -24,13 +23,19 @@ priv trait Trig { #[inline(always)] pub pure fn cos, R>(theta: &T) -> R { theta.cos() } #[inline(always)] pub pure fn tan, R>(theta: &T) -> R { theta.tan() } -priv impl Radians: Trig { - #[inline(always)] pure fn sin(&self) -> T { cast(f64::sin(cast(**self))) } - #[inline(always)] pure fn cos(&self) -> T { cast(f64::cos(cast(**self))) } - #[inline(always)] pure fn tan(&self) -> T { cast(f64::tan(cast(**self))) } +priv impl Radians: Trig { + #[inline(always)] pure fn sin(&self) -> T { Number::from(f64::sin(Number::from(**self))) } + #[inline(always)] pure fn cos(&self) -> T { Number::from(f64::cos(Number::from(**self))) } + #[inline(always)] pure fn tan(&self) -> T { Number::from(f64::tan(Number::from(**self))) } } -pub impl Vec2>: Trig> { +pub impl Degrees: Trig { + #[inline(always)] pure fn sin(&self) -> T { Number::from(f64::sin(Number::from(*self.to_radians()))) } + #[inline(always)] pure fn cos(&self) -> T { Number::from(f64::cos(Number::from(*self.to_radians()))) } + #[inline(always)] pure fn tan(&self) -> T { Number::from(f64::tan(Number::from(*self.to_radians()))) } +} + +pub impl Vec2>: Trig> { #[inline(always)] pure fn sin(&self) -> Vec2 { Vec2::new(sin(&self[0]), @@ -50,7 +55,7 @@ pub impl Vec2>: Trig> { } } -pub impl Vec3>: Trig> { +pub impl Vec3>: Trig> { #[inline(always)] pure fn sin(&self) -> Vec3 { Vec3::new(sin(&self[0]), @@ -73,7 +78,7 @@ pub impl Vec3>: Trig> { } } -pub impl Vec4>: Trig> { +pub impl Vec4>: Trig> { #[inline(always)] pure fn sin(&self) -> Vec4 { Vec4::new(sin(&self[0]), diff --git a/src/mat.rs b/src/mat.rs index c9ba72c..ca9d79d 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -10,7 +10,6 @@ use angle::Angle; use funs::common::*; use funs::exponential::*; use funs::triganomic::{sin, cos}; -use num::conv::cast; use num::types::{Float, Number}; use quat::{Quat, ToQuat}; use vec::{NumericVector, Vec2, Vec3, Vec4}; @@ -356,8 +355,7 @@ pub impl Mat2 { */ #[inline(always)] static pure fn from_value(value: T) -> Mat2 { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE + let _0 = Number::from(0); Mat2::new(value, _0, _0, value) } @@ -365,10 +363,8 @@ pub impl Mat2 { // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn identity() -> Mat2 { - let _0 = cast(0); - let _1 = cast(1); - // let _0 = Number::from(0); // FIXME: causes ICE - // let _1 = Number::from(1); // FIXME: causes ICE + let _0 = Number::from(0); + let _1 = Number::from(1); Mat2::new(_1, _0, _0, _1) } @@ -376,8 +372,7 @@ pub impl Mat2 { // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn zero() -> Mat2 { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE + let _0 = Number::from(0); Mat2::new(_0, _0, _0, _0) } @@ -474,10 +469,8 @@ pub impl Mat2: Matrix> { #[inline(always)] pure fn inverse(&self) -> Option> { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE let d = self.determinant(); - if d.fuzzy_eq(&_0) { + if d.fuzzy_eq(&Number::from(0)) { None } else { Some(Mat2::new( self[1][1]/d, -self[0][1]/d, @@ -499,8 +492,7 @@ pub impl Mat2: Matrix> { #[inline(always)] pure fn is_diagonal(&self) -> bool { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE + let _0 = Number::from(0); self[0][1].fuzzy_eq(&_0) && self[1][0].fuzzy_eq(&_0) } @@ -519,9 +511,7 @@ pub impl Mat2: Matrix> { #[inline(always)] pure fn is_invertible(&self) -> bool { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE - !self.determinant().fuzzy_eq(&_0) + !self.determinant().fuzzy_eq(&Number::from(0)) } #[inline(always)] @@ -751,8 +741,7 @@ pub impl Mat3 { */ #[inline(always)] static pure fn from_value(value: T) -> Mat3 { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE + let _0 = Number::from(0); Mat3::new(value, _0, _0, _0, value, _0, _0, _0, value) @@ -760,10 +749,8 @@ pub impl Mat3 { #[inline(always)] static pure fn from_Mat2(m: &Mat2) -> Mat3 { - let _0 = cast(0); - let _1 = cast(1); - // let _0 = Number::from(0); // FIXME: causes ICE - // let _1 = Number::from(1); // FIXME: causes ICE + let _0 = Number::from(0); + let _1 = Number::from(1); Mat3::new(m[0][0], m[0][1], _0, m[1][0], m[1][1], _0, _0, _0, _1) @@ -772,8 +759,8 @@ pub impl Mat3 { // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn identity() -> Mat3 { - let _0 = cast(0); - let _1 = cast(1); + let _0 = Number::from(0); + let _1 = Number::from(1); Mat3::new(_1, _0, _0, _0, _1, _0, _0, _0, _1) @@ -782,7 +769,7 @@ pub impl Mat3 { // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn zero() -> Mat3 { - let _0 = cast(0); + let _0 = Number::from(0); Mat3::new(_0, _0, _0, _0, _0, _0, _0, _0, _0) @@ -815,8 +802,6 @@ pub impl Mat3: Matrix> { */ #[inline(always)] static pure fn identity() -> Mat3 { - // let _0 = cast(0); - // let _1 = cast(1); let _0 = Number::from(0); let _1 = Number::from(1); Mat3::new(_1, _0, _0, @@ -895,15 +880,12 @@ pub impl Mat3: Matrix> { // #[inline(always)] pure fn inverse(&self) -> Option> { let d = self.determinant(); - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE - if d.fuzzy_eq(&_0) { + if d.fuzzy_eq(&Number::from(0)) { None } else { Some(Mat3::from_cols(self[1].cross(&self[2]).div_t(d), self[2].cross(&self[0]).div_t(d), - self[0].cross(&self[1]).div_t(d)) - .transpose()) + self[0].cross(&self[1]).div_t(d)).transpose()) } } @@ -922,8 +904,7 @@ pub impl Mat3: Matrix> { #[inline(always)] pure fn is_diagonal(&self) -> bool { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE + let _0 = Number::from(0); self[0][1].fuzzy_eq(&_0) && self[0][2].fuzzy_eq(&_0) && @@ -954,9 +935,7 @@ pub impl Mat3: Matrix> { #[inline(always)] pure fn is_invertible(&self) -> bool { - let _0 = cast(0); - // let _0 = Number::from(0); // FIXME: causes ICE - !self.determinant().fuzzy_eq(&_0) + !self.determinant().fuzzy_eq(&Number::zero()) } #[inline(always)] @@ -1055,10 +1034,8 @@ pub impl Mat3: Matrix3> { static pure fn from_axis_angle>(axis: &Vec3, theta: A) -> Mat3 { let c: T = cos(&theta.to_radians()); let s: T = sin(&theta.to_radians()); - let _0: T = cast(0); - let _1: T = cast(1); - // let _0: T = Number::from(0); // FIXME: causes ICE - // let _1: T = Number::from(1); // FIXME: causes ICE + let _0: T = Number::from(0); + let _1: T = Number::from(1); let _1_c: T = _1 - c; let x = axis.x; @@ -1271,7 +1248,7 @@ pub impl Mat4 { */ #[inline(always)] static pure fn from_value(value: T) -> Mat4 { - let _0 = cast(0); + let _0 = Number::from(0); Mat4::new(value, _0, _0, _0, _0, value, _0, _0, _0, _0, value, _0, @@ -1280,8 +1257,8 @@ pub impl Mat4 { #[inline(always)] static pure fn from_Mat2(m: &Mat2) -> Mat4 { - let _0 = cast(0); - let _1 = cast(1); + let _0 = Number::from(0); + let _1 = Number::from(1); Mat4::new(m[0][0], m[0][1], _0, _0, m[1][0], m[1][1], _0, _0, _0, _0, _1, _0, @@ -1290,8 +1267,8 @@ pub impl Mat4 { #[inline(always)] static pure fn from_Mat3(m: &Mat3) -> Mat4 { - let _0 = cast(0); - let _1 = cast(1); + let _0 = Number::from(0); + let _1 = Number::from(1); Mat4::new(m[0][0], m[0][1], m[0][2], _0, m[1][0], m[1][1], m[1][2], _0, m[2][0], m[2][1], m[2][2], _0, @@ -1301,8 +1278,8 @@ pub impl Mat4 { // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn identity() -> Mat4 { - let _0 = cast(0); - let _1 = cast(1); + let _0 = Number::from(0); + let _1 = Number::from(1); Mat4::new(_1, _0, _0, _0, _0, _1, _0, _0, _0, _0, _1, _0, @@ -1312,7 +1289,7 @@ pub impl Mat4 { // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn zero() -> Mat4 { - let _0 = cast(0); + let _0 = Number::from(0); Mat4::new(_0, _0, _0, _0, _0, _0, _0, _0, _0, _0, _0, _0, @@ -1449,9 +1426,7 @@ pub impl Mat4: Matrix> { pure fn inverse(&self) -> Option> { let d = self.determinant(); - // let _0 = Number::from(0); // FIXME: Triggers ICE - let _0 = cast(0); - if d.fuzzy_eq(&_0) { + if d.fuzzy_eq(&Number::from(0)) { None } else { @@ -1512,7 +1487,7 @@ pub impl Mat4: Matrix> { #[inline(always)] pure fn is_diagonal(&self) -> bool { - let _0 = cast(0); + let _0 = Number::from(0); self[0][1].fuzzy_eq(&_0) && self[0][2].fuzzy_eq(&_0) && self[0][3].fuzzy_eq(&_0) && @@ -1557,8 +1532,7 @@ pub impl Mat4: Matrix> { #[inline(always)] pure fn is_invertible(&self) -> bool { - let _0 = cast(0); - !self.determinant().fuzzy_eq(&_0) + !self.determinant().fuzzy_eq(&Number::zero()) } #[inline(always)] diff --git a/src/num/conv.rs b/src/num/conv.rs index 2ebdc42..3ed4800 100644 --- a/src/num/conv.rs +++ b/src/num/conv.rs @@ -1,14 +1,7 @@ /** * Wrapper methods for numeric type casts - * - * Note: although the `from` and `cast` medods are still inclueded, they will - * be phased out in favour of the `num::kinds::Number::from(n: T) -> self; pure fn to_u8(&self) -> u8; pure fn to_u16(&self) -> u16; @@ -27,12 +20,7 @@ pub trait NumConv { pure fn to_float(&self) -> float; } -#[inline(always)] -pub pure fn cast(n: T) -> U { NumConv::from(move n) } - pub impl u8: NumConv { - #[inline(always)] static pure fn from(n: T) -> u8 { n.to_u8() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -51,8 +39,6 @@ pub impl u8: NumConv { } pub impl u16: NumConv { - #[inline(always)] static pure fn from(n: T) -> u16 { n.to_u16() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -71,8 +57,6 @@ pub impl u16: NumConv { } pub impl u32: NumConv { - #[inline(always)] static pure fn from(n: T) -> u32 { n.to_u32() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self } @@ -91,8 +75,6 @@ pub impl u32: NumConv { } pub impl u64: NumConv { - #[inline(always)] static pure fn from(n: T) -> u64 { n.to_u64() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -111,8 +93,6 @@ pub impl u64: NumConv { } pub impl uint: NumConv { - #[inline(always)] static pure fn from(n: T) -> uint { n.to_uint() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -131,8 +111,6 @@ pub impl uint: NumConv { } pub impl i8: NumConv { - #[inline(always)] static pure fn from(n: T) -> i8 { n.to_i8() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -151,8 +129,6 @@ pub impl i8: NumConv { } pub impl i16: NumConv { - #[inline(always)] static pure fn from(n: T) -> i16 { n.to_i16() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -171,8 +147,6 @@ pub impl i16: NumConv { } pub impl i32: NumConv { - #[inline(always)] static pure fn from(n: T) -> i32 { n.to_i32() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -191,8 +165,6 @@ pub impl i32: NumConv { } pub impl i64: NumConv { - #[inline(always)] static pure fn from(n: T) -> i64 { n.to_i64() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -211,8 +183,6 @@ pub impl i64: NumConv { } pub impl int: NumConv { - #[inline(always)] static pure fn from(n: T) -> int { n.to_int_() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -231,8 +201,6 @@ pub impl int: NumConv { } pub impl f32: NumConv { - #[inline(always)] static pure fn from(n: T) -> f32 { n.to_f32() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -251,8 +219,6 @@ pub impl f32: NumConv { } pub impl f64: NumConv { - #[inline(always)] static pure fn from(n: T) -> f64 { n.to_f64() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } @@ -271,8 +237,6 @@ pub impl f64: NumConv { } pub impl float: NumConv { - #[inline(always)] static pure fn from(n: T) -> float { n.to_float() } - #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 } diff --git a/src/num/types.rs b/src/num/types.rs index 4cb7d28..2695c14 100644 --- a/src/num/types.rs +++ b/src/num/types.rs @@ -16,7 +16,7 @@ pub trait Number: Eq Num NumConv Ord { * assert twenty == 20f32; * ~~~ */ - static pure fn from(n: T) -> self; + static pure fn from(n: T) -> self; static pure fn size_of() -> uint; static pure fn bits() -> uint; @@ -27,9 +27,9 @@ pub trait Number: Eq Num NumConv Ord { pub impl u8: Number { /** - * Construct a `u8` from the type `T:Number` + * Construct a `u8` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> u8 { n.to_u8() } + #[inline(always)] static pure fn from(n: T) -> u8 { n.to_u8() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 8 } @@ -40,9 +40,9 @@ pub impl u8: Number { pub impl u16: Number { /** - * Construct a `u16` from the type `T:Number` + * Construct a `u16` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> u16 { n.to_u16() } + #[inline(always)] static pure fn from(n: T) -> u16 { n.to_u16() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 16 } @@ -53,9 +53,9 @@ pub impl u16: Number { pub impl u32: Number { /** - * Construct a `u32` from the type `T:Number` + * Construct a `u32` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> u32 { n.to_u32() } + #[inline(always)] static pure fn from(n: T) -> u32 { n.to_u32() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 32 } @@ -66,9 +66,9 @@ pub impl u32: Number { pub impl u64: Number { /** - * Construct a `u64` from the type `T:Number` + * Construct a `u64` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> u64 { n.to_u64() } + #[inline(always)] static pure fn from(n: T) -> u64 { n.to_u64() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 64 } @@ -79,9 +79,9 @@ pub impl u64: Number { pub impl uint: Number { /** - * Construct a `uint` from the type `T:Number` + * Construct a `uint` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> uint { n.to_uint() } + #[inline(always)] static pure fn from(n: T) -> uint { n.to_uint() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { sys::size_of::() * 8 } @@ -92,9 +92,9 @@ pub impl uint: Number { pub impl i8: Number { /** - * Construct an `i8` from the type `T:Number` + * Construct an `i8` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> i8 { n.to_i8() } + #[inline(always)] static pure fn from(n: T) -> i8 { n.to_i8() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 8 } @@ -105,9 +105,9 @@ pub impl i8: Number { pub impl i16: Number { /** - * Construct an `i16` from the type `T:Number` + * Construct an `i16` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> i16 { n.to_i16() } + #[inline(always)] static pure fn from(n: T) -> i16 { n.to_i16() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 16 } @@ -118,9 +118,9 @@ pub impl i16: Number { pub impl i32: Number { /** - * Construct an `i32` from the type `T:Number` + * Construct an `i32` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> i32 { n.to_i32() } + #[inline(always)] static pure fn from(n: T) -> i32 { n.to_i32() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 32 } @@ -131,9 +131,9 @@ pub impl i32: Number { pub impl i64: Number { /** - * Construct an `i64` from the type `T:Number` + * Construct an `i64` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> i64 { n.to_i64() } + #[inline(always)] static pure fn from(n: T) -> i64 { n.to_i64() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 64 } @@ -144,9 +144,9 @@ pub impl i64: Number { pub impl int: Number { /** - * Construct an `int` from the type `T:Number` + * Construct an `int` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> int { n.to_int_() } + #[inline(always)] static pure fn from(n: T) -> int { n.to_int_() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { sys::size_of::() * 8 } @@ -157,9 +157,9 @@ pub impl int: Number { pub impl f32: Number { /** - * Construct a `f32` from the type `T:Number` + * Construct a `f32` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> f32 { n.to_f32() } + #[inline(always)] static pure fn from(n: T) -> f32 { n.to_f32() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 32 } @@ -170,9 +170,9 @@ pub impl f32: Number { pub impl f64: Number { /** - * Construct a `f64` from the type `T:Number` + * Construct a `f64` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> f64 { n.to_f64() } + #[inline(always)] static pure fn from(n: T) -> f64 { n.to_f64() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { 64 } @@ -183,9 +183,9 @@ pub impl f64: Number { pub impl float: Number { /** - * Construct a `float` from the type `T:Number` + * Construct a `float` from the type `T` */ - #[inline(always)] static pure fn from(n: T) -> float { n.to_float() } + #[inline(always)] static pure fn from(n: T) -> float { n.to_float() } #[inline(always)] static pure fn size_of() -> uint { sys::size_of::() } #[inline(always)] static pure fn bits() -> uint { sys::size_of::() * 8 } diff --git a/src/quat.rs b/src/quat.rs index 44407d9..9b3e69d 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -21,7 +21,6 @@ use funs::exponential::*; use funs::triganomic::*; use mat::{Mat3, Mat4}; use num::types::{Float, Number}; -use num::conv::cast; use vec::Vec3; @@ -240,8 +239,7 @@ pub impl Quat { #[inline(always)] static pure fn from_axis_angle>(axis: &Vec3, theta: A) -> Quat { - // let half = theta.to_radians() / Number::from(2); - let half = theta.to_radians() / cast(2); + let half = theta.to_radians() / Number::from(2); Quat::from_sv(cos(&half), axis.mul_t(sin(&half))) } }