Skip to content

Commit e426b13

Browse files
committed
Add uniform distrib for colors
Should check what's needed for writing one impl for all Affine. Probably AsRef<[T]> or From or similar to get the components.
1 parent 7ad2090 commit e426b13

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

core/src/math/rand.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use core::{array, fmt::Debug, ops::Range};
44

5-
use super::{Point, Point2, Point3, Vec2, Vec3, Vector};
5+
use super::{Color, Point, Point2, Point3, Vec2, Vec3, Vector};
66

77
//
88
// Traits and types
@@ -381,6 +381,22 @@ where
381381
.into()
382382
}
383383
}
384+
impl<Sc, Sp, const DIM: usize> Distrib for Uniform<Color<[Sc; DIM], Sp>>
385+
where
386+
Sc: Copy,
387+
Sp: Clone, // TODO Color needs manual Clone etc impls like Vector
388+
Uniform<[Sc; DIM]>: Distrib<Sample = [Sc; DIM]>,
389+
{
390+
type Sample = Point<[Sc; DIM], Sp>;
391+
392+
/// Returns a point uniformly sampled from the rectangular volume
393+
/// bounded by `self.0`.
394+
fn sample(&self, rng: &mut DefaultRng) -> Self::Sample {
395+
Uniform(self.0.start.0..self.0.end.0)
396+
.sample(rng)
397+
.into()
398+
}
399+
}
384400

385401
#[cfg(feature = "fp")]
386402
impl Distrib for UnitCircle {

0 commit comments

Comments
 (0)