diff --git a/src/point.rs b/src/point.rs index c659293..1533321 100644 --- a/src/point.rs +++ b/src/point.rs @@ -17,7 +17,7 @@ //! disinguishes them from vectors, which have a length and direction, but do //! not have a fixed position. -use num_traits::NumCast; +use num_traits::{NumCast, Bounded}; use std::fmt; use std::mem; use std::ops::*; @@ -195,6 +195,18 @@ macro_rules! impl_point { } } + impl Bounded for $PointN { + #[inline] + fn min_value() -> $PointN { + $PointN { $($field: S::min_value()),+ } + } + + #[inline] + fn max_value() -> $PointN { + $PointN { $($field: S::max_value()),+ } + } + } + impl_operator!( Add<$VectorN > for $PointN { fn add(lhs, rhs) -> $PointN { $PointN::new($(lhs.$field + rhs.$field),+) } }); diff --git a/src/vector.rs b/src/vector.rs index f52232a..70dd081 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -14,7 +14,7 @@ // limitations under the License. use rand::{Rand, Rng}; -use num_traits::NumCast; +use num_traits::{NumCast, Bounded}; use std::fmt; use std::iter; use std::mem; @@ -223,6 +223,18 @@ macro_rules! impl_vector { } } + impl Bounded for $VectorN { + #[inline] + fn min_value() -> $VectorN { + $VectorN { $($field: S::min_value()),+ } + } + + #[inline] + fn max_value() -> $VectorN { + $VectorN { $($field: S::max_value()),+ } + } + } + impl_operator!( Add<$VectorN > for $VectorN { fn add(lhs, rhs) -> $VectorN { $VectorN::new($(lhs.$field + rhs.$field),+) } });