summaryrefslogtreecommitdiffstats
path: root/svgbob/src/element.rs
diff options
context:
space:
mode:
Diffstat (limited to 'svgbob/src/element.rs')
-rw-r--r--svgbob/src/element.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/svgbob/src/element.rs b/svgbob/src/element.rs
index 4dfe1a5..17b3b08 100644
--- a/svgbob/src/element.rs
+++ b/svgbob/src/element.rs
@@ -19,6 +19,7 @@ use element::{
Feature::{Arrow,ArrowStart,Circle,Square,OpenCircle,BigOpenCircle,Nothing},
};
use unicode_width::UnicodeWidthStr;
+use point;
@@ -32,6 +33,28 @@ pub enum Element {
Text(Loc, String),
}
+impl Element{
+
+ fn longer_line<'a>(&'a self, other: &'a Element) -> &'a Element {
+ match self{
+ Element::Line(s1, e1, _, _, _) => match other{
+ Element::Line(s2, e2, _, _,_) => {
+ let d1 = point::distance(s1, e1);
+ let d2 = point::distance(s2, e2);
+ if d1 > d2 {
+ self
+ }
+ else{
+ other
+ }
+ }
+ _ => panic!("only for lines"),
+ }
+ _ => panic!("only for lines"),
+ }
+ }
+}
+
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
pub enum Stroke {
Solid,
@@ -165,6 +188,7 @@ impl Element {
return Some(other.clone())
}
+ // extend 1 with 2
// line1 line2
// s-----e s2-----e2
// s----------------e2
@@ -183,6 +207,7 @@ impl Element {
));
}
}
+ // extend 1 with flip 2
// line1 line2
// s------e e2-------s2
// s-------------------s2
@@ -199,6 +224,7 @@ impl Element {
));
}
}
+ // flip1 extend 2
// line1 line2
// e------s s2------e2
// s------------------e2
@@ -215,7 +241,17 @@ impl Element {
end_feature2.clone(),
));
}
+ // TODO: need fixing
+ // same starting point, take longer line
+ // longer line
+ // s-------e
+ // s2-------------->e2
+ else {
+ //println!("longer line");
+ return Some(self.longer_line(other).clone())
+ }
}
+ // extend 2 with 1
// line1 line2
// e------s e2------s2
// e---------------------s2
@@ -235,6 +271,7 @@ impl Element {
));
}
}
+
}
return None;
}