From 854dda73bfee8a2917110db9f1deed833145e7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 15 Jun 2013 22:11:33 +0000 Subject: [PATCH] Add implementation of Bounded. --- src/dim1/vec1.rs | 14 ++++++++++++-- src/dim2/vec2.rs | 13 ++++++++++++- src/dim3/vec3.rs | 13 ++++++++++++- src/ndim/nvec.rs | 13 ++++++++++++- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index e4f8d627..1e451586 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -1,4 +1,4 @@ -use std::num::{Zero, One, Algebraic}; +use std::num::{Zero, One, Algebraic, Bounded}; use std::rand::{Rand, Rng, RngUtil}; use std::cmp::ApproxEq; use traits::basis::Basis; @@ -14,7 +14,6 @@ use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; pub struct Vec1 { x : N } - impl Vec1 { #[inline(always)] @@ -219,3 +218,14 @@ impl Flatten for Vec1 fn flatten_to(&self, l: &mut [N], off: uint) { l[off] = self.x } } + +impl Bounded for Vec1 +{ + #[inline(always)] + fn max_value() -> Vec1 + { Vec1::new(Bounded::max_value()) } + + #[inline(always)] + fn min_value() -> Vec1 + { Vec1::new(Bounded::min_value()) } +} diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index 9265201d..ff230448 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -1,4 +1,4 @@ -use std::num::{Zero, One, Algebraic}; +use std::num::{Zero, One, Algebraic, Bounded}; use std::rand::{Rand, Rng, RngUtil}; use dim1::vec1::Vec1; use std::cmp::ApproxEq; @@ -257,3 +257,14 @@ impl Flatten for Vec2 l[off + 1] = self.y; } } + +impl Bounded for Vec2 +{ + #[inline(always)] + fn max_value() -> Vec2 + { Vec2::new(Bounded::max_value(), Bounded::max_value()) } + + #[inline(always)] + fn min_value() -> Vec2 + { Vec2::new(Bounded::min_value(), Bounded::min_value()) } +} diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index 6ded2d09..235d9420 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -1,4 +1,4 @@ -use std::num::{Zero, One, Algebraic, abs}; +use std::num::{Zero, One, Algebraic, abs, Bounded}; use std::rand::{Rand, Rng, RngUtil}; use std::cmp::ApproxEq; use traits::basis::Basis; @@ -287,3 +287,14 @@ impl Flatten for Vec3 l[off + 2] = self.z; } } + +impl Bounded for Vec3 +{ + #[inline(always)] + fn max_value() -> Vec3 + { Vec3::new(Bounded::max_value(), Bounded::max_value(), Bounded::max_value()) } + + #[inline(always)] + fn min_value() -> Vec3 + { Vec3::new(Bounded::min_value(), Bounded::min_value(), Bounded::min_value()) } +} diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index 6263151d..c8cd5497 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -1,5 +1,5 @@ use std::uint::iterate; -use std::num::{Zero, Algebraic}; +use std::num::{Zero, Algebraic, Bounded}; use std::rand::{Rand, Rng, RngUtil}; use std::vec::{map}; use std::cmp::ApproxEq; @@ -265,3 +265,14 @@ impl Flatten for NVec { l[off + i] = self.at.at[i] } } } + +impl + Copy> Bounded for NVec +{ + #[inline(always)] + fn max_value() -> NVec + { Zero::zero::>().scalar_add(&Bounded::max_value()) } + + #[inline(always)] + fn min_value() -> NVec + { Zero::zero::>().scalar_add(&Bounded::min_value()) } +}