|
|
|
@ -1,3 +1,5 @@
@@ -1,3 +1,5 @@
|
|
|
|
|
#![feature(drain_filter)] |
|
|
|
|
|
|
|
|
|
extern crate nalgebra; |
|
|
|
|
#[macro_use] |
|
|
|
|
extern crate approx; |
|
|
|
@ -15,7 +17,7 @@ fn main() {
@@ -15,7 +17,7 @@ fn main() {
|
|
|
|
|
let origin = Point::new_ref(Var::new_single(Point2::new(0., 0.))); |
|
|
|
|
let p1 = Point::new_ref(Var::new_full(Point2::new(1., 1.))); |
|
|
|
|
let p2 = Point::new_ref(Var::new_full(Point2::new(4., 4.))); |
|
|
|
|
let p3 = Point::new_ref(Var::new_single(Point2::new(2., 2.))); |
|
|
|
|
let p3 = Point::new_ref(Var::new_full(Point2::new(2., 2.))); |
|
|
|
|
let mut points: Vec<PointRef> = vec![origin.clone(), p1.clone(), p2.clone(), p3.clone()]; |
|
|
|
|
let print_points = |points: &Vec<PointRef>| { |
|
|
|
|
println!( |
|
|
|
@ -29,23 +31,49 @@ fn main() {
@@ -29,23 +31,49 @@ fn main() {
|
|
|
|
|
p2: p1.clone(), |
|
|
|
|
}; |
|
|
|
|
let c2 = relation::PointAngle::new_vertical(p1.clone(), p2.clone()); |
|
|
|
|
let c3 = relation::PointAngle::new_horizontal(p1.clone(), p2.clone()); |
|
|
|
|
let c4 = relation::PointAngle::new_horizontal(p1.clone(), p3.clone()); |
|
|
|
|
let mut relations: Vec<Box<dyn Relation>> = |
|
|
|
|
vec![Box::new(c1), Box::new(c2), Box::new(c3), Box::new(c4)]; |
|
|
|
|
let mut has_underconstrained = true; |
|
|
|
|
while has_underconstrained { |
|
|
|
|
has_underconstrained = false; |
|
|
|
|
for r in &relations { |
|
|
|
|
let c3 = relation::PointAngle::new_horizontal(p2.clone(), p3.clone()); |
|
|
|
|
// let c4 = relation::PointAngle::new_horizontal(p1.clone(), p3.clone());
|
|
|
|
|
let mut relations: Vec<Box<dyn Relation>> = vec![ |
|
|
|
|
Box::new(c1), |
|
|
|
|
Box::new(c2), |
|
|
|
|
Box::new(c3), /*, Box::new(c4)*/ |
|
|
|
|
]; |
|
|
|
|
let mut constrained: Vec<Box<dyn Relation>> = Vec::new(); |
|
|
|
|
let mut any_underconstrained = true; |
|
|
|
|
let mut any_constrained = true; |
|
|
|
|
let mut any_overconstrained = false; |
|
|
|
|
while any_underconstrained && any_constrained && !any_overconstrained { |
|
|
|
|
any_underconstrained = false; |
|
|
|
|
any_constrained = false; |
|
|
|
|
let newly_constrained = relations.drain_filter(|r| { |
|
|
|
|
let rr = r.resolve(); |
|
|
|
|
if rr == ResolveResult::Underconstrained { |
|
|
|
|
has_underconstrained = true; |
|
|
|
|
} |
|
|
|
|
println!("resolve result: {:?}", rr); |
|
|
|
|
println!( |
|
|
|
|
"origin, p1, p2, p3:\n {:?}\n {:?}\n {:?}\n {:?}", |
|
|
|
|
origin, p1, p2, p3 |
|
|
|
|
); |
|
|
|
|
match rr { |
|
|
|
|
ResolveResult::Underconstrained => { |
|
|
|
|
any_underconstrained = true; |
|
|
|
|
false |
|
|
|
|
} |
|
|
|
|
ResolveResult::Constrained => { |
|
|
|
|
any_constrained = true; |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
ResolveResult::Overconstrained => { |
|
|
|
|
any_overconstrained = true; |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
constrained.extend(newly_constrained); |
|
|
|
|
} |
|
|
|
|
if any_overconstrained { |
|
|
|
|
println!("The system is overconstrained") |
|
|
|
|
} else if any_underconstrained { |
|
|
|
|
println!("Some constraints could not be solved") |
|
|
|
|
} else { |
|
|
|
|
println!("All constraints have been solved") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|