Expand description
Encapsulation for the Wave Function Collapse implementation.
Fields§
§flags: Vec<Flags>Implementations§
source§impl Wave
impl Wave
pub fn new() -> Self
sourcepub fn collapse_all<F>(
&mut self,
max_contradictions: usize,
callback: Option<F>
) -> Result<(), String>where
F: Fn(usize, usize, Vec<Vec<Vec<usize>>>),
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 theWave. - 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.
pub fn perfect_rep(&self) -> Result<Vec<Vec<usize>>, String>
pub fn current_rep(&self) -> Vec<Vec<Vec<usize>>>
sourcepub fn collapse_once(&mut self)
pub fn collapse_once(&mut self)
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.