Merge pull request #425 from Osspial/master
Implement num_traits::Bounded for Points, Vectors, and Angles
This commit is contained in:
commit
7823f46b68
4 changed files with 40 additions and 4 deletions
14
src/angle.rs
14
src/angle.rs
|
@ -22,7 +22,7 @@ use std::ops::*;
|
|||
|
||||
use rand::{Rand, Rng};
|
||||
use rand::distributions::range::SampleRange;
|
||||
use num_traits::cast;
|
||||
use num_traits::{cast, Bounded};
|
||||
|
||||
use structure::*;
|
||||
|
||||
|
@ -117,6 +117,18 @@ macro_rules! impl_angle {
|
|||
fn neg(self) -> $Angle<S> { $Angle(-self.0) }
|
||||
}
|
||||
|
||||
impl<S: Bounded> Bounded for $Angle<S> {
|
||||
#[inline]
|
||||
fn min_value() -> $Angle<S> {
|
||||
$Angle(S::min_value())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn max_value() -> $Angle<S> {
|
||||
$Angle(S::max_value())
|
||||
}
|
||||
}
|
||||
|
||||
impl_operator!(<S: BaseFloat> Add<$Angle<S> > for $Angle<S> {
|
||||
fn add(lhs, rhs) -> $Angle<S> { $Angle(lhs.0 + rhs.0) }
|
||||
});
|
||||
|
|
14
src/point.rs
14
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<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),+) }
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@ use approx::ApproxEq;
|
|||
use angle::Rad;
|
||||
use num::{BaseNum, BaseFloat};
|
||||
|
||||
pub use num_traits::{One, Zero};
|
||||
pub use num_traits::{One, Zero, Bounded};
|
||||
|
||||
/// An array containing elements of type `Element`
|
||||
pub trait Array where
|
||||
|
|
|
@ -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),+) }
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue