Remove num::cast::cast function and num::cast::NumCast::from method

This commit is contained in:
Brendan Zabarauskas 2012-12-13 11:10:53 +10:00
parent bc9104fdb5
commit b429d91fcf
6 changed files with 83 additions and 143 deletions

View file

@ -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<T:Copy Float> Radians<T>: Angle<T> {
#[inline(always)] static pure fn zero() -> Radians<T> { Radians(Number::zero()) }
#[inline(always)] pure fn to_radians(&self) -> Radians<T> { *self }
#[inline(always)] pure fn to_degrees(&self) -> Degrees<T> { Degrees(**self * cast(180.0 / Float::pi())) }
#[inline(always)] pure fn to_degrees(&self) -> Degrees<T> { Degrees(**self * Number::from(180.0 / Float::pi())) }
#[inline(always)]
pure fn wrap(&self) -> Radians<T> {
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<T> Radians<T>: ToStr {
pub enum Degrees<T> = T;
pub impl<T:Copy Float> Degrees<T>: Angle<T> {
#[inline(always)] static pure fn full_turn() -> Degrees<T> { Degrees(cast(360.0)) }
#[inline(always)] static pure fn half_turn() -> Degrees<T> { Degrees(cast(180.0)) }
#[inline(always)] static pure fn quadrant() -> Degrees<T> { Degrees(cast(90.0)) }
#[inline(always)] static pure fn sextant() -> Degrees<T> { Degrees(cast(60.0)) }
#[inline(always)] static pure fn octant() -> Degrees<T> { Degrees(cast(45.0)) }
#[inline(always)] static pure fn zero() -> Degrees<T> { Degrees(cast(0.0)) }
#[inline(always)] static pure fn full_turn() -> Degrees<T> { Degrees(Number::from(360.0)) }
#[inline(always)] static pure fn half_turn() -> Degrees<T> { Degrees(Number::from(180.0)) }
#[inline(always)] static pure fn quadrant() -> Degrees<T> { Degrees(Number::from(90.0)) }
#[inline(always)] static pure fn sextant() -> Degrees<T> { Degrees(Number::from(60.0)) }
#[inline(always)] static pure fn octant() -> Degrees<T> { Degrees(Number::from(45.0)) }
#[inline(always)] static pure fn zero() -> Degrees<T> { Degrees(Number::from(0.0)) }
#[inline(always)] pure fn to_radians(&self) -> Radians<T> { Radians(**self * cast(Float::pi::<float>() / 180.0)) }
#[inline(always)] pure fn to_radians(&self) -> Radians<T> { Radians(**self * Number::from(Float::pi::<float>() / 180.0)) }
#[inline(always)] pure fn to_degrees(&self) -> Degrees<T> { *self }
#[inline(always)]
pure fn wrap(&self) -> Degrees<T> {
let theta = (*self) % cast(360);
let theta = (*self) % Number::from(360);
// keep in the domain of 0 to 360 degrees
if theta >= Angle::zero() {

View file

@ -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<T> {
#[inline(always)] pub pure fn cos<T:Trig<R>, R>(theta: &T) -> R { theta.cos() }
#[inline(always)] pub pure fn tan<T:Trig<R>, R>(theta: &T) -> R { theta.tan() }
priv impl<T:Copy Number> Radians<T>: Trig<T> {
#[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<T:Copy Float> Radians<T>: Trig<T> {
#[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<T:Copy Number> Vec2<Radians<T>>: Trig<Vec2<T>> {
pub impl<T:Copy Float> Degrees<T>: Trig<T> {
#[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<T:Copy Float> Vec2<Radians<T>>: Trig<Vec2<T>> {
#[inline(always)]
pure fn sin(&self) -> Vec2<T> {
Vec2::new(sin(&self[0]),
@ -50,7 +55,7 @@ pub impl<T:Copy Number> Vec2<Radians<T>>: Trig<Vec2<T>> {
}
}
pub impl<T:Copy Number> Vec3<Radians<T>>: Trig<Vec3<T>> {
pub impl<T:Copy Float> Vec3<Radians<T>>: Trig<Vec3<T>> {
#[inline(always)]
pure fn sin(&self) -> Vec3<T> {
Vec3::new(sin(&self[0]),
@ -73,7 +78,7 @@ pub impl<T:Copy Number> Vec3<Radians<T>>: Trig<Vec3<T>> {
}
}
pub impl<T:Copy Number> Vec4<Radians<T>>: Trig<Vec4<T>> {
pub impl<T:Copy Float> Vec4<Radians<T>>: Trig<Vec4<T>> {
#[inline(always)]
pure fn sin(&self) -> Vec4<T> {
Vec4::new(sin(&self[0]),

View file

@ -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<T:Copy Float> Mat2<T> {
*/
#[inline(always)]
static pure fn from_value(value: T) -> Mat2<T> {
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<T:Copy Float> Mat2<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn identity() -> Mat2<T> {
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<T:Copy Float> Mat2<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn zero() -> Mat2<T> {
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<T:Copy Float> Mat2<T>: Matrix<T, Vec2<T>> {
#[inline(always)]
pure fn inverse(&self) -> Option<Mat2<T>> {
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<T:Copy Float> Mat2<T>: Matrix<T, Vec2<T>> {
#[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<T:Copy Float> Mat2<T>: Matrix<T, Vec2<T>> {
#[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<T:Copy Float> Mat3<T> {
*/
#[inline(always)]
static pure fn from_value(value: T) -> Mat3<T> {
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<T:Copy Float> Mat3<T> {
#[inline(always)]
static pure fn from_Mat2(m: &Mat2<T>) -> Mat3<T> {
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<T:Copy Float> Mat3<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn identity() -> Mat3<T> {
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<T:Copy Float> Mat3<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn zero() -> Mat3<T> {
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<T:Copy Float> Mat3<T>: Matrix<T, Vec3<T>> {
*/
#[inline(always)]
static pure fn identity() -> Mat3<T> {
// 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<T:Copy Float> Mat3<T>: Matrix<T, Vec3<T>> {
// #[inline(always)]
pure fn inverse(&self) -> Option<Mat3<T>> {
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<T:Copy Float> Mat3<T>: Matrix<T, Vec3<T>> {
#[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<T:Copy Float> Mat3<T>: Matrix<T, Vec3<T>> {
#[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<T:Copy Float> Mat3<T>: Matrix3<T, Vec3<T>> {
static pure fn from_axis_angle<A:Angle<T>>(axis: &Vec3<T>, theta: A) -> Mat3<T> {
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<T:Copy Float> Mat4<T> {
*/
#[inline(always)]
static pure fn from_value(value: T) -> Mat4<T> {
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<T:Copy Float> Mat4<T> {
#[inline(always)]
static pure fn from_Mat2(m: &Mat2<T>) -> Mat4<T> {
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<T:Copy Float> Mat4<T> {
#[inline(always)]
static pure fn from_Mat3(m: &Mat3<T>) -> Mat4<T> {
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<T:Copy Float> Mat4<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn identity() -> Mat4<T> {
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<T:Copy Float> Mat4<T> {
// FIXME: An interim solution to the issues with static functions
#[inline(always)]
static pure fn zero() -> Mat4<T> {
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<T:Copy Float Sign> Mat4<T>: Matrix<T, Vec4<T>> {
pure fn inverse(&self) -> Option<Mat4<T>> {
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<T:Copy Float Sign> Mat4<T>: Matrix<T, Vec4<T>> {
#[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<T:Copy Float Sign> Mat4<T>: Matrix<T, Vec4<T>> {
#[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)]

View file

@ -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<T:Number(n: T)`
* static constructor method. I feel that this will be far clearer than using
* the `cast` function everywhere.
*/
pub trait NumConv {
// TODO: remove and use `num::kinds::Number::from` instead
static pure fn from<T:NumConv>(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<T:NumConv, U:NumConv>(n: T) -> U { NumConv::from(move n) }
pub impl u8: NumConv {
#[inline(always)] static pure fn from<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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<T:NumConv>(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 }

View file

@ -16,7 +16,7 @@ pub trait Number: Eq Num NumConv Ord {
* assert twenty == 20f32;
* ~~~
*/
static pure fn from<T:Number>(n: T) -> self;
static pure fn from<T:NumConv>(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<T:Number>(n: T) -> u8 { n.to_u8() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> u8 { n.to_u8() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<u8>() }
#[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<T:Number>(n: T) -> u16 { n.to_u16() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> u16 { n.to_u16() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<u16>() }
#[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<T:Number>(n: T) -> u32 { n.to_u32() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> u32 { n.to_u32() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<u32>() }
#[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<T:Number>(n: T) -> u64 { n.to_u64() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> u64 { n.to_u64() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<u64>() }
#[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<T:Number>(n: T) -> uint { n.to_uint() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> uint { n.to_uint() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<uint>() }
#[inline(always)] static pure fn bits() -> uint { sys::size_of::<uint>() * 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<T:Number>(n: T) -> i8 { n.to_i8() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> i8 { n.to_i8() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<i8>() }
#[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<T:Number>(n: T) -> i16 { n.to_i16() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> i16 { n.to_i16() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<i16>() }
#[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<T:Number>(n: T) -> i32 { n.to_i32() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> i32 { n.to_i32() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<i32>() }
#[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<T:Number>(n: T) -> i64 { n.to_i64() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> i64 { n.to_i64() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<i64>() }
#[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<T:Number>(n: T) -> int { n.to_int_() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> int { n.to_int_() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<int>() }
#[inline(always)] static pure fn bits() -> uint { sys::size_of::<int>() * 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<T:Number>(n: T) -> f32 { n.to_f32() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> f32 { n.to_f32() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<f32>() }
#[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<T:Number>(n: T) -> f64 { n.to_f64() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> f64 { n.to_f64() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<f64>() }
#[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<T:Number>(n: T) -> float { n.to_float() }
#[inline(always)] static pure fn from<T:NumConv>(n: T) -> float { n.to_float() }
#[inline(always)] static pure fn size_of() -> uint { sys::size_of::<float>() }
#[inline(always)] static pure fn bits() -> uint { sys::size_of::<float>() * 8 }

View file

@ -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<T:Copy Float> Quat<T> {
#[inline(always)]
static pure fn from_axis_angle<A:Angle<T>>(axis: &Vec3<T>, theta: A) -> Quat<T> {
// 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)))
}
}