Improve ergonomics
This commit is contained in:
		
							parent
							
								
									3abe5c6573
								
							
						
					
					
						commit
						8a33818790
					
				| @ -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<PointRef> = vec![origin.clone(), p1.clone(), p2.clone(), p3.clone()]; | ||||
|     let print_points = |points: &Vec<PointRef>| { | ||||
|         println!( | ||||
|  | ||||
| @ -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) => { | ||||
|  | ||||
| @ -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), | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -150,7 +150,7 @@ impl fmt::Display for Line2 { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!( | ||||
|             f, | ||||
|             "{{ <x, y> = {} + {} * {} }}", | ||||
|             "{{ (x, y, t): ⟨x, y⟩ = {} + t{} & t ∈ {} }}", | ||||
|             self.start, self.dir, self.extent | ||||
|         ) | ||||
|     } | ||||
|  | ||||
| @ -149,7 +149,7 @@ use std::fmt; | ||||
| 
 | ||||
| impl<T: fmt::Display> fmt::Display for Point2<T> { | ||||
|     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) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user