Remove zero and one methods from NumCast
This commit is contained in:
parent
e62e914035
commit
ddc7559153
4 changed files with 29 additions and 71 deletions
|
@ -3,7 +3,7 @@ use core::f64::consts::pi;
|
|||
|
||||
use funs::triganomic::{cos, sin};
|
||||
use mat::{Mat3, Mat4};
|
||||
use num::kinds::Float;
|
||||
use num::kinds::{Float, Number};
|
||||
use num::cast::{NumCast, cast};
|
||||
use quat::Quat;
|
||||
use vec::Vec3;
|
||||
|
@ -46,7 +46,7 @@ pub impl<T:Copy Float> Radians<T>: Angle<T> {
|
|||
#[inline(always)] static pure fn quadrant() -> Radians<T> { Radians(Float::pi_2()) }
|
||||
#[inline(always)] static pure fn sextant() -> Radians<T> { Radians(Float::pi_3()) }
|
||||
#[inline(always)] static pure fn octant() -> Radians<T> { Radians(Float::pi_4()) }
|
||||
#[inline(always)] static pure fn zero() -> Radians<T> { Radians(NumCast::zero()) }
|
||||
#[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 / pi)) }
|
||||
|
|
|
@ -8,9 +8,6 @@ pub trait NumCast {
|
|||
static pure fn from<T:NumCast>(n: T) -> self;
|
||||
pure fn cast<T:NumCast>(&self) -> T;
|
||||
|
||||
static pure fn zero() -> self;
|
||||
static pure fn one() -> self;
|
||||
|
||||
pure fn to_u8(&self) -> u8;
|
||||
pure fn to_u16(&self) -> u16;
|
||||
pure fn to_u32(&self) -> u32;
|
||||
|
@ -35,9 +32,6 @@ pub impl u8: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u8 { n.to_u8() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> u8 { 0u8 }
|
||||
static pure fn one() -> u8 { 1u8 }
|
||||
|
||||
#[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 }
|
||||
|
@ -59,9 +53,6 @@ pub impl u16: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u16 { n.to_u16() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> u16 { 0u16 }
|
||||
static pure fn one() -> u16 { 1u16 }
|
||||
|
||||
#[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 }
|
||||
|
@ -83,9 +74,6 @@ pub impl u32: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u32 { n.to_u32() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> u32 { 0u32 }
|
||||
static pure fn one() -> u32 { 1u32 }
|
||||
|
||||
#[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 }
|
||||
|
@ -107,9 +95,6 @@ pub impl u64: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u64 { n.to_u64() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> u64 { 0u64 }
|
||||
static pure fn one() -> u64 { 1u64 }
|
||||
|
||||
#[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,9 +116,6 @@ pub impl uint: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> uint { n.to_uint() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> uint { 0u }
|
||||
static pure fn one() -> uint { 1u }
|
||||
|
||||
#[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 }
|
||||
|
@ -155,9 +137,6 @@ pub impl i8: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i8 { n.to_i8() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> i8 { 0i8 }
|
||||
static pure fn one() -> i8 { 1i8 }
|
||||
|
||||
#[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 }
|
||||
|
@ -179,9 +158,6 @@ pub impl i16: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i16 { n.to_i16() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> i16 { 0i16 }
|
||||
static pure fn one() -> i16 { 1i16 }
|
||||
|
||||
#[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 }
|
||||
|
@ -203,9 +179,6 @@ pub impl i32: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i32 { n.to_i32() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> i32 { 0i32 }
|
||||
static pure fn one() -> i32 { 1i32 }
|
||||
|
||||
#[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 }
|
||||
|
@ -227,9 +200,6 @@ pub impl i64: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i64 { n.to_i64() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> i64 { 0i64 }
|
||||
static pure fn one() -> i64 { 1i64 }
|
||||
|
||||
#[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,9 +221,6 @@ pub impl int: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> int { n.to_int() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> int { 0 }
|
||||
static pure fn one() -> int { 1 }
|
||||
|
||||
#[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 }
|
||||
|
@ -275,9 +242,6 @@ pub impl f32: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> f32 { n.to_f32() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> f32 { 0f32 }
|
||||
static pure fn one() -> f32 { 1f32 }
|
||||
|
||||
#[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 }
|
||||
|
@ -299,9 +263,6 @@ pub impl f64: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> f64 { n.to_f64() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> f64 { 0f64 }
|
||||
static pure fn one() -> f64 { 1f64 }
|
||||
|
||||
#[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 }
|
||||
|
@ -323,9 +284,6 @@ pub impl float: NumCast {
|
|||
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> float { n.to_float() }
|
||||
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) }
|
||||
|
||||
static pure fn zero() -> float { 0f }
|
||||
static pure fn one() -> float { 1f }
|
||||
|
||||
#[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 }
|
||||
|
|
18
src/quat.rs
18
src/quat.rs
|
@ -13,7 +13,7 @@ use funs::triganomic::*;
|
|||
use mat::{Mat3, Mat4};
|
||||
use num::cast::*;
|
||||
use num::default_eq::DefaultEq;
|
||||
use num::kinds::Float;
|
||||
use num::kinds::{Float, Number};
|
||||
use vec::Vec3;
|
||||
|
||||
|
||||
|
@ -99,18 +99,18 @@ pub impl<T:Copy> Quat<T>: ToPtr<T> {
|
|||
pub impl<T:Copy Float Exp Extent InvTrig> Quat<T>: Quaternion<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Quat<T> {
|
||||
Quat::new(NumCast::one(),
|
||||
NumCast::one(),
|
||||
NumCast::one(),
|
||||
NumCast::one())
|
||||
Quat::new(Number::one(),
|
||||
Number::one(),
|
||||
Number::one(),
|
||||
Number::one())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Quat<T> {
|
||||
Quat::new(NumCast::zero(),
|
||||
NumCast::zero(),
|
||||
NumCast::zero(),
|
||||
NumCast::zero())
|
||||
Quat::new(Number::zero(),
|
||||
Number::zero(),
|
||||
Number::zero(),
|
||||
Number::zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
36
src/vec.rs
36
src/vec.rs
|
@ -136,14 +136,14 @@ pub impl<T:Copy> Vec2<T>: ToPtr<T> {
|
|||
pub impl<T:Copy Number> Vec2<T>: NumericVector<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec2<T> {
|
||||
Vec2::new(NumCast::one(),
|
||||
NumCast::one())
|
||||
Vec2::new(Number::one(),
|
||||
Number::one())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Vec2<T> {
|
||||
Vec2::new(NumCast::zero(),
|
||||
NumCast::zero())
|
||||
Vec2::new(Number::zero(),
|
||||
Number::zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -298,16 +298,16 @@ pub impl<T:Copy> Vec3<T>: ToPtr<T> {
|
|||
pub impl<T:Copy Number> Vec3<T>: NumericVector<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec3<T> {
|
||||
Vec3::new(NumCast::one(),
|
||||
NumCast::one(),
|
||||
NumCast::one())
|
||||
Vec3::new(Number::one(),
|
||||
Number::one(),
|
||||
Number::one())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Vec3<T> {
|
||||
Vec3::new(NumCast::zero(),
|
||||
NumCast::zero(),
|
||||
NumCast::zero())
|
||||
Vec3::new(Number::zero(),
|
||||
Number::zero(),
|
||||
Number::zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -478,18 +478,18 @@ pub impl<T:Copy> Vec4<T>: ToPtr<T> {
|
|||
pub impl<T:Copy Number> Vec4<T>: NumericVector<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec4<T> {
|
||||
Vec4::new(NumCast::one(),
|
||||
NumCast::one(),
|
||||
NumCast::one(),
|
||||
NumCast::one())
|
||||
Vec4::new(Number::one(),
|
||||
Number::one(),
|
||||
Number::one(),
|
||||
Number::one())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Vec4<T> {
|
||||
Vec4::new(NumCast::zero(),
|
||||
NumCast::zero(),
|
||||
NumCast::zero(),
|
||||
NumCast::zero())
|
||||
Vec4::new(Number::zero(),
|
||||
Number::zero(),
|
||||
Number::zero(),
|
||||
Number::zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
Loading…
Reference in a new issue