Space

Trait Space 

Source
pub trait Space<T>: IndexMut<Self::Coordinate, Output = T> + 'static {
    type Coordinate: Default + Copy + Hash + Ord + Index<Self::Axis, Output = u32>;
    type Direction: Copy + Debug + Eq + Neg<Output = Self::Direction> + 'static;
    type Axis: Copy + Debug + Eq + 'static;
    type RotationAxis: Copy + Debug + Eq + 'static;

    const DIRECTIONS: &'static [Self::Direction];

    // Required methods
    fn new(
        dimensions: Self::Coordinate,
        init_fn: impl FnMut(Self::Coordinate) -> T,
    ) -> Self;
    fn dimensions(&self) -> Self::Coordinate;
    fn map(
        coordinate: Self::Coordinate,
        map_fn: impl Fn(Self::Axis, u32) -> u32,
    ) -> Self::Coordinate;
    fn perp(
        &self,
        coordinate: Self::Coordinate,
        axis: Self::RotationAxis,
    ) -> Self::Coordinate;
    fn add_sub(
        &self,
        start: Self::Coordinate,
        add: Self::Coordinate,
        sub: Self::Coordinate,
    ) -> Option<Self::Coordinate>;
    fn visit_coordinates(
        dimensions: Self::Coordinate,
        visitor: impl FnMut(Self::Coordinate),
    );
    fn neighbor(
        &self,
        coord: Self::Coordinate,
        direction: Self::Direction,
    ) -> Option<Self::Coordinate>;
}
Expand description

Defines the space or “world” to run WFC on.

This is the primary data structure behind WFC, and is modified in-place by the algorithm. The only expectation placed on Space is that it’s size and shape do not change during calls to crate::collapse.

In order to support arbitrary dimension and shape, two associated types are defined:

  • Coordinate is the index type for this space. Cells in the space are uniquely identified by coordinates.
  • CoordinateDelta represents adjacency relations between cells. In general, a collapse rule supplies a list of coordinate deltas to get neighbor cell coordinates.

Required Associated Constants§

Source

const DIRECTIONS: &'static [Self::Direction]

All possible values of Space::Direction.

Required Associated Types§

Source

type Coordinate: Default + Copy + Hash + Ord + Index<Self::Axis, Output = u32>

Coordinates for cells in the space

Source

type Direction: Copy + Debug + Eq + Neg<Output = Self::Direction> + 'static

Spatial relationship between cells for accessing neighbors

Source

type Axis: Copy + Debug + Eq + 'static

Axes of translation/flipping.

Source

type RotationAxis: Copy + Debug + Eq + 'static

Axes of rotation.

Required Methods§

Source

fn new( dimensions: Self::Coordinate, init_fn: impl FnMut(Self::Coordinate) -> T, ) -> Self

The grid will occupy (0,0,0)..dimensions.

Source

fn dimensions(&self) -> Self::Coordinate

The dimensions passed to Space::new during construction.

Source

fn map( coordinate: Self::Coordinate, map_fn: impl Fn(Self::Axis, u32) -> u32, ) -> Self::Coordinate

Apply map_fn to each component of coordinate.

Source

fn perp( &self, coordinate: Self::Coordinate, axis: Self::RotationAxis, ) -> Self::Coordinate

90 degree rotation of coordinate around axis as if by looking down that axis in a left-handed coordinate system and rotating counter-clockwise.

Source

fn add_sub( &self, start: Self::Coordinate, add: Self::Coordinate, sub: Self::Coordinate, ) -> Option<Self::Coordinate>

Computes start + add - sub, returning Some if the result is in the space.

Source

fn visit_coordinates( dimensions: Self::Coordinate, visitor: impl FnMut(Self::Coordinate), )

Get every valid coordinate in the space.

Source

fn neighbor( &self, coord: Self::Coordinate, direction: Self::Direction, ) -> Option<Self::Coordinate>

Get the neighbor coordinates of a given cell based on a direction.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§