pub struct WfcPropagator<Pos, Pat>where
Pos: WavePosition,{ /* private fields */ }Expand description
The propagator is responsible for the wave function collapse algorithm and
it contains all the necessary data except for the WfcConstrain object
that contains the rules for which patterns may be chosen.
The contraint object is not owned by the propagator because the wave function collapse algorithm may be spread out across many steps and it may be necessary for the constraint object to not live as long as the propagator, and be reconstructed at each step.
Every constraint object at each step should always fully agree with the constraint objects at all previous steps, or else the algorithm may produce undesired results.
Implementations§
Source§impl<Pos, Pat> WfcPropagator<Pos, Pat>
impl<Pos, Pat> WfcPropagator<Pos, Pat>
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<Pos, Pat> Clone for WfcPropagator<Pos, Pat>
impl<Pos, Pat> Clone for WfcPropagator<Pos, Pat>
Source§fn clone(&self) -> WfcPropagator<Pos, Pat>
fn clone(&self) -> WfcPropagator<Pos, Pat>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Pos, Pat> Debug for WfcPropagator<Pos, Pat>
impl<Pos, Pat> Debug for WfcPropagator<Pos, Pat>
Source§impl<Pos, Pat> Default for WfcPropagator<Pos, Pat>
impl<Pos, Pat> Default for WfcPropagator<Pos, Pat>
Source§fn default() -> WfcPropagator<Pos, Pat>
fn default() -> WfcPropagator<Pos, Pat>
Auto Trait Implementations§
impl<Pos, Pat> Freeze for WfcPropagator<Pos, Pat>
impl<Pos, Pat> RefUnwindSafe for WfcPropagator<Pos, Pat>
impl<Pos, Pat> Send for WfcPropagator<Pos, Pat>
impl<Pos, Pat> Sync for WfcPropagator<Pos, Pat>
impl<Pos, Pat> Unpin for WfcPropagator<Pos, Pat>
impl<Pos, Pat> UnsafeUnpin for WfcPropagator<Pos, Pat>
impl<Pos, Pat> UnwindSafe for WfcPropagator<Pos, Pat>
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.