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
impl Wave
pub fn new() -> Self
Sourcepub fn set_debug(&mut self)
pub fn set_debug(&mut self)
Sets the debug mode for the wave. This will print some extra output helpful for debugging.
Sourcepub fn collapse_all<F>(
&mut self,
max_contradictions: usize,
callback: Option<F>,
) -> Result<(), String>
pub fn collapse_all<F>( &mut self, max_contradictions: usize, callback: Option<F>, ) -> Result<(), String>
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.
- When an error is returned, the final state at which the error occurred is preserved in the wave.
Sourcepub fn perfect_rep(&self) -> Result<Vec<Vec<usize>>, String>
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.
pub fn current_rep(&self) -> Vec<Vec<Vec<usize>>>
Sourcepub fn collapse_once(&mut self)
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
NoHistoryflag.
- This can be disabled using the
- If the internal superposition grid is empty, this function will do nothing.
Sourcepub fn propagate(&mut self, center_element: usize)
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.
pub fn fill(&mut self, size: Vector2<usize>) -> Result<(), String>
Source§impl Wave
impl Wave
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clears the wave’s internal history log.
Sourcepub fn undo_collapse(&mut self, remove_record: bool) -> Result<(), String>
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
Waveis empty, this function does nothing. - If
remove_recordis 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.