forked from M-Labs/nalgebra
Add Rand implementation for everything.
This commit is contained in:
parent
53131731b3
commit
bc93c44206
@ -1,4 +1,5 @@
|
||||
use core::num::{One, Zero}; // , Trigonometric};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::workarounds::rlmul::{RMul, LMul};
|
||||
use traits::workarounds::trigonometric::Trigonometric;
|
||||
@ -56,6 +57,20 @@ pub fn Rotmat3<T: Copy + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Rand + Trigonometric + Neg<T>> Rand for Rotmat<Mat2<T>>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Rotmat<Mat2<T>>
|
||||
{ Rotmat2(rng.gen()) }
|
||||
}
|
||||
|
||||
impl<T:Copy + Rand + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
|
||||
Mul<T, T>>
|
||||
Rand for Rotmat<Mat3<T>>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Rotmat<Mat3<T>>
|
||||
{ Rotmat3(&rng.gen(), rng.gen()) }
|
||||
}
|
||||
|
||||
impl<M: Dim> Dim for Rotmat<M>
|
||||
{
|
||||
fn dim() -> uint
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{One, Zero};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
@ -91,6 +92,12 @@ impl<T, M:FuzzyEq<T>, V:FuzzyEq<T>> FuzzyEq<T> for Transform<M, V>
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Rand + Copy, V: Rand + Copy> Rand for Transform<M, V>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Transform<M, V>
|
||||
{ Transform(&rng.gen(), &rng.gen()) }
|
||||
}
|
||||
|
||||
impl<M:ToStr, V:ToStr> ToStr for Transform<M, V>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{One, Zero};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
@ -93,6 +94,12 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat1<T>
|
||||
{ self.m11.fuzzy_eq_eps(&other.m11, epsilon) }
|
||||
}
|
||||
|
||||
impl<T:Rand + Copy> Rand for Mat1<T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Mat1<T>
|
||||
{ Mat1(rng.gen()) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Mat1<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{Zero, Algebraic};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dot::Dot;
|
||||
use traits::dim::Dim;
|
||||
@ -67,6 +68,12 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec1<T>
|
||||
{ self.x.fuzzy_eq_eps(&other.x, epsilon) }
|
||||
}
|
||||
|
||||
impl<T:Rand + Copy> Rand for Vec1<T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Vec1<T>
|
||||
{ Vec1(rng.gen()) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Vec1<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{One, Zero};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
@ -144,6 +145,12 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat2<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Rand + Copy> Rand for Mat2<T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Mat2<T>
|
||||
{ Mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Mat2<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{Zero, Algebraic};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dot::Dot;
|
||||
use traits::dim::Dim;
|
||||
@ -81,6 +82,12 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec2<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Rand + Copy> Rand for Vec2<T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Vec2<T>
|
||||
{ Vec2(rng.gen(), rng.gen()) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Vec2<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{One, Zero};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
@ -195,6 +196,16 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat3<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Rand + Copy> Rand for Mat3<T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Mat3<T>
|
||||
{
|
||||
Mat3(rng.gen(), rng.gen(), rng.gen(),
|
||||
rng.gen(), rng.gen(), rng.gen(),
|
||||
rng.gen(), rng.gen(), rng.gen())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Mat3<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
@ -1,4 +1,5 @@
|
||||
use core::num::{Zero, Algebraic};
|
||||
use core::rand::{Rand, Rng, RngUtil};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::dot::Dot;
|
||||
@ -92,6 +93,12 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec3<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Rand> Rand for Vec3<T>
|
||||
{
|
||||
fn rand<R: Rng>(rng: &R) -> Vec3<T>
|
||||
{ Vec3(rng.gen(), rng.gen(), rng.gen()) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Vec3<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
Loading…
Reference in New Issue
Block a user