Trait bevy::math::sampling::ShapeSample
pub trait ShapeSample {
type Output;
// Required methods
fn sample_interior<R>(&self, rng: &mut R) -> Self::Output
where R: Rng + ?Sized;
fn sample_boundary<R>(&self, rng: &mut R) -> Self::Output
where R: Rng + ?Sized;
}
Available on crate feature
rand
only.Expand description
Exposes methods to uniformly sample a variety of primitive shapes.
Required Associated Types§
Required Methods§
fn sample_interior<R>(&self, rng: &mut R) -> Self::Output
fn sample_interior<R>(&self, rng: &mut R) -> Self::Output
Uniformly sample a point from inside the area/volume of this shape, centered on 0.
Shapes like Cylinder
, Capsule2d
and Capsule3d
are oriented along the y-axis.
§Example
let square = Rectangle::new(2.0, 2.0);
// Returns a Vec2 with both x and y between -1 and 1.
println!("{:?}", square.sample_interior(&mut rand::thread_rng()));
fn sample_boundary<R>(&self, rng: &mut R) -> Self::Output
fn sample_boundary<R>(&self, rng: &mut R) -> Self::Output
Uniformly sample a point from the surface of this shape, centered on 0.
Shapes like Cylinder
, Capsule2d
and Capsule3d
are oriented along the y-axis.
§Example
let square = Rectangle::new(2.0, 2.0);
// Returns a Vec2 where one of the coordinates is at ±1,
// and the other is somewhere between -1 and 1.
println!("{:?}", square.sample_boundary(&mut rand::thread_rng()));
Object Safety§
This trait is not object safe.