From 16d78f46808fae7638c61043d6f9e1cd9918f04d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Fri, 26 Jul 2019 15:38:21 +0100 Subject: [PATCH] UnitComplex: make use of UnitCircle where available --- src/geometry/unit_complex_construction.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index 32bb1252..da9a68cf 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen}; use num::One; use num_complex::Complex; -use rand::distributions::{Distribution, Standard, uniform::SampleUniform}; +use rand::distributions::{Distribution, Standard}; use rand::Rng; use alga::general::RealField; @@ -275,8 +275,21 @@ impl One for UnitComplex { } } +#[cfg(feature = "std")] impl Distribution> for Standard -where N: SampleUniform +where rand_distr::UnitCircle: Distribution<[N; 2]> +{ + /// Generate a uniformly distributed random `UnitComplex`. + #[inline] + fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex { + let x = rand_distr::UnitCircle.sample(rng); + UnitComplex::new_unchecked(Complex::new(x[0], x[1])) + } +} + +#[cfg(not(feature = "std"))] +impl Distribution> for Standard +where N: rand::distributions::uniform::SampleUniform { /// Generate a uniformly distributed random `UnitComplex`. #[inline]