Browse Source

more fixes

eqn_relations
Alex Mikhalev 6 years ago
parent
commit
8da067fec2
  1. 5
      src/main.rs
  2. 7
      src/math/eqn.rs
  3. 1
      src/math/mod.rs
  4. 8
      src/math/vec.rs

5
src/main.rs

@ -18,7 +18,7 @@ mod relation;
fn main() { fn main() {
use entity::{Point, PointRef, Var}; use entity::{Point, PointRef, Var};
use math::{Point2, eqn, Region2}; use math::{Point2, eqn, Region2, Rot2};
use relation::{Relation, ResolveResult}; use relation::{Relation, ResolveResult};
env_logger::init(); env_logger::init();
@ -48,8 +48,9 @@ fn main() {
let c4 = relation::PointAngle::new_vertical(p1.clone(), p2.clone()); let c4 = relation::PointAngle::new_vertical(p1.clone(), p2.clone());
let c3 = relation::PointAngle::new_horizontal(p2.clone(), p3.clone()); let c3 = relation::PointAngle::new_horizontal(p2.clone(), p3.clone());
let c2 = relation::AlignedDistance::new_vertical(p1.clone(), p2.clone(), 12.); 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<Box<dyn Relation>> = let mut relations: Vec<Box<dyn Relation>> =
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<Box<dyn Relation>> = Vec::new(); let mut constrained: Vec<Box<dyn Relation>> = Vec::new();
let mut any_underconstrained = true; let mut any_underconstrained = true;
let mut any_constrained = true; let mut any_constrained = true;

7
src/math/eqn.rs

@ -199,6 +199,9 @@ fn distribute_product_sums(mut es: Exprs) -> Expr {
trace!("distribute_product_sums: {}", Product(es.clone())); trace!("distribute_product_sums: {}", Product(es.clone()));
use itertools::Itertools; use itertools::Itertools;
use Expr::*; use Expr::*;
for e in &mut es {
*e = e.clone().distribute();
}
let sums = es let sums = es
.drain_filter(|e| match e { .drain_filter(|e| match e {
Sum(_) => true, Sum(_) => true,
@ -383,6 +386,10 @@ impl Expr {
match v { match v {
box Const(c) => Const(-c), box Const(c) => Const(-c),
box Neg(v) => *v, box Neg(v) => *v,
box Product(mut es) => {
es.push(Const(-1.));
Product(es)
}
e => Product(vec![Const(-1.), *e]), e => Product(vec![Const(-1.), *e]),
} }
} }

1
src/math/mod.rs

@ -212,6 +212,7 @@ impl Line2 {
+ b_0.y.clone() * a_c.clone()) + b_0.y.clone() * a_c.clone())
/ (a_s.clone() * b_c.clone() - a_c.clone() * b_s.clone()); / (a_s.clone() * b_c.clone() - a_c.clone() * b_s.clone());
// Region2::Singleton(b.evaluate(t_b)) // 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()))); let res = Region2::Line(b.clone().with_extent(Region1::Singleton(t_b.simplify())));
trace!("intersect a: {}, b: {} = {}", a, b, res); trace!("intersect a: {}, b: {} = {}", a, b, res);
res res

8
src/math/vec.rs

@ -92,8 +92,8 @@ impl<T> Point2<T> {
impl Point2<Value> { impl Point2<Value> {
pub fn simplify(self) -> Self { pub fn simplify(self) -> Self {
Self { Self {
x: self.x.simplify(), x: self.x.distribute().simplify().distribute().simplify(),
y: self.y.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 { pub fn cardinal(index: i64) -> Self {
match index % 4 { match index % 4 {
0 => Rot2 { 0 => Rot2 {

Loading…
Cancel
Save