diff --git a/src/main.rs b/src/main.rs index ae784b5..f6225bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,15 +28,15 @@ fn main() { let u2 = math::Unknown(2); // let u1 = eqn::Expr::from(1.); // let u2 = eqn::Expr::from(1.); - let origin = CPoint::new_single(Point2::new((0.).into(), (0.).into())).into_ref(); + let origin = CPoint::new_single(Point2::new(0., 0.)).into_ref(); // let p1 = Point::new_ref(Var::new_full(Point2::new((1.).into(), (1.).into()))); let p1 = CPoint::new( Point2::new(0., 0.), Region2::Singleton(Point2::new((u1).into(), (u2).into())), ) .into_ref(); - let p2 = CPoint::new_full(Point2::new((4.).into(), (4.).into())).into_ref(); - let p3 = CPoint::new_full(Point2::new((2.).into(), (2.).into())).into_ref(); + let p2 = CPoint::new_full(Point2::new(4., 4.)).into_ref(); + let p3 = CPoint::new_full(Point2::new(2., 2.)).into_ref(); let mut points: Vec = vec![origin.clone(), p1.clone(), p2.clone(), p3.clone()]; let print_points = |points: &Vec| { println!( diff --git a/src/math/eqn.rs b/src/math/eqn.rs index a9ff202..d54801d 100644 --- a/src/math/eqn.rs +++ b/src/math/eqn.rs @@ -3,6 +3,7 @@ use std::fmt; use super::expr::Expr; use super::unknown::*; use super::Scalar; +use crate::math::expr::Expr::*; #[derive(Clone, Debug, PartialEq)] pub struct Eqn(pub Expr, pub Expr); @@ -47,17 +48,18 @@ impl Eqn { if !self.has_unknown(for_u) { return None; } + trace!("solve: {}", self); let (l, r) = ( self.0 - .clone() /*.distribute()*/ + .clone().distribute() .simplify(), self.1 - .clone() /*.distribute()*/ + .clone().distribute() .simplify(), ); let (mut l, mut r) = ord_by_unkn(l, r, for_u)?; loop { - trace!("solve: {} == {}", l, r); + trace!("solve iter: {} == {}", l, r); let (new_l, new_r): (Expr, Expr) = match l { Unkn(u) => return if u == for_u { Some(r.simplify()) } else { None }, Sum(es) => { diff --git a/src/math/expr.rs b/src/math/expr.rs index 3e52633..692c5dd 100644 --- a/src/math/expr.rs +++ b/src/math/expr.rs @@ -31,14 +31,16 @@ impl Unknowns for Exprs { fn write_separated_exprs(es: &Exprs, f: &mut fmt::Formatter, sep: &str) -> fmt::Result { let mut is_first = true; + write!(f, "(")?; for e in es { if is_first { is_first = false; } else { write!(f, "{}", sep)? } - write!(f, "({})", e)? + write!(f, "{}", e)? } + write!(f, ")")?; Ok(()) } @@ -451,7 +453,7 @@ impl fmt::Display for Expr { Const(c) => write!(f, "{}", c), Sum(es) => write_separated_exprs(es, f, " + "), Product(es) => write_separated_exprs(es, f, " * "), - Div(num, den) => write!(f, "({}) / ({})", num, den), + Div(num, den) => write!(f, "({} / {})", num, den), Neg(e) => write!(f, "-({})", e), } } diff --git a/src/math/region.rs b/src/math/region.rs index 00ff31e..bfdb573 100644 --- a/src/math/region.rs +++ b/src/math/region.rs @@ -150,7 +150,7 @@ impl fmt::Display for Line2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{{ = {} + {} * {} }}", + "{{ (x, y, t): ⟨x, y⟩ = {} + t{} & t ∈ {} }}", self.start, self.dir, self.extent ) } diff --git a/src/math/vec.rs b/src/math/vec.rs index e5cc6d2..f7e5304 100644 --- a/src/math/vec.rs +++ b/src/math/vec.rs @@ -149,7 +149,7 @@ use std::fmt; impl fmt::Display for Point2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "<{}, {}>", self.x, self.y) + write!(f, "⟨{}, {}⟩", self.x, self.y) } } @@ -161,7 +161,7 @@ pub struct Rot2 { impl fmt::Display for Rot2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "<{}, {}>", self.cos, self.sin) + write!(f, "⟨{}, {}⟩", self.cos, self.sin) } }