pub enum FailReason {
Inconsistent,
DidntConverge,
TooManyUnknowns,
}Expand description
Reasons that the constraint solver failed.
§Examples
Most commonly, a failed solve will result from an over-constrained system. This can fall into two different categories: consistently over-constrained and inconsistently over-constrained.
A consistently over-constrained system is solveable, but has redundant constraints.
In the example below, the distance between p1 and p2 is constrained to be
10 units twice.
Note that while the solver returns a failure, the locations for p1 and p2 have
moved to satisfy the constraint.
use slvs::{
constraint::PtPtDistance,
entity::Point,
system::{FailReason, SolveResult},
System,
};
let mut sys = System::new();
let g = sys.add_group();
let p1 = sys
.sketch(Point::new_in_3d(g, [10.0, 10.0, 10.0]))
.expect("p1 created");
let p2 = sys
.sketch(Point::new_in_3d(g, [20.0, 20.0, 20.0]))
.expect("p2 created");
// distance between p1 and p2 is 10
sys.constrain(PtPtDistance::new(g, p1, p2, 10.0, None))
.expect("distance constraint added");
// distance between p1 and p2 is 10, a second time
sys.constrain(PtPtDistance::new(g, p1, p2, 10.0, None))
.expect("distance constraint added");
let solve_result = sys.solve(&g);
if let SolveResult::Fail { reason, .. } = solve_result {
assert_eq!(reason, FailReason::Inconsistent);
println!("{:#?}", sys.entity_data(&p1));
println!("{:#?}", sys.entity_data(&p2));
}An *inconsistently over-constrained system has constraints that cannot be satisfied
simultaneously. Here, we have tried to constrain the distances between p1 and p2
to be 10 units and 20 units apart, at the same time.
With inconsistently over-constrained systems, entities will remain in their initial position after the solve attempt.
use slvs::{
constraint::PtPtDistance,
entity::Point,
system::{FailReason, SolveResult},
System,
};
let mut sys = System::new();
let g = sys.add_group();
let p1 = sys
.sketch(Point::new_in_3d(g, [10.0, 10.0, 10.0]))
.expect("p1 created");
let p2 = sys
.sketch(Point::new_in_3d(g, [20.0, 20.0, 20.0]))
.expect("p2 created");
// distance between p1 and p2 is 10
sys.constrain(PtPtDistance::new(g, p1, p2, 10.0, None))
.expect("distance constraint added");
// distance between p1 and p2 is 20
sys.constrain(PtPtDistance::new(g, p1, p2, 20.0, None))
.expect("distance constraint added");
let solve_result = sys.solve(&g);
if let SolveResult::Fail { reason, .. } = solve_result {
assert_eq!(reason, FailReason::Inconsistent);
println!("{:#?}", sys.entity_data(&p1));
println!("{:#?}", sys.entity_data(&p2));
}Variants§
Inconsistent
DidntConverge
The conditions required to ensure that Newton’s method will converge were not met.
TooManyUnknowns
The system exceeds the hard-coded maximum of 2048 variables.
Trait Implementations§
Source§impl Clone for FailReason
impl Clone for FailReason
Source§fn clone(&self) -> FailReason
fn clone(&self) -> FailReason
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more