hcomplex/transform/moebius/
random.rs1use num_traits::{Float};
2use rand::Rng;
3use rand_distr::Distribution;
4use crate::*;
5use super::*;
6
7
8pub use rand_distr::StandardNormal;
9
10pub struct Normalized;
12
13
14impl<U> Distribution<Moebius<U>> for StandardNormal where StandardNormal: Distribution<U> {
15 fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Moebius<U> {
16 Moebius::new(
17 rng.sample(Self), rng.sample(Self),
18 rng.sample(Self), rng.sample(Self),
19 )
20 }
21}
22
23impl<T: Float + Algebra, U: NormSqr<Output=T> + Clone> Distribution<Moebius<Construct<T, U>>> for Normalized where
24 StandardNormal: Distribution<Moebius<Construct<T, U>>>,
25 Construct<T, U>: Algebra<T>
26{
27 fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Moebius<Construct<T, U>> {
28 loop {
29 let m = rng.sample(&StandardNormal);
30 if m.det().norm() > T::epsilon() {
31 break m.normalize();
32 }
33 }
34 }
35}