Bumped rand and fixed compiler issues

This commit is contained in:
Victor Koenders 2018-06-08 13:39:02 +02:00
parent 1c5fb672a4
commit cdb0e8c8a1
6 changed files with 45 additions and 25 deletions

View file

@ -24,7 +24,7 @@ swizzle = []
approx = "0.2"
mint = { version = "0.5", optional = true }
num-traits = "0.2"
rand = "0.4"
rand = "0.5"
serde = { version = "1.0", features = ["serde_derive"], optional = true }
simd = { version = "0.2", optional = true }

View file

@ -20,8 +20,9 @@ use std::f64;
use std::iter;
use std::ops::*;
use rand::{Rand, Rng};
use rand::distributions::range::SampleRange;
use rand::Rng;
use rand::distributions::{Distribution, Standard};
use rand::distributions::uniform::SampleUniform;
use num_traits::{cast, Bounded};
use structure::*;
@ -207,10 +208,12 @@ macro_rules! impl_angle {
S::ulps_eq(&self.0, &other.0, epsilon, max_ulps)
}
}
impl<S: BaseFloat + SampleRange> Rand for $Angle<S> {
impl<S> Distribution<$Angle<S>> for Standard
where Standard: Distribution<S>,
S: BaseFloat + SampleUniform {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> $Angle<S> {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $Angle<S> {
$Angle(rng.gen_range(cast(-$hi).unwrap(), cast($hi).unwrap()))
}
}

View file

@ -13,7 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rand::{Rand, Rng};
use rand::distributions::{Distribution, Standard};
use rand::Rng;
use num_traits::cast;
use structure::*;
@ -185,9 +186,10 @@ impl<A: Angle> approx::UlpsEq for Euler<A> {
}
}
impl<A: Angle + Rand> Rand for Euler<A> {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Euler<A> {
impl<A> Distribution<Euler<A>> for Standard
where Standard: Distribution<A>,
A: Angle {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Euler<A> {
Euler {
x: rng.gen(),
y: rng.gen(),

View file

@ -13,7 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rand::{Rand, Rng};
use rand::distributions::{Standard, Distribution};
use rand::Rng;
use num_traits::{cast, NumCast};
use std::fmt;
use std::iter;
@ -1529,19 +1530,24 @@ impl<S: fmt::Debug> fmt::Debug for Matrix4<S> {
}
}
impl<S: BaseFloat + Rand> Rand for Matrix2<S> {
impl<S> Distribution<Matrix2<S>> for Standard
where
Standard: Distribution<Vector2<S>>,
S: BaseFloat {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Matrix2<S> {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Matrix2<S> {
Matrix2 {
x: rng.gen(),
y: rng.gen(),
x: self.sample(rng),
y: self.sample(rng),
}
}
}
impl<S: BaseFloat + Rand> Rand for Matrix3<S> {
impl<S> Distribution<Matrix3<S>> for Standard
where Standard: Distribution<Vector3<S>>,
S: BaseFloat {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Matrix3<S> {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Matrix3<S> {
Matrix3 {
x: rng.gen(),
y: rng.gen(),
@ -1550,9 +1556,11 @@ impl<S: BaseFloat + Rand> Rand for Matrix3<S> {
}
}
impl<S: BaseFloat + Rand> Rand for Matrix4<S> {
impl<S> Distribution<Matrix4<S>> for Standard
where Standard: Distribution<Vector4<S>>,
S: BaseFloat {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Matrix4<S> {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Matrix4<S> {
Matrix4 {
x: rng.gen(),
y: rng.gen(),

View file

@ -17,7 +17,8 @@ use std::iter;
use std::mem;
use std::ops::*;
use rand::{Rand, Rng};
use rand::distributions::{Distribution, Standard};
use rand::Rng;
use num_traits::{cast, NumCast};
use structure::*;
@ -864,9 +865,12 @@ index_operators!(S, [S], RangeTo<usize>);
index_operators!(S, [S], RangeFrom<usize>);
index_operators!(S, [S], RangeFull);
impl<S: BaseFloat + Rand> Rand for Quaternion<S> {
impl<S> Distribution<Quaternion<S>> for Standard
where Standard: Distribution<S>,
Standard: Distribution<Vector3<S>>,
S: BaseFloat {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Quaternion<S> {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Quaternion<S> {
Quaternion::from_sv(rng.gen(), rng.gen())
}
}

View file

@ -13,7 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rand::{Rand, Rng};
use rand::distributions::{Distribution, Standard};
use rand::Rng;
use num_traits::{Bounded, NumCast};
use std::fmt;
use std::iter;
@ -244,9 +245,11 @@ macro_rules! impl_vector {
}
}
impl<S: BaseFloat + Rand> Rand for $VectorN<S> {
impl<S> Distribution<$VectorN<S>> for Standard
where Standard: Distribution<S>,
S: BaseFloat {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> $VectorN<S> {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $VectorN<S> {
$VectorN { $($field: rng.gen()),+ }
}
}