diff --git a/src/vector.rs b/src/vector.rs index a644a17..f71cebf 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -48,6 +48,8 @@ pub trait NumericVector: Vector, Neg{ pub trait GeometricVector: NumericVector { 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 Vec2: GeometricVector { self.length2().sqrt() } + // TODO: tests + #[inline(always)] + pure fn distance2(other: &Vec2) -> T { + other.sub_v(&self).length2() + } + + // TODO: tests + #[inline(always)] + pure fn distance(other: &Vec2) -> T { + other.distance2(&self).sqrt() + } + #[inline(always)] pure fn normalize() -> Vec2 { let mut n: T = cast(1); @@ -361,6 +375,18 @@ pub impl Vec3: GeometricVector { self.length2().sqrt() } + // TODO: tests + #[inline(always)] + pure fn distance2(other: &Vec3) -> T { + other.sub_v(&self).length2() + } + + // TODO: tests + #[inline(always)] + pure fn distance(other: &Vec3) -> T { + other.distance2(&self).sqrt() + } + #[inline(always)] pure fn normalize() -> Vec3 { let mut n: T = cast(1); @@ -549,6 +575,18 @@ pub impl Vec4: GeometricVector { self.length2().sqrt() } + // TODO: tests + #[inline(always)] + pure fn distance2(other: &Vec4) -> T { + other.sub_v(&self).length2() + } + + // TODO: tests + #[inline(always)] + pure fn distance(other: &Vec4) -> T { + other.distance2(&self).sqrt() + } + #[inline(always)] pure fn normalize() -> Vec4 { let mut n: T = cast(1);