Add Bounded impl for Vectors and Points

This commit is contained in:
Osspial 2017-08-08 19:11:14 -04:00
parent b270f9fb52
commit 1e98ef4dd4
2 changed files with 26 additions and 2 deletions

View file

@ -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<S: Bounded> Bounded for $PointN<S> {
#[inline]
fn min_value() -> $PointN<S> {
$PointN { $($field: S::min_value()),+ }
}
#[inline]
fn max_value() -> $PointN<S> {
$PointN { $($field: S::max_value()),+ }
}
}
impl_operator!(<S: BaseNum> Add<$VectorN<S> > for $PointN<S> {
fn add(lhs, rhs) -> $PointN<S> { $PointN::new($(lhs.$field + rhs.$field),+) }
});

View file

@ -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<S: Bounded> Bounded for $VectorN<S> {
#[inline]
fn min_value() -> $VectorN<S> {
$VectorN { $($field: S::min_value()),+ }
}
#[inline]
fn max_value() -> $VectorN<S> {
$VectorN { $($field: S::max_value()),+ }
}
}
impl_operator!(<S: BaseNum> Add<$VectorN<S> > for $VectorN<S> {
fn add(lhs, rhs) -> $VectorN<S> { $VectorN::new($(lhs.$field + rhs.$field),+) }
});