Move abs method to Abs trait implementations
This commit is contained in:
parent
11c7ee06fa
commit
28a9a8250a
1 changed files with 28 additions and 29 deletions
57
src/vec.rs
57
src/vec.rs
|
@ -1,7 +1,7 @@
|
|||
use std::cmp::FuzzyEq;
|
||||
use cmp::Eq;
|
||||
use ops::{Neg, Index};
|
||||
use math::{Abs, min, max, Sqrt};
|
||||
use math::{Abs, abs, min, max, Sqrt};
|
||||
use to_str::ToStr;
|
||||
|
||||
//
|
||||
|
@ -27,7 +27,6 @@ pub trait Vector<T> {
|
|||
pure fn normalize() -> self;
|
||||
|
||||
pure fn lerp(other: &self, value: T) -> self;
|
||||
pure fn abs() -> self;
|
||||
pure fn min(other: &self) -> self;
|
||||
pure fn max(other: &self) -> self;
|
||||
|
||||
|
@ -35,12 +34,6 @@ pub trait Vector<T> {
|
|||
static pure fn identity() -> self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pub trait Vector3<T> {
|
||||
fn cross(other: &self) -> self;
|
||||
}
|
||||
|
@ -142,12 +135,6 @@ pub impl Vec2: Vector<float> {
|
|||
self.add_v(&other.sub_v(&self).mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn abs() -> Vec2 {
|
||||
Vec2(self[0].abs(),
|
||||
self[1].abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn min(other: &Vec2) -> Vec2 {
|
||||
Vec2(min(&self[0], &other[0]),
|
||||
|
@ -175,6 +162,14 @@ pub impl Vec2: Index<uint, float> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl Vec2: Abs {
|
||||
#[inline]
|
||||
pure fn abs() -> Vec2 {
|
||||
Vec2(abs(self[0]),
|
||||
abs(self[1]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec2: Neg<Vec2> {
|
||||
#[inline]
|
||||
pure fn neg() -> Vec2 {
|
||||
|
@ -328,13 +323,6 @@ pub impl Vec3: Vector<float> {
|
|||
self.add_v(&other.sub_v(&self).mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn abs() -> Vec3 {
|
||||
Vec3(self[0].abs(),
|
||||
self[1].abs(),
|
||||
self[2].abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn min(other: &Vec3) -> Vec3 {
|
||||
Vec3(min(&self[0], &other[0]),
|
||||
|
@ -365,6 +353,15 @@ pub impl Vec3: Index<uint, float> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl Vec3: Abs {
|
||||
#[inline]
|
||||
pure fn abs() -> Vec3 {
|
||||
Vec3(abs(self[0]),
|
||||
abs(self[1]),
|
||||
abs(self[2]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec3: Neg<Vec3> {
|
||||
#[inline]
|
||||
pure fn neg() -> Vec3 {
|
||||
|
@ -516,14 +513,6 @@ pub impl Vec4: Vector<float> {
|
|||
self.add_v(&other.sub_v(&self).mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn abs() -> Vec4 {
|
||||
Vec4(self[0].abs(),
|
||||
self[1].abs(),
|
||||
self[2].abs(),
|
||||
self[3].abs())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn min(other: &Vec4) -> Vec4 {
|
||||
Vec4(min(&self[0], &other[0]),
|
||||
|
@ -557,6 +546,16 @@ pub impl Vec4: Index<uint, float> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl Vec4: Abs {
|
||||
#[inline]
|
||||
pure fn abs() -> Vec4 {
|
||||
Vec4(abs(self[0]),
|
||||
abs(self[1]),
|
||||
abs(self[2]),
|
||||
abs(self[3]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec4: Neg<Vec4> {
|
||||
#[inline]
|
||||
pure fn neg() -> Vec4 {
|
||||
|
|
Loading…
Reference in a new issue