diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-07-30 01:07:53 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-07-30 01:07:53 +0800 |
commit | b80eb726abcfd5b8c76df85d88f95e584d949f86 (patch) | |
tree | dbaaf42ebdbbbc488419006a2289ffd4c70f09e9 /svgbob | |
parent | c260fa2109789fd82b2f1ffd433bb505e8e06945 (diff) |
Fix circuitry, initial implementation for dashed line
Diffstat (limited to 'svgbob')
-rw-r--r-- | svgbob/src/element.rs | 10 | ||||
-rw-r--r-- | svgbob/src/enhance.rs | 135 | ||||
-rw-r--r-- | svgbob/src/focus_char.rs | 2 | ||||
-rw-r--r-- | svgbob/src/optimizer.rs | 1 |
4 files changed, 129 insertions, 19 deletions
diff --git a/svgbob/src/element.rs b/svgbob/src/element.rs index 2f3d737..f82dbb9 100644 --- a/svgbob/src/element.rs +++ b/svgbob/src/element.rs @@ -111,6 +111,10 @@ impl Element { // for line it has to be collinear and in can connect start->end->start // for text, the other text should apear on the right side of this text pub fn reduce(&self, other: &Element) -> Option<Element> { + // if same then return one + if self == other{ + return Some(other.clone()) + } match *self { Element::Line(ref s, ref e, ref stroke, ref feature) => { match *other { @@ -119,11 +123,15 @@ impl Element { if collinear(s, e, s2) && collinear(s, e, e2) && stroke == stroke2{ + // same length line + if s == s2 && e == e2 && feature == feature2{ + return Some(other.clone()) + } // line1 line2 // s-----e s2-----e2 // s----------------e2 - if e == s2 { + else if e == s2 { // ----- // o---- let cond1 = feature.is_empty() || (feature.contains(&Circle) && feature.len() == 1); diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs index b34815e..75c5e1b 100644 --- a/svgbob/src/enhance.rs +++ b/svgbob/src/enhance.rs @@ -4,7 +4,7 @@ use location::Location; use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight}; use block::Block::{A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y}; use point_block::PointBlock; -use fragments::{self, line, arc, arrow_line}; +use fragments::{self, line, arc, arrow_line, dashed_line}; pub trait Enhance { fn enhance(&self) -> (Vec<Fragment>, Vec<Location>); @@ -14,7 +14,6 @@ impl<'g> Enhance for FocusChar<'g> { fn enhance(&self) -> (Vec<Fragment>, Vec<Location>) { let mut elm = vec![]; let mut consumed = vec![]; - let a = &PointBlock::block(A); let _b = &PointBlock::block(B); let c = &PointBlock::block(C); @@ -41,43 +40,147 @@ impl<'g> Enhance for FocusChar<'g> { let _x = &PointBlock::block(X); let y = &PointBlock::block(Y); - let top = ||Location::go(Top); - let bottom = ||Location::go(Bottom); - let left = ||Location::go(Left); - let right = ||Location::go(Right); - let top_left = ||Location::go(TopLeft); - let top_right = ||Location::go(TopRight); - let bottom_left = ||Location::go(BottomLeft); - let bottom_right = ||Location::go(BottomRight); + let top = || Location::go(Top); + let bottom = || Location::go(Bottom); + let left = || Location::go(Left); + let right = || Location::go(Right); + let top_left = || Location::go(TopLeft); + let top_right = || Location::go(TopRight); + let bottom_left = || Location::go(BottomLeft); + let bottom_right = || Location::go(BottomRight); + // _ underscore if self.is('_') { // _| if self.right().any("|[") { - elm.push(fragments::line(u, &right().w())); + elm.push(line(u, &right().w())); } // |_ if self.left().any("|]") { - elm.push(fragments::line(y, &left().w())); + elm.push(line(y, &left().w())); } // _ // | if self.bottom_left().any("|]") { - elm.push(fragments::line(y, &left().w())); + elm.push(line(y, &left().w())); } // _ // | if self.bottom_right().any("|[") { - elm.push(fragments::line(u, &right().w())); + elm.push(line(u, &right().w())); } // /_ if self.left().is('/') { - elm.push(fragments::line(y, &left().u())); + elm.push(line(y, &left().u())); } if self.right().is('\\') { // _\ - elm.push(fragments::line(u, &right().y())); + elm.push(line(u, &right().y())); + } + } + else if self.any("`'") { + // for circuitries + // + + \ + // `> '> `> + if self.top_left().any("+\\") && self.right().is('>') { + elm.push(fragments::arrow_line(&top_left().m(), &right().f())); + consumed.push(right()); + if self.top_left().is('\\') { + consumed.push(top_left()); + } + } + // for circuitries + // + / + // <' <' + if self.top_right().any("+/") && self.left().is('<') { + elm.push(fragments::arrow_line(&top_right().m(), &left().j())); + consumed.push(left()); + if self.top_right().is('/') { + consumed.push(top_right()); + } + } + // For diamon rectanle + // . + // ' + if self.top_right().any(".,") { + elm.push(fragments::line(c, &top_right().m())); + consumed.push(top_right()); + } + // . + // ' + if self.top_left().any(".,") { + elm.push(fragments::line(c, &top_left().m())); + consumed.push(top_left()); + } + // .' + if self.left().any(".,") { + elm.push(fragments::line(c, &left().m())); + consumed.push(left()); + } + // '. + if self.right().any(".,") { + elm.push(fragments::line(c, &right().m())); + consumed.push(right()); } + } else if self.any(".,") { + // for circuitries + // <. <, + // + \ + if self.bottom_right().any("+\\") && self.left().is('<') { + elm.push(fragments::arrow_line(&bottom_right().m(), &left().t())); + consumed.push(left()); + if self.bottom_right().is('\\') { + consumed.push(bottom_right()); + } + } + // for circuitries + // .> ,> ,> + // + + / + if self.bottom_left().any("+/") && self.right().is('>') { + elm.push(fragments::arrow_line(&bottom_left().m(), &right().p())); + consumed.push(right()); + if self.bottom_left().is('/') { + consumed.push(bottom_left()); + } + } + } + // circuitries jump + // | + // -(- + // | + // + else if self.is('(') && self.top().can_strongly_connect(&W) + && self.bottom().can_strongly_connect(&C) + && self.left().can_strongly_connect(&O) + && self.right().can_strongly_connect(&K) + { + elm.extend(vec![arc(c, w, 5), line(k, o)]); + } + // circuitries jump + // | + // -)- + // | + // + else if self.is(')') && self.top().can_strongly_connect(&W) + && self.bottom().can_strongly_connect(&C) + && self.left().can_strongly_connect(&O) + && self.right().can_strongly_connect(&K) + { + elm.extend(vec![arc(w, c, 5), line(k, o)]); } + // for horizontal dash line + // - - + else if self.is('-') { + if self.right().is(' ') && self.in_right(2).is('-'){ + elm.push(dashed_line(k, &right().right().o())); + //consumed.push(right().right()); + } + if self.left().is(' ') && self.in_left(2).is('-'){ + elm.push(dashed_line(o, &left().left().k())); + //consumed.push(left().left()); + } + } + (elm, consumed) } } diff --git a/svgbob/src/focus_char.rs b/svgbob/src/focus_char.rs index 24e537c..c96d045 100644 --- a/svgbob/src/focus_char.rs +++ b/svgbob/src/focus_char.rs @@ -97,7 +97,7 @@ impl<'g> FocusChar<'g> { } fn is_text_char(&self)->bool{ - if self.ch.any("oO"){// exclude letter oO and _underscore in the alphanumeric + if self.ch.any("oO_"){// exclude letter oO and _underscore in the alphanumeric return false; } else { diff --git a/svgbob/src/optimizer.rs b/svgbob/src/optimizer.rs index 930f158..01c0410 100644 --- a/svgbob/src/optimizer.rs +++ b/svgbob/src/optimizer.rs @@ -6,7 +6,6 @@ use element::Stroke; pub struct Optimizer { elements: Vec<Vec<Vec<Element>>>, - /// TODO: consumed location should also include the consumed element index of that location. consumed_loc: Vec<Loc>, } |