pub struct HashWfcConstraint<Pat, V> { /* private fields */ }Expand description
An implementation for WfcConstrain that stores the information for each pattern
in a hash table and also keeps track of a which values each pattern may represent,
so that patterns may be translated into tiles after wave function collapse is complete.
Implementations§
Source§impl<Pat, V> HashWfcConstraint<Pat, V>
impl<Pat, V> HashWfcConstraint<Pat, V>
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all data, reseting this object to empty so it is ready to be reused with new pattern data.
Sourcepub fn add(&mut self, pattern: Pat, frequency: f32, value: V)
pub fn add(&mut self, pattern: Pat, frequency: f32, value: V)
Add a new value to the data with the given pattern and frequency.
The frequency does not need to be between 0.0 and 1.0.
Frequencies of 0.0 or less will be silently ignored, and
frequencies will be automatically normalized into probabilities
when finalize is called.
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Calculate the probability of each pattern based on the frequencies
of all values that were added with add.
The sum of the frequencies is calculated and then each frequency is
divided by the sum to normalize the frequencies into probabilities between
0.0 and 1.0.
Sourcepub fn finalize_with_terrain_normalization<Ter, F>(&mut self, terrain: F)
pub fn finalize_with_terrain_normalization<Ter, F>(&mut self, terrain: F)
Calculate the probability of each pattern based on the frequencies
of all values that were added with add.
Divide the frequency of each pattern by the total number of patterns
in that pattern’s terrain so that terrains with many patterns are not
given an advantage over terrains with few patterns.
The terrain function is used to determine the terrain of each pattern.
The sum of the frequencies is calculated and then each frequency is
divided by the sum to normalize the frequencies into probabilities between
0.0 and 1.0.
Sourcepub fn get_random<R>(&self, rng: &mut R, pattern: &Pat) -> Option<&V>
pub fn get_random<R>(&self, rng: &mut R, pattern: &Pat) -> Option<&V>
A random value that matches the given pattern, based upon previous calls to
add. Often there may be more than one tile that matches a particular
pattern, and so this method helps with the final step after wave function collapse:
converting the chosen patterns into actual tiles.
Trait Implementations§
Source§impl<Pat, V> Default for HashWfcConstraint<Pat, V>
impl<Pat, V> Default for HashWfcConstraint<Pat, V>
Source§fn default() -> HashWfcConstraint<Pat, V>
fn default() -> HashWfcConstraint<Pat, V>
Source§impl<Pat, V> WfcConstrain for HashWfcConstraint<Pat, V>
impl<Pat, V> WfcConstrain for HashWfcConstraint<Pat, V>
Source§type Offset = <Pat as TilePattern>::Offset
type Offset = <Pat as TilePattern>::Offset
Source§fn all_patterns(
&self,
) -> impl Iterator<Item = &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern>
fn all_patterns( &self, ) -> impl Iterator<Item = &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern>
Source§fn probability_of(
&self,
pattern: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern,
) -> f32
fn probability_of( &self, pattern: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern, ) -> f32
Source§fn is_legal(
&self,
from: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern,
offset: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Offset,
to: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern,
) -> bool
fn is_legal( &self, from: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern, offset: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Offset, to: &<HashWfcConstraint<Pat, V> as WfcConstrain>::Pattern, ) -> bool
from pattern may be chosen when the to pattern has already been chosen
for the cell at position offset relative to from.Auto Trait Implementations§
impl<Pat, V> Freeze for HashWfcConstraint<Pat, V>
impl<Pat, V> RefUnwindSafe for HashWfcConstraint<Pat, V>where
Pat: RefUnwindSafe,
V: RefUnwindSafe,
impl<Pat, V> Send for HashWfcConstraint<Pat, V>
impl<Pat, V> Sync for HashWfcConstraint<Pat, V>
impl<Pat, V> Unpin for HashWfcConstraint<Pat, V>
impl<Pat, V> UnwindSafe for HashWfcConstraint<Pat, V>where
Pat: UnwindSafe,
V: UnwindSafe,
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> 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.