From f9b1f8924c8f3de9e9f25dbd1a86226157a166dd Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Mon, 25 Feb 2019 13:37:53 -0800 Subject: [PATCH] add resolve_with --- src/entity.rs | 10 ++++++++++ src/main.rs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/entity.rs b/src/entity.rs index 7e2dae5..5da3b78 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -34,6 +34,16 @@ impl + Clone> Var { &self.value } + pub fn resolve_with(&mut self, eqns: &Eqns) -> bool { + let resolved_constraints = self.constraints.clone().evaluate_with(eqns).simplify(); + if let Some(n) = resolved_constraints.nearest(&self.value) { + self.value = n; + true + } else { + false + } + } + pub fn evaluate_with(&mut self, eqns: &Eqns) -> bool { self.constraints = self.constraints.clone().evaluate_with(eqns).simplify(); if let Some(n) = self.constraints.nearest(&self.value) { diff --git a/src/main.rs b/src/main.rs index 1886d16..3b6aa74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ fn main() { let c4 = relation::PointAngle::new_vertical(p1.clone(), p2.clone()); let c3 = relation::PointAngle::new_horizontal(p2.clone(), p3.clone()); let c2 = relation::AlignedDistance::new_vertical(p1.clone(), p2.clone(), 12.); - let c5 = relation::PointAngle::new(p1.clone(), p3.clone(), Rot2::from_angle_deg(45.)); + let c5 = relation::PointAngle::new(p1.clone(), p3.clone(), Rot2::from_angle_deg(0.572938698)); let mut relations: Vec> = vec![/*Box::new(c1),*/ Box::new(c2), Box::new(c3), Box::new(c4), Box::new(c5)]; let mut constrained: Vec> = Vec::new(); @@ -94,7 +94,7 @@ fn main() { let e2 = eqn::Eqn::new(eqn::Expr::Unkn(u2), eqn::Expr::Const(1.)); let eqns = eqn::Eqns(vec![e1, e2]); for p in &mut points { - p.borrow_mut().pos.evaluate_with(&eqns); + p.borrow_mut().pos.resolve_with(&eqns); } print_points(&points); }