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:
Coordinateis the index type for this space. Cells in the space are uniquely identified by coordinates.CoordinateDeltarepresents adjacency relations between cells. In general, a collapse rule supplies a list of coordinate deltas to get neighbor cell coordinates.
Required Associated Constants§
Sourceconst DIRECTIONS: &'static [Self::Direction]
const DIRECTIONS: &'static [Self::Direction]
All possible values of Space::Direction.
Required Associated Types§
Sourcetype Coordinate: Default + Copy + Hash + Ord + Index<Self::Axis, Output = u32>
type Coordinate: Default + Copy + Hash + Ord + Index<Self::Axis, Output = u32>
Coordinates for cells in the space
Sourcetype Direction: Copy + Debug + Eq + Neg<Output = Self::Direction> + 'static
type Direction: Copy + Debug + Eq + Neg<Output = Self::Direction> + 'static
Spatial relationship between cells for accessing neighbors
Sourcetype RotationAxis: Copy + Debug + Eq + 'static
type RotationAxis: Copy + Debug + Eq + 'static
Axes of rotation.
Required Methods§
Sourcefn new(
dimensions: Self::Coordinate,
init_fn: impl FnMut(Self::Coordinate) -> T,
) -> Self
fn new( dimensions: Self::Coordinate, init_fn: impl FnMut(Self::Coordinate) -> T, ) -> Self
The grid will occupy (0,0,0)..dimensions.
Sourcefn dimensions(&self) -> Self::Coordinate
fn dimensions(&self) -> Self::Coordinate
The dimensions passed to Space::new during construction.
Sourcefn map(
coordinate: Self::Coordinate,
map_fn: impl Fn(Self::Axis, u32) -> u32,
) -> Self::Coordinate
fn map( coordinate: Self::Coordinate, map_fn: impl Fn(Self::Axis, u32) -> u32, ) -> Self::Coordinate
Apply map_fn to each component of coordinate.
Sourcefn perp(
&self,
coordinate: Self::Coordinate,
axis: Self::RotationAxis,
) -> Self::Coordinate
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.
Sourcefn add_sub(
&self,
start: Self::Coordinate,
add: Self::Coordinate,
sub: Self::Coordinate,
) -> Option<Self::Coordinate>
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.
Sourcefn visit_coordinates(
dimensions: Self::Coordinate,
visitor: impl FnMut(Self::Coordinate),
)
fn visit_coordinates( dimensions: Self::Coordinate, visitor: impl FnMut(Self::Coordinate), )
Get every valid coordinate in the space.
Sourcefn neighbor(
&self,
coord: Self::Coordinate,
direction: Self::Direction,
) -> Option<Self::Coordinate>
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.