Wave

Struct Wave 

Source
pub struct Wave {
    pub flags: Vec<Flags>,
    /* private fields */
}
Expand description

Encapsulation for the Wave Function Collapse implementation.

Fields§

§flags: Vec<Flags>

Implementations§

Source§

impl Wave

Source

pub fn new() -> Self

Source

pub fn set_debug(&mut self)

Sets the debug mode for the wave. This will print some extra output helpful for debugging.

Source

pub fn collapse_all<F>( &mut self, max_contradictions: usize, callback: Option<F>, ) -> Result<(), String>
where F: Fn(usize, usize, Vec<Vec<Vec<usize>>>),

Collapses continuously until the wave function either completely collapses or the max number of contradictions (attempts has been reached).

§Arguments
  • callback: An optional function which accepts the number of iterations and failures occured, as well as the current state of the wave function. This can be used for logging or print purposes.
§Notes
  • The number of iterations resets after a failed attempt. The number of failures is never reset.
  • The current representation (Vec<Vec<Vec<usize>>>) is provided in the callback as its not available while the function is borrowing the Wave.
  • No final perfect result is returned from a successful run as to avoid doing extra work in case the caller doesn’t need the final representation.
  • When an error is returned, the final state at which the error occurred is preserved in the wave.
Source

pub fn perfect_rep(&self) -> Result<Vec<Vec<usize>>, String>

Returns the perfect representation of the current internal state of the wave.

This function will throw an error if the internal wave isn’t completely collapsed.

Source

pub fn current_rep(&self) -> Vec<Vec<Vec<usize>>>

Source

pub fn collapse_once(&mut self)

Causing the wave to perform one collapse. This will also cause consequent propagation.

§Notes
  • The wave doesn’t stop propogating until its completely iterated over the entire superposition grid. It does this as, although on the first run it doesn’t make much sense, on future runs it will propagate out changes between the sites of different collapses.
  • After this function is called, it saves what it did to a private history log.
    • This can be disabled using the NoHistory flag.
  • If the internal superposition grid is empty, this function will do nothing.
Source

pub fn propagate(&mut self, center_element: usize)

Propagates pattern changes from a center element to its neighbours, pruning invalid pattern values based on consistency with the rules of the collapsed center element.

Source

pub fn fill(&mut self, size: Vector2<usize>) -> Result<(), String>

Source

pub fn analyze( &mut self, input: Vec<Vec<usize>>, chunk_size: Vector2<usize>, border_mode: BorderMode, )

Please note, the flag Flag::NoTransforms must be set at this point for it to be registered.

Source§

impl Wave

Source

pub fn clear_history(&mut self)

Clears the wave’s internal history log.

Source

pub fn undo_collapse(&mut self, remove_record: bool) -> Result<(), String>

Undo’s the last collapse undertaken by the algorithm.

§Parameters:
  • remove_record: Determines whether the operation being undone should be forgotten in the internal history log or remembered.
§Notes:
  • If the internal history log for the Wave is empty, this function does nothing.
  • If remove_record is set to true, if an error is returned, DO NOT attempt another undo.
    • In this situation, the last undo will have been marked as undone but an error occurred during this process. Undoing again will likely result in an error for a variety of reasons.
Source

pub fn redo_collapse(&mut self) -> Result<(), String>

Redos the previous undo if one occured. Otherwise, this function does nothing.

§Notes:

Trait Implementations§

Source§

impl Clone for Wave

Source§

fn clone(&self) -> Wave

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

Auto Trait Implementations§

§

impl Freeze for Wave

§

impl RefUnwindSafe for Wave

§

impl Send for Wave

§

impl Sync for Wave

§

impl Unpin for Wave

§

impl UnwindSafe for Wave

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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