Trait bevy::prelude::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;
}
Expand description

Exposes methods to uniformly sample a variety of primitive shapes.

Required Associated Types§

type Output

The type of vector returned by the sample methods, Vec2 for 2D shapes and Vec3 for 3D shapes.

Required Methods§

fn sample_interior<R>(&self, rng: &mut R) -> Self::Output
where R: Rng + ?Sized,

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
where R: Rng + ?Sized,

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.

Implementors§