use arael::model::{CrossBlock, Param};
use arael::vect::vect2d;
use arael_sketch_solver::*;
fn main() {
let mut sketch = Sketch::new();
let bottom = sketch.add_line(vect2d::new(0.0, 0.0), vect2d::new(3.0, 0.1));
let right = sketch.add_line(vect2d::new(3.1, 0.0), vect2d::new(3.0, 2.1));
let top = sketch.add_line(vect2d::new(2.9, 2.0), vect2d::new(0.1, 1.9));
let left = sketch.add_line(vect2d::new(0.0, 2.1), vect2d::new(0.1, 0.1));
sketch.lines[bottom].constraints.horizontal = true;
sketch.lines[top].constraints.horizontal = true;
sketch.lines[left].constraints.vertical = true;
sketch.lines[right].constraints.vertical = true;
for (a, b) in [(bottom, right), (right, top), (top, left), (left, bottom)] {
sketch.coincident_ll21.push(CoincidentLL21 {
a, b, nid: 0, cid: 0, hb: CrossBlock::new(),
});
}
sketch.lines[bottom].p1 = Param::fixed(vect2d::new(0.0, 0.0));
sketch.lines[bottom].constraints.has_length = true;
sketch.lines[bottom].constraints.length = 4.0;
sketch.lines[left].constraints.has_length = true;
sketch.lines[left].constraints.length = 2.0;
let result = sketch.solve();
println!("solver: iters={}, cost={:.6} -> {:.6}",
result.iterations, result.start_cost, result.end_cost);
let b = &sketch.lines[bottom];
let r = &sketch.lines[right];
let t = &sketch.lines[top];
let l = &sketch.lines[left];
println!("bottom: ({:.3},{:.3}) -> ({:.3},{:.3})",
b.p1.value.x, b.p1.value.y, b.p2.value.x, b.p2.value.y);
println!("right: ({:.3},{:.3}) -> ({:.3},{:.3})",
r.p1.value.x, r.p1.value.y, r.p2.value.x, r.p2.value.y);
println!("top: ({:.3},{:.3}) -> ({:.3},{:.3})",
t.p1.value.x, t.p1.value.y, t.p2.value.x, t.p2.value.y);
println!("left: ({:.3},{:.3}) -> ({:.3},{:.3})",
l.p1.value.x, l.p1.value.y, l.p2.value.x, l.p2.value.y);
}