pub struct TileSetWfcPropagator { /* private fields */ }Expand description
Wave function collapse propagator for the tiles of a TileSet that uses
the nine-slice values of one of the tile set’s properties as the wave function’s
pattern.
Implementations§
Source§impl TileSetWfcPropagator
impl TileSetWfcPropagator
Sourcepub fn constrain_edges<Con>(
&mut self,
tile_set: &TileSet,
pattern_property: TileSetPropertyNine,
tile_map: &TileMap,
update: &MacroTilesUpdate,
constraint: &Con,
) -> Result<(), WfcFailure>
pub fn constrain_edges<Con>( &mut self, tile_set: &TileSet, pattern_property: TileSetPropertyNine, tile_map: &TileMap, update: &MacroTilesUpdate, constraint: &Con, ) -> Result<(), WfcFailure>
After all the wave cells have been added using WfcPropagator::add_cell,
this method may be used to automatically restrict the edges of the cells by
using the given tile map to find the patterns of surrounding tiles and
calling WfcPropagator::restrict_edge as appropriate.
This forces the wave function collapse to fit smoothly with the existing
tiles of the tile map, though such restrictions may make failure more likely.
WfcFailure is returned if wave function collapse is made impossible by the
restrictions.
Sourcepub fn apply_autotile_to_update<R: Rng + ?Sized>(
&self,
rng: &mut R,
value_map: &TileSetWfcConstraint,
update: &mut MacroTilesUpdate,
)
pub fn apply_autotile_to_update<R: Rng + ?Sized>( &self, rng: &mut R, value_map: &TileSetWfcConstraint, update: &mut MacroTilesUpdate, )
Modify the given tile map update based on the result of the autotiler.
Sourcepub fn apply_autotile_to_data<R: Rng + ?Sized>(
&self,
rng: &mut R,
value_map: &TileSetWfcConstraint,
data: &mut TileMapData,
)
pub fn apply_autotile_to_data<R: Rng + ?Sized>( &self, rng: &mut R, value_map: &TileSetWfcConstraint, data: &mut TileMapData, )
Modify the given tile map data based on the result of the autotiler.
Methods from Deref<Target = WfcPropagator<Vector2<i32>, PatternBits>>§
Sourcepub fn positions(&self) -> impl Iterator<Item = &Pos>
pub fn positions(&self) -> impl Iterator<Item = &Pos>
An iterator over the positions of every cell of the wave.
Sourcepub fn contains_cell(&self, position: &Pos) -> bool
pub fn contains_cell(&self, position: &Pos) -> bool
True if the wave has a cell at the given position.
Sourcepub fn assigned_patterns(&self) -> impl Iterator<Item = (&Pos, &Pat)>
pub fn assigned_patterns(&self) -> impl Iterator<Item = (&Pos, &Pat)>
Iterator over the cells that have been given a pattern by the wave function collapse.
Sourcepub fn fill_from<Con>(&mut self, constraint: &Con)
pub fn fill_from<Con>(&mut self, constraint: &Con)
Use the data in a WfcConstrain object to initialize the propagator
for a new wave function collapse using the given constraint.
After calling this method, the next step is to call add_cell for each
cell that needs to be filled by wave function collapse.
Sourcepub fn add_cell(&mut self, position: Pos)
pub fn add_cell(&mut self, position: Pos)
Create a new cell at the given position, assuming that wave function collapse has not yet begun
and all the surrounding cells have no restrictions.
Calling this after restrict_edge, observe_random_cell,
or observe_all may produce undesirable consequences.
After all the cells have been added, the next step is to optionally call restrict_edge to constrain which patterns
the may be put into the border cells.
Sourcepub fn find_min_entropy<R>(&self, rng: &mut R) -> Option<Pos>
pub fn find_min_entropy<R>(&self, rng: &mut R) -> Option<Pos>
Randomly choose a low-entropy cell. This is used by observe_random_cell
to decide which cell will be observed.
Sourcepub fn choose_random_pattern<R, Con>(
&self,
position: &Pos,
rng: &mut R,
constraint: &Con,
) -> Option<Pat>
pub fn choose_random_pattern<R, Con>( &self, position: &Pos, rng: &mut R, constraint: &Con, ) -> Option<Pat>
Choose a random pattern from among the potential patterns for the given cell based
on probabilities given in constraint. This is called by
observe_random_cell to decide which pattern to assign.
Sourcepub fn restrict_edge<Con>(
&mut self,
position: &Pos,
pattern: &Pat,
constraint: &Con,
) -> Result<(), WfcFailure>
pub fn restrict_edge<Con>( &mut self, position: &Pos, pattern: &Pat, constraint: &Con, ) -> Result<(), WfcFailure>
Constrain the cells around the given position based on the assumption that the given
position has the given pattern. Calling this method twice on the same position may put
the surrounding cells into an invalid state, even if both calls have the same pattern.
This should be called after all cells have been added using add_cell,
and there should be no cell at the given position.
The next step is to call observe_random_cell or
observe_all to begin collapsing the wave function.
Sourcepub fn observe_all<R, Con>(
&mut self,
rng: &mut R,
constraint: &Con,
) -> Result<(), WfcFailure>where
R: Rng + ?Sized,
Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,
Pos: Debug,
<Pos as WavePosition>::Counter: Debug,
pub fn observe_all<R, Con>(
&mut self,
rng: &mut R,
constraint: &Con,
) -> Result<(), WfcFailure>where
R: Rng + ?Sized,
Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,
Pos: Debug,
<Pos as WavePosition>::Counter: Debug,
Completely collapse the wave function. This method repeatedly observes a random cell and propagates each observation until all cells have been observed or the wave function collapse fails due to not being able to find a valid pattern for some cell.
If the number of cells is large, this method may be slow. Use observe_random_cell
to progress the collapse one cell at a time and thereby have more control over the process
and allow the possibility of aborting.
Sourcepub fn observe_random_cell<R, Con>(
&mut self,
rng: &mut R,
constraint: &Con,
) -> Result<WfcControlFlow, WfcFailure>where
R: Rng + ?Sized,
Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,
Pos: Debug,
<Pos as WavePosition>::Counter: Debug,
pub fn observe_random_cell<R, Con>(
&mut self,
rng: &mut R,
constraint: &Con,
) -> Result<WfcControlFlow, WfcFailure>where
R: Rng + ?Sized,
Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,
Pos: Debug,
<Pos as WavePosition>::Counter: Debug,
Observing a cell means choosing a random pattern for that cell from all the potential patterns
for that particular cell. Each cell keeps its own independent list of possible patterns,
and after a cell has been observed the possibilities for the surrounding cells may need to be
restricted. The restriction of the surrounding cells is called propagation and it should be
performed after each observation by calling propagate or
propagate_until_finished.
If propagation is not complete when this method is called, then propagate_until_finished is
automatically called before the cell is observed.
WfcControlFlow::Continue is returned if a cell was successfully observed, meaning that propagation
and more observations may be required to complete the collapse.
WfcControlFlow::Finish is returned if no cell could be observed because the pattern for all
cells has already been determined and the wave function collapse is complete.
Sourcepub fn propagate_until_finished<Con>(
&mut self,
constraint: &Con,
) -> Result<(), WfcFailure>
pub fn propagate_until_finished<Con>( &mut self, constraint: &Con, ) -> Result<(), WfcFailure>
Repeatedly call propagate until it returns WfcControlFlow::Finish,
thus ensuring that all the cells are prepared for the next observation. This is called
automatically by observe_random_cell.
Sourcepub fn propagate<Con>(
&mut self,
constraint: &Con,
) -> Result<WfcControlFlow, WfcFailure>
pub fn propagate<Con>( &mut self, constraint: &Con, ) -> Result<WfcControlFlow, WfcFailure>
Propagate the restrictions from the most recent calls to observe_random_cell
or restrict_edge by one step, so that appropriate restrictions are spread across
the cells of the wave. This method should be repeatedly called until it returns WfcControlFlow::Finish
before another cell is observed so that the observation is based upon an accurate list of possible patterns
for the cell.
Trait Implementations§
Source§impl Clone for TileSetWfcPropagator
impl Clone for TileSetWfcPropagator
Source§fn clone(&self) -> TileSetWfcPropagator
fn clone(&self) -> TileSetWfcPropagator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TileSetWfcPropagator
impl Debug for TileSetWfcPropagator
Source§impl Default for TileSetWfcPropagator
impl Default for TileSetWfcPropagator
Source§fn default() -> TileSetWfcPropagator
fn default() -> TileSetWfcPropagator
Source§impl Deref for TileSetWfcPropagator
impl Deref for TileSetWfcPropagator
Source§type Target = WfcPropagator<Matrix<i32, Const<2>, Const<1>, ArrayStorage<i32, 2, 1>>, PatternBits>
type Target = WfcPropagator<Matrix<i32, Const<2>, Const<1>, ArrayStorage<i32, 2, 1>>, PatternBits>
Auto Trait Implementations§
impl Freeze for TileSetWfcPropagator
impl RefUnwindSafe for TileSetWfcPropagator
impl Send for TileSetWfcPropagator
impl Sync for TileSetWfcPropagator
impl Unpin for TileSetWfcPropagator
impl UnwindSafe for TileSetWfcPropagator
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.