pub struct Solver { /* private fields */ }
Expand description
A constraint solver using the Cassowary algorithm. For proper usage please see the top level crate documentation.
Implementations§
Source§impl Solver
impl Solver
pub fn add_constraints<'a, I: IntoIterator<Item = &'a Constraint>>( &mut self, constraints: I, ) -> Result<(), AddConstraintError>
Sourcepub fn add_constraint(
&mut self,
constraint: Constraint,
) -> Result<(), AddConstraintError>
pub fn add_constraint( &mut self, constraint: Constraint, ) -> Result<(), AddConstraintError>
Add a constraint to the solver.
Sourcepub fn remove_constraint(
&mut self,
constraint: &Constraint,
) -> Result<(), RemoveConstraintError>
pub fn remove_constraint( &mut self, constraint: &Constraint, ) -> Result<(), RemoveConstraintError>
Remove a constraint from the solver.
Sourcepub fn has_constraint(&self, constraint: &Constraint) -> bool
pub fn has_constraint(&self, constraint: &Constraint) -> bool
Test whether a constraint has been added to the solver.
Sourcepub fn add_edit_variable(
&mut self,
v: Variable,
strength: f64,
) -> Result<(), AddEditVariableError>
pub fn add_edit_variable( &mut self, v: Variable, strength: f64, ) -> Result<(), AddEditVariableError>
Add an edit variable to the solver.
This method should be called before the suggest_value
method is
used to supply a suggested value for the given edit variable.
Sourcepub fn remove_edit_variable(
&mut self,
v: Variable,
) -> Result<(), RemoveEditVariableError>
pub fn remove_edit_variable( &mut self, v: Variable, ) -> Result<(), RemoveEditVariableError>
Remove an edit variable from the solver.
Sourcepub fn has_edit_variable(&self, v: &Variable) -> bool
pub fn has_edit_variable(&self, v: &Variable) -> bool
Test whether an edit variable has been added to the solver.
Sourcepub fn suggest_value(
&mut self,
variable: Variable,
value: f64,
) -> Result<(), SuggestValueError>
pub fn suggest_value( &mut self, variable: Variable, value: f64, ) -> Result<(), SuggestValueError>
Suggest a value for the given edit variable.
This method should be used after an edit variable has been added to the solver in order to suggest the value for that variable.
Sourcepub fn fetch_changes(&mut self) -> &[(Variable, f64)]
pub fn fetch_changes(&mut self) -> &[(Variable, f64)]
Fetches all changes to the values of variables since the last call to this function.
The list of changes returned is not in a specific order. Each change comprises the variable changed and the new value of that variable.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the solver to the empty starting condition.
This method resets the internal solver state to the empty starting condition, as if no constraints or edit variables have been added. This can be faster than deleting the solver and creating a new one when the entire system must change, since it can avoid unnecessary heap (de)allocations.