From 3449fe8a738750f035ad9057e7eaf947ac296d3d Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 17 Sep 2013 16:40:29 +1000 Subject: [PATCH] Add bisection method for angles --- src/cgmath/angle.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cgmath/angle.rs b/src/cgmath/angle.rs index 83a479d..c7a64d2 100644 --- a/src/cgmath/angle.rs +++ b/src/cgmath/angle.rs @@ -110,6 +110,12 @@ pub trait Angle self.add_a(Angle::turn_div_2()).normalize() } + /// Returns the interior bisector of the two angles + #[inline] + fn bisect(&self, other: Self) -> Self { + self.add_a(self.sub_a(other).mul_s(cast(0.5))).normalize() + } + fn full_turn() -> Self; #[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2)) } @@ -118,6 +124,8 @@ pub trait Angle #[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6)) } } +#[inline] pub fn bisect>(a: A, b: A) -> A { a.bisect(b) } + impl Rad { #[inline] pub fn zero() -> Rad { zero() } #[inline] pub fn full_turn() -> Rad { Angle::full_turn() }