|
|
|
@ -21,10 +21,15 @@ pub type Value = eqn::Expr;
@@ -21,10 +21,15 @@ pub type Value = eqn::Expr;
|
|
|
|
|
|
|
|
|
|
// pub type Rot2 = nalgebra::UnitComplex<Value>;
|
|
|
|
|
|
|
|
|
|
pub trait Region<T> { |
|
|
|
|
pub trait GenericRegion { |
|
|
|
|
fn full() -> Self; |
|
|
|
|
fn intersection(self, other: Self) -> Self; |
|
|
|
|
fn simplify(self) -> Self; |
|
|
|
|
fn evaluate_with(self, eqns: &eqn::Eqns) -> Self; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub trait Region<T>: GenericRegion { |
|
|
|
|
fn singleton(value: T) -> Self; |
|
|
|
|
// fn intersection(self, other: Self) -> Self;
|
|
|
|
|
|
|
|
|
|
fn nearest(&self, value: &T) -> Option<T>; |
|
|
|
|
fn contains(&self, value: &T) -> Option<bool>; |
|
|
|
@ -53,12 +58,16 @@ impl fmt::Display for Region1 {
@@ -53,12 +58,16 @@ impl fmt::Display for Region1 {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region1 { |
|
|
|
|
pub fn intersection(self, other: Region1) -> Self { |
|
|
|
|
impl GenericRegion for Region1 { |
|
|
|
|
fn intersection(self, other: Region1) -> Self { |
|
|
|
|
Region1::Intersection(Box::new(self), Box::new(other)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn simplify(self) -> Self { |
|
|
|
|
fn full() -> Self { |
|
|
|
|
Region1::Full |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn simplify(self) -> Self { |
|
|
|
|
use Region1::*; |
|
|
|
|
match self { |
|
|
|
|
Singleton(n) => Singleton(n.simplify()), |
|
|
|
@ -67,13 +76,19 @@ impl Region1 {
@@ -67,13 +76,19 @@ impl Region1 {
|
|
|
|
|
other => other, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region<Scalar> for Region1 { |
|
|
|
|
fn full() -> Self { |
|
|
|
|
Region1::Full |
|
|
|
|
fn evaluate_with(self, eqns: &eqn::Eqns) -> Self { |
|
|
|
|
use Region1::*; |
|
|
|
|
match self { |
|
|
|
|
Singleton(n) => Singleton(n.evaluate_with(eqns)), |
|
|
|
|
Range(l, u) => Range(l.evaluate_with(eqns), u.evaluate_with(eqns)), |
|
|
|
|
Intersection(r1, r2) => r1.evaluate_with(eqns).intersection(r2.evaluate_with(eqns)), |
|
|
|
|
other => other, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region<Scalar> for Region1 { |
|
|
|
|
fn singleton(value: Scalar) -> Self { |
|
|
|
|
Region1::Singleton(value.into()) |
|
|
|
|
} |
|
|
|
@ -230,6 +245,14 @@ impl Line2 {
@@ -230,6 +245,14 @@ impl Line2 {
|
|
|
|
|
} |
|
|
|
|
Region2::Line(new_l) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn evaluate_with(self, eqns: &eqn::Eqns) -> Self { |
|
|
|
|
Line2 { |
|
|
|
|
start: self.start.evaluate_with(eqns), |
|
|
|
|
dir: self.dir, |
|
|
|
|
extent: self.extent.evaluate_with(eqns), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)] |
|
|
|
@ -257,11 +280,42 @@ impl fmt::Display for Region2 {
@@ -257,11 +280,42 @@ impl fmt::Display for Region2 {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region<Point2<Scalar>> for Region2 { |
|
|
|
|
impl GenericRegion for Region2 { |
|
|
|
|
fn full() -> Self { |
|
|
|
|
Region2::Full |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn intersection(self, other: Self) -> Self { |
|
|
|
|
use Region2::*; |
|
|
|
|
match (self, other) { |
|
|
|
|
(Empty, _) | (_, Empty) => Empty, |
|
|
|
|
(Full, r) | (r, Full) => r, |
|
|
|
|
(r1, r2) => Intersection(Box::new(r1), Box::new(r2)), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn simplify(self) -> Region2 { |
|
|
|
|
use Region2::*; |
|
|
|
|
match self { |
|
|
|
|
Singleton(n) => Singleton(n.simplify()), |
|
|
|
|
Line(l) => l.simplify(), |
|
|
|
|
Intersection(r1, r2) => r1.simplify().intersect(r2.simplify()), |
|
|
|
|
other => other, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn evaluate_with(self, eqns: &eqn::Eqns) -> Self { |
|
|
|
|
use Region2::*; |
|
|
|
|
match self { |
|
|
|
|
Singleton(n) => Singleton(n.evaluate_with(eqns)), |
|
|
|
|
Line(l) => Line(l.evaluate_with(eqns)), |
|
|
|
|
Intersection(r1, r2) => r1.evaluate_with(eqns).intersection(r2.evaluate_with(eqns)), |
|
|
|
|
other => other, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region<Point2<Scalar>> for Region2 { |
|
|
|
|
fn singleton(value: Point2<Scalar>) -> Self { |
|
|
|
|
Region2::Singleton(value.into()) |
|
|
|
|
} |
|
|
|
@ -312,10 +366,6 @@ impl Region<Point2<Scalar>> for Region2 {
@@ -312,10 +366,6 @@ impl Region<Point2<Scalar>> for Region2 {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region<Point2<Value>> for Region2 { |
|
|
|
|
fn full() -> Self { |
|
|
|
|
Region2::Full |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn singleton(value: Point2<Value>) -> Self { |
|
|
|
|
Region2::Singleton(value) |
|
|
|
|
} |
|
|
|
@ -353,15 +403,6 @@ impl Region<Point2<Value>> for Region2 {
@@ -353,15 +403,6 @@ impl Region<Point2<Value>> for Region2 {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Region2 { |
|
|
|
|
pub fn intersection(self, other: Self) -> Self { |
|
|
|
|
use Region2::*; |
|
|
|
|
match (self, other) { |
|
|
|
|
(Empty, _) | (_, Empty) => Empty, |
|
|
|
|
(Full, r) | (r, Full) => r, |
|
|
|
|
(r1, r2) => Intersection(Box::new(r1), Box::new(r2)), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
pub fn union(r1: Region2, r2: Region2) -> Region2 { |
|
|
|
|
use Region2::*; |
|
|
|
@ -402,14 +443,4 @@ impl Region2 {
@@ -402,14 +443,4 @@ impl Region2 {
|
|
|
|
|
(r1, r2) => Intersection(Box::new(r1), Box::new(r2)), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn simplify(self) -> Region2 { |
|
|
|
|
use Region2::*; |
|
|
|
|
match self { |
|
|
|
|
Singleton(n) => Singleton(n.simplify()), |
|
|
|
|
Line(l) => l.simplify(), |
|
|
|
|
Intersection(r1, r2) => r1.simplify().intersect(r2.simplify()), |
|
|
|
|
other => other, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|