diff --git a/src/main.rs b/src/main.rs index 424328f..88a0a9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ mod relation; fn main() { use entity::{Point, PointRef, Var}; - use math::{Point2, eqn, Region2}; + use math::{Point2, eqn, Region2, Rot2}; use relation::{Relation, ResolveResult}; env_logger::init(); @@ -48,8 +48,9 @@ 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 mut relations: Vec> = - vec![/*Box::new(c1),*/ Box::new(c2), Box::new(c3), Box::new(c4)]; + vec![/*Box::new(c1),*/ Box::new(c2), Box::new(c3), Box::new(c4), Box::new(c5)]; let mut constrained: Vec> = Vec::new(); let mut any_underconstrained = true; let mut any_constrained = true; diff --git a/src/math/eqn.rs b/src/math/eqn.rs index b07fa11..55090b6 100644 --- a/src/math/eqn.rs +++ b/src/math/eqn.rs @@ -199,6 +199,9 @@ fn distribute_product_sums(mut es: Exprs) -> Expr { trace!("distribute_product_sums: {}", Product(es.clone())); use itertools::Itertools; use Expr::*; + for e in &mut es { + *e = e.clone().distribute(); + } let sums = es .drain_filter(|e| match e { Sum(_) => true, @@ -383,6 +386,10 @@ impl Expr { match v { box Const(c) => Const(-c), box Neg(v) => *v, + box Product(mut es) => { + es.push(Const(-1.)); + Product(es) + } e => Product(vec![Const(-1.), *e]), } } diff --git a/src/math/mod.rs b/src/math/mod.rs index 44c6945..e51e087 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -212,6 +212,7 @@ impl Line2 { + b_0.y.clone() * a_c.clone()) / (a_s.clone() * b_c.clone() - a_c.clone() * b_s.clone()); // Region2::Singleton(b.evaluate(t_b)) + trace!("intersect a: {}, b: {}, t_b = {}", a, b, t_b); let res = Region2::Line(b.clone().with_extent(Region1::Singleton(t_b.simplify()))); trace!("intersect a: {}, b: {} = {}", a, b, res); res diff --git a/src/math/vec.rs b/src/math/vec.rs index 6890405..753b948 100644 --- a/src/math/vec.rs +++ b/src/math/vec.rs @@ -92,8 +92,8 @@ impl Point2 { impl Point2 { pub fn simplify(self) -> Self { Self { - x: self.x.simplify(), - y: self.y.simplify(), + x: self.x.distribute().simplify().distribute().simplify(), + y: self.y.distribute().simplify().distribute().simplify(), } } } @@ -170,6 +170,10 @@ impl Rot2 { } } + pub fn from_angle_deg(angle_deg: Scalar) -> Self { + Self::from_angle(angle_deg * std::f64::consts::PI / 180.) + } + pub fn cardinal(index: i64) -> Self { match index % 4 { 0 => Rot2 {