From 57d8c4809b4990736923829334807df3c4c8a5db Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sat, 8 Sep 2012 01:18:18 +1000 Subject: [PATCH] OCD - move dot product methods --- src/vec.rs | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index 6980a7f..1eb5ecb 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -24,12 +24,12 @@ trait Vector { pure fn add_v(&&other: self) -> self; pure fn sub_v(&&other: self) -> self; + pure fn dot(&&other: self) -> T; + pure fn exact_eq(&&other:self) -> bool; pure fn fuzzy_eq(&&other:self) -> bool; pure fn eq(&&other:self) -> bool; - pure fn dot(&&other: self) -> T; - pure fn magnitude2() -> T; pure fn magnitude() -> T; pure fn normalize() -> self; @@ -157,6 +157,12 @@ impl vec2: Vector { self[1] - other[1]) } + #[inline(always)] + pure fn dot(&&other: vec2) -> float { + self[0] * other[0] + + self[1] * other[1] + } + #[inline(always)] pure fn exact_eq(&&other:vec2) -> bool { self[0] == other[0] && @@ -174,12 +180,6 @@ impl vec2: Vector { self.fuzzy_eq(other) } - #[inline(always)] - pure fn dot(&&other: vec2) -> float { - self[0] * other[0] + - self[1] * other[1] - } - #[inline(always)] pure fn magnitude2() -> float { self[0] * self[0] + @@ -310,6 +310,13 @@ impl vec3: Vector { self[2] - other[2]) } + #[inline(always)] + pure fn dot(&&other: vec3) -> float { + self[0] * other[0] + + self[1] * other[1] + + self[2] * other[2] + } + #[inline(always)] pure fn exact_eq(&&other:vec3) -> bool { self[0] == other[0] && @@ -329,13 +336,6 @@ impl vec3: Vector { self.fuzzy_eq(other) } - #[inline(always)] - pure fn dot(&&other: vec3) -> float { - self[0] * other[0] + - self[1] * other[1] + - self[2] * other[2] - } - #[inline(always)] pure fn magnitude2() -> float { self[0] * self[0] + @@ -467,6 +467,14 @@ impl vec4: Vector { self[3] - other[3]) } + #[inline(always)] + pure fn dot(&&other:vec4) -> float { + self[0] * other[0] + + self[1] * other[1] + + self[2] * other[2] + + self[3] * other[3] + } + #[inline(always)] pure fn exact_eq(&&other:vec4) -> bool { self[0] == other[0] && @@ -488,14 +496,6 @@ impl vec4: Vector { self.fuzzy_eq(other) } - #[inline(always)] - pure fn dot(&&other:vec4) -> float { - self[0] * other[0] + - self[1] * other[1] + - self[2] * other[2] + - self[3] * other[3] - } - #[inline(always)] pure fn magnitude2() -> float { self[0] * self[0] +