Add distance methods
This commit is contained in:
parent
07df95313e
commit
26bab58b0d
1 changed files with 38 additions and 0 deletions
|
@ -48,6 +48,8 @@ pub trait NumericVector<T>: Vector<T>, Neg<self>{
|
|||
pub trait GeometricVector<T>: NumericVector<T> {
|
||||
pure fn length2() -> T;
|
||||
pure fn length() -> T;
|
||||
pure fn distance2(other: &self) -> T;
|
||||
pure fn distance(other: &self) -> T;
|
||||
pure fn normalize() -> self;
|
||||
pure fn lerp(other: &self, amount: T) -> self;
|
||||
}
|
||||
|
@ -179,6 +181,18 @@ pub impl<T:Copy Num NumCast Exp> Vec2<T>: GeometricVector<T> {
|
|||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
// TODO: tests
|
||||
#[inline(always)]
|
||||
pure fn distance2(other: &Vec2<T>) -> T {
|
||||
other.sub_v(&self).length2()
|
||||
}
|
||||
|
||||
// TODO: tests
|
||||
#[inline(always)]
|
||||
pure fn distance(other: &Vec2<T>) -> T {
|
||||
other.distance2(&self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Vec2<T> {
|
||||
let mut n: T = cast(1);
|
||||
|
@ -361,6 +375,18 @@ pub impl<T:Copy Num NumCast Exp> Vec3<T>: GeometricVector<T> {
|
|||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
// TODO: tests
|
||||
#[inline(always)]
|
||||
pure fn distance2(other: &Vec3<T>) -> T {
|
||||
other.sub_v(&self).length2()
|
||||
}
|
||||
|
||||
// TODO: tests
|
||||
#[inline(always)]
|
||||
pure fn distance(other: &Vec3<T>) -> T {
|
||||
other.distance2(&self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Vec3<T> {
|
||||
let mut n: T = cast(1);
|
||||
|
@ -549,6 +575,18 @@ pub impl<T:Copy Num NumCast Exp> Vec4<T>: GeometricVector<T> {
|
|||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
// TODO: tests
|
||||
#[inline(always)]
|
||||
pure fn distance2(other: &Vec4<T>) -> T {
|
||||
other.sub_v(&self).length2()
|
||||
}
|
||||
|
||||
// TODO: tests
|
||||
#[inline(always)]
|
||||
pure fn distance(other: &Vec4<T>) -> T {
|
||||
other.distance2(&self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Vec4<T> {
|
||||
let mut n: T = cast(1);
|
||||
|
|
Loading…
Reference in a new issue