/** * Vector Relational Functions */ use cmp::{Eq, Ord}; use vector::{Vec2, Vec3, Vec4}; pub trait RelVector { pure fn less_than(y: &self) -> BVec; pure fn less_than_equal(y: &self) -> BVec; pure fn greater_than(y: &self) -> BVec; pure fn greater_than_equal(y: &self) -> BVec; pure fn equal(y: &self) -> BVec; pure fn not_equal(y: &self) -> BVec; } #[inline(always)] pub pure fn less_than , BV>(x: &T, y: &T) -> BV { x.less_than(y) } #[inline(always)] pub pure fn less_than_equal , BV>(x: &T, y: &T) -> BV { x.less_than_equal(y) } #[inline(always)] pub pure fn greater_than , BV>(x: &T, y: &T) -> BV { x.greater_than(y) } #[inline(always)] pub pure fn greater_than_equal, BV>(x: &T, y: &T) -> BV { x.greater_than_equal(y) } #[inline(always)] pub pure fn equal , BV>(x: &T, y: &T) -> BV { x.equal(y) } #[inline(always)] pub pure fn not_equal , BV>(x: &T, y: &T) -> BV { x.not_equal(y) } pub impl Vec2: RelVector> { #[inline(always)] pure fn less_than(y: &Vec2) -> Vec2 { Vec2::new(self[0] < y[0], self[1] < y[1]) } #[inline(always)] pure fn less_than_equal(y: &Vec2) -> Vec2 { Vec2::new(self[0] <= y[0], self[1] <= y[1]) } #[inline(always)] pure fn greater_than(y: &Vec2) -> Vec2 { Vec2::new(self[0] > y[0], self[1] > y[1]) } #[inline(always)] pure fn greater_than_equal(y: &Vec2) -> Vec2 { Vec2::new(self[0] >= y[0], self[1] >= y[1]) } #[inline(always)] pure fn equal(y: &Vec2) -> Vec2 { Vec2::new(self[0] == y[0], self[1] == y[1]) } #[inline(always)] pure fn not_equal(y: &Vec2) -> Vec2 { Vec2::new(self[0] != y[0], self[1] != y[1]) } } pub impl Vec3: RelVector> { #[inline(always)] pure fn less_than(y: &Vec3) -> Vec3 { Vec3::new(self[0] < y[0], self[1] < y[1], self[2] < y[2]) } #[inline(always)] pure fn less_than_equal(y: &Vec3) -> Vec3 { Vec3::new(self[0] <= y[0], self[1] <= y[1], self[2] <= y[2]) } #[inline(always)] pure fn greater_than(y: &Vec3) -> Vec3 { Vec3::new(self[0] > y[0], self[1] > y[1], self[2] > y[2]) } #[inline(always)] pure fn greater_than_equal(y: &Vec3) -> Vec3 { Vec3::new(self[0] >= y[0], self[1] >= y[1], self[2] >= y[2]) } #[inline(always)] pure fn equal(y: &Vec3) -> Vec3 { Vec3::new(self[0] == y[0], self[1] == y[1], self[2] == y[2]) } #[inline(always)] pure fn not_equal(y: &Vec3) -> Vec3 { Vec3::new(self[0] != y[0], self[1] != y[1], self[2] != y[2]) } } pub impl Vec4: RelVector> { #[inline(always)] pure fn less_than(y: &Vec4) -> Vec4 { Vec4::new(self[0] < y[0], self[1] < y[1], self[2] < y[2], self[3] < y[3]) } #[inline(always)] pure fn less_than_equal(y: &Vec4) -> Vec4 { Vec4::new(self[0] <= y[0], self[1] <= y[1], self[2] <= y[2], self[3] <= y[3]) } #[inline(always)] pure fn greater_than(y: &Vec4) -> Vec4 { Vec4::new(self[0] > y[0], self[1] > y[1], self[2] > y[2], self[3] > y[3]) } #[inline(always)] pure fn greater_than_equal(y: &Vec4) -> Vec4 { Vec4::new(self[0] >= y[0], self[1] >= y[1], self[2] >= y[2], self[3] >= y[3]) } #[inline(always)] pure fn equal(y: &Vec4) -> Vec4 { Vec4::new(self[0] == y[0], self[1] == y[1], self[2] == y[2], self[3] == y[3]) } #[inline(always)] pure fn not_equal(y: &Vec4) -> Vec4 { Vec4::new(self[0] != y[0], self[1] != y[1], self[2] != y[2], self[3] != y[3]) } }