Add Bounded impl for Vectors and Points
This commit is contained in:
parent
b270f9fb52
commit
1e98ef4dd4
2 changed files with 26 additions and 2 deletions
14
src/point.rs
14
src/point.rs
|
@ -17,7 +17,7 @@
|
||||||
//! disinguishes them from vectors, which have a length and direction, but do
|
//! disinguishes them from vectors, which have a length and direction, but do
|
||||||
//! not have a fixed position.
|
//! not have a fixed position.
|
||||||
|
|
||||||
use num_traits::NumCast;
|
use num_traits::{NumCast, Bounded};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::*;
|
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> {
|
impl_operator!(<S: BaseNum> Add<$VectorN<S> > for $PointN<S> {
|
||||||
fn add(lhs, rhs) -> $PointN<S> { $PointN::new($(lhs.$field + rhs.$field),+) }
|
fn add(lhs, rhs) -> $PointN<S> { $PointN::new($(lhs.$field + rhs.$field),+) }
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use rand::{Rand, Rng};
|
use rand::{Rand, Rng};
|
||||||
use num_traits::NumCast;
|
use num_traits::{NumCast, Bounded};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::mem;
|
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> {
|
impl_operator!(<S: BaseNum> Add<$VectorN<S> > for $VectorN<S> {
|
||||||
fn add(lhs, rhs) -> $VectorN<S> { $VectorN::new($(lhs.$field + rhs.$field),+) }
|
fn add(lhs, rhs) -> $VectorN<S> { $VectorN::new($(lhs.$field + rhs.$field),+) }
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue