Skip to main content

TileSetWfcPropagator

Struct TileSetWfcPropagator 

Source
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

Source

pub fn constrain_edges<Con>( &mut self, tile_set: &TileSet, pattern_property: TileSetPropertyNine, tile_map: &TileMap, update: &MacroTilesUpdate, constraint: &Con, ) -> Result<(), WfcFailure>
where Con: WfcConstrain<Pattern = PatternBits, Offset = Vector2Offset>,

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.

Source

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.

Source

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>>§

Source

pub fn is_empty(&self) -> bool

This propagator contains no cells.

Source

pub fn positions(&self) -> impl Iterator<Item = &Pos>

An iterator over the positions of every cell of the wave.

Source

pub fn contains_cell(&self, position: &Pos) -> bool

True if the wave has a cell at the given position.

Source

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.

Source

pub fn fill_from<Con>(&mut self, constraint: &Con)
where Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,

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.

Source

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.

Source

pub fn find_min_entropy<R>(&self, rng: &mut R) -> Option<Pos>
where R: Rng + ?Sized, <Pos as WavePosition>::Counter: Debug,

Randomly choose a low-entropy cell. This is used by observe_random_cell to decide which cell will be observed.

Source

pub fn choose_random_pattern<R, Con>( &self, position: &Pos, rng: &mut R, constraint: &Con, ) -> Option<Pat>
where R: Rng + ?Sized, Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,

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.

Source

pub fn restrict_edge<Con>( &mut self, position: &Pos, pattern: &Pat, constraint: &Con, ) -> Result<(), WfcFailure>
where Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>, Pos: Debug,

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.

Source

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.

Source

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.

Source

pub fn propagate_until_finished<Con>( &mut self, constraint: &Con, ) -> Result<(), WfcFailure>
where Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,

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.

Source

pub fn propagate<Con>( &mut self, constraint: &Con, ) -> Result<WfcControlFlow, WfcFailure>
where Con: WfcConstrain<Pattern = Pat, Offset = <Pos as OffsetPosition>::Offset>,

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

Source§

fn clone(&self) -> TileSetWfcPropagator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TileSetWfcPropagator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TileSetWfcPropagator

Source§

fn default() -> TileSetWfcPropagator

Returns the “default value” for a type. Read more
Source§

impl Deref for TileSetWfcPropagator

Source§

type Target = WfcPropagator<Matrix<i32, Const<2>, Const<1>, ArrayStorage<i32, 2, 1>>, PatternBits>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for TileSetWfcPropagator

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsyncTaskResult for T
where T: Any + Send + 'static,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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 T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T, U> ObjectOrVariant<T> for U

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more