summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2018-07-29 03:53:36 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2018-07-29 03:53:36 +0800
commit038f0ccfe8b3de8500c13d15a57f4dc204f0b32d (patch)
tree4fac78bcfa9407c63ad43eb0a1123886cda521eb
parentd70b9bfb5b4f0770fabd01b0617c2a67e9e759f9 (diff)
removed enhancements
-rw-r--r--svgbob/src/enhance.rs272
-rw-r--r--svgbob/src/enhance_circles.rs531
-rw-r--r--svgbob/src/lib.rs41
-rw-r--r--svgbob/src/optimizer.rs5
-rw-r--r--svgbob/src/patterns.rs6
5 files changed, 37 insertions, 818 deletions
diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs
deleted file mode 100644
index bba89d0..0000000
--- a/svgbob/src/enhance.rs
+++ /dev/null
@@ -1,272 +0,0 @@
-use fragments::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 patterns::FocusChar;
-use properties::Location;
-use properties::PointBlock;
-
-use fragments::Fragment;
-use fragments::{arc, line};
-
-pub trait Enhance {
- fn enhance(&self) -> (Vec<Fragment>, Vec<Location>);
-}
-
-impl<'g> Enhance for FocusChar<'g> {
- ///
- /// Enhancement use case where it is hard to incorporate into the default characteristic
- /// examples:
- /// + \ _ _
- /// `> `> |_ _|
- ///
- /// .-.
- /// ( )
- /// `-'
- ///
- /// without checking the characteristic, this will enchance the character
- /// based on the surrounding neighbors
- /// returns the fragments, consumed location
- fn enhance(&self) -> (Vec<Fragment>, Vec<Location>) {
- use fragments;
- use fragments::Direction::*;
- let a = &PointBlock::block(A);
- let _b = &PointBlock::block(B);
- let c = &PointBlock::block(C);
- let _d = &PointBlock::block(D);
- let e = &PointBlock::block(E);
- let _f = &PointBlock::block(F);
- let _g = &PointBlock::block(G);
- let _h = &PointBlock::block(H);
- let _i = &PointBlock::block(I);
- let _j = &PointBlock::block(J);
- let k = &PointBlock::block(K);
- let l = &PointBlock::block(L);
- let _m = &PointBlock::block(M);
- let n = &PointBlock::block(N);
- let o = &PointBlock::block(O);
- let _p = &PointBlock::block(P);
- let _q = &PointBlock::block(Q);
- let _r = &PointBlock::block(R);
- let _s = &PointBlock::block(S);
- let _t = &PointBlock::block(T);
- let u = &PointBlock::block(U);
- let _v = &PointBlock::block(V);
- let w = &PointBlock::block(W);
- 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 enable_aggressive_underscore = true;
-
- let mut elm = vec![];
- let mut consumed = vec![];
- if self.is('|') {
- // | |
- // < >
- if self.bottom().any("></\\") {
- elm.push(line(c, &bottom().m()));
- }
- // < >
- // | |
- if self.top().any("></\\") {
- elm.push(line(w, &top().m()));
- }
- } else if self.is('/') {
- // >
- // /
- if self.top_right().is('>') {
- elm.push(line(u, &top_right().m()));
- }
- // /
- // <
- if self.bottom_left().is('<') {
- elm.push(line(e, &bottom_left().m()));
- }
- } else if self.is('\\') {
- // \
- // >
- if self.bottom_right().is('>') {
- elm.push(line(a, &bottom_right().m()));
- }
- // <
- // \
- if self.top_left().is('<') {
- elm.push(line(y, &top_left().m()));
- }
- } 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());
- }
- }
- // .
- // '
- 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());
- }
- }
- } else if self.is('_') {
- // _|
- if self.right().any("|[") {
- elm.push(fragments::line(u, &right().w()));
- }
- // |_
- if self.left().any("|]") {
- elm.push(fragments::line(y, &left().w()));
- }
- // _
- // |
- if self.bottom_left().any("|]") {
- elm.push(fragments::line(y, &left().w()));
- }
- // _
- // |
- if self.bottom_right().any("|[") {
- elm.push(fragments::line(u, &right().w()));
- }
- if enable_aggressive_underscore {
- // /_
- if self.left().is('/') {
- elm.push(fragments::line(y, &left().u()));
- }
- if self.right().is('\\') {
- // _\
- elm.push(fragments::line(u, &right().y()));
- }
- }
- } else if self.is('-') {
- // -| -/ -\ x- X-
- if self.right().any("|/\\xX<") {
- elm.push(fragments::line(k, &right().m()));
- }
- // |- /- /- x- X-
- if self.left().any("|/\\xX>") {
- elm.push(fragments::line(o, &left().m()));
- }
- // -O the O has radius of 3 units, so this line
- // must only run from k to n only
- if self.right().is('O') {
- elm.push(fragments::line(k, n));
- }
- // O-
- if self.left().is('O') {
- elm.push(fragments::line(o, l));
- }
- // circuit jump
- // |
- // _.-._
- // |
- if self.top().can_strongly_connect(&W) && self.bottom().can_strongly_connect(&C)
- && self.left().is('.') && self.in_left(2).is('_')
- && self.right().is('.') && self.in_right(2).is('_')
- {
- elm.extend(vec![
- line(&left().u(), &left().w()),
- arc(&right().w(), &left().w(), 5),
- line(&right().w(), &right().y()),
- line(c, w),
- ]);
- consumed.extend(vec![left(), right()]);
- }
- }
- // 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)]);
- }
- // |
- // -~-
- // |
- 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![
- line(&left().k(), &left().m()),
- arc(&right().m(), &left().m(), 5),
- line(&right().o(), &right().m()),
- line(c, &bottom().w()),
- ]);
- consumed.extend(vec![left(), right()]);
- }
- (elm, consumed)
- }
-}
diff --git a/svgbob/src/enhance_circles.rs b/svgbob/src/enhance_circles.rs
deleted file mode 100644
index 8427a88..0000000
--- a/svgbob/src/enhance_circles.rs
+++ /dev/null
@@ -1,531 +0,0 @@
-use fragments::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 patterns::FocusChar;
-use properties::Location;
-use properties::PointBlock;
-
-use fragments::Fragment;
-use fragments::{arc, line, open_circle};
-
-use fragments::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight};
-
-pub trait Round {
- fn round(&self) -> (Vec<Fragment>, Vec<Location>, bool);
-}
-
-impl<'g> Round for FocusChar<'g> {
- ///
- /// Enhance drawings by making circular shapes into circle
- /// element
- /// example:
- /// _ .-. .--.
- /// (_) ( ) ( )
- /// `-' `--'
- ///
- ///
- /// The circle is held by the element that is the center of the circle
- /// as oppused to arcs where the arcs
- /// are held by the element at its center along the arc points
- ///
- /// Arc and circles will be treated differently
- fn round(&self) -> (Vec<Fragment>, Vec<Location>, bool) {
- let _a = &PointBlock::block(A);
- let _b = &PointBlock::block(B);
- let _c = &PointBlock::block(C);
- let _d = &PointBlock::block(D);
- let _e = &PointBlock::block(E);
- let _f = &PointBlock::block(F);
- let _g = &PointBlock::block(G);
- let _h = &PointBlock::block(H);
- let _i = &PointBlock::block(I);
- let _j = &PointBlock::block(J);
- let _k = &PointBlock::block(K);
- let _l = &PointBlock::block(L);
- let m = &PointBlock::block(M);
- let _n = &PointBlock::block(N);
- let o = &PointBlock::block(O);
- let _p = &PointBlock::block(P);
- let _q = &PointBlock::block(Q);
- let _r = &PointBlock::block(R);
- let _s = &PointBlock::block(S);
- let _t = &PointBlock::block(T);
- let _u = &PointBlock::block(U);
- let _v = &PointBlock::block(V);
- let _w = &PointBlock::block(W);
- 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 go_top = |step| Location::jump(Top, step);
- let go_bottom = |step| Location::jump(Bottom, step);
- let go_left = |step| Location::jump(Left, step);
- let go_right = |step| Location::jump(Right, step);
- let _go_top_left = |step| Location::jump(TopLeft, step);
- let _go_top_right = |step| Location::jump(TopRight, step);
- let _go_bottom_left = |step| Location::jump(BottomLeft, step);
- let _go_bottom_right = |step| Location::jump(BottomRight, step);
-
- let mut elm = vec![];
- let mut consumed = vec![];
- // tells whether that element
- // containing the arc/circle is along
- // with it, if along then no
- // additional processing is needed for this element
- // if not along, then further enhancement
- // intended behaviors would have to take effect
- let mut along_arc = false;
-
- let mut matched_circle = false;
- let _enable_round_pill = true;
-
- // circle 0
- // _
- // (_)
- if self.is('_') && self.left().is('(') && self.right().is(')') && self.top().is('_') {
- elm.push(open_circle(m, 4));
- consumed.extend(vec![top(), left(), right()]);
- matched_circle = true;
- along_arc = true; // since the circle is too small
- // that the center and the bottom points of
- // the circle share the same element `_`
- }
-
- // circle 1
- // .-.
- // ( + )
- // `-'
- if !matched_circle {
- let mut quadrants = vec![];
- let mut matched_quadrant2 = false;
- let mut matched_quadrant1 = false;
- let mut matched_quadrant3 = false;
- let mut matched_quadrant4 = false;
- let mut _matched_circle1 = false;
- // .-
- // ( +
- if self.top().is('-') && self.top().left().any(".,") && self.in_left(2).is('(') {
- quadrants.extend(vec![arc(&top().k(), &go_left(2).y(), 8)]);
- consumed.extend(vec![top_left(), go_left(2)]);
- matched_quadrant2 = true;
- }
- // -.
- // + )
- if self.top().is('-') && self.top().right().any(".,") && self.in_right(2).is(')') {
- quadrants.extend(vec![arc(&go_right(2).u(), &top().o(), 8)]);
- consumed.extend(vec![top_right(), go_right(2)]);
- matched_quadrant1 = true;
- }
-
- // ( +
- // `-
- if self.bottom().is('-') && self.bottom().left().any("`'") && self.in_left(2).is('(') {
- quadrants.extend(vec![arc(&go_left(2).e(), &bottom().k(), 8)]);
- consumed.extend(vec![bottom_left(), go_left(2)]);
- matched_quadrant3 = true;
- }
-
- // + )
- // -'
- if self.bottom().is('-') && self.bottom().right().any("`'") && self.in_right(2).is(')')
- {
- quadrants.extend(vec![arc(&bottom().o(), &go_right(2).a(), 8)]);
- consumed.extend(vec![bottom_right(), go_right(2)]);
- matched_quadrant4 = true;
- }
-
- // circle 1
- // .-.
- // ( + )
- // `-'
- if matched_quadrant1 && matched_quadrant2 && matched_quadrant3 && matched_quadrant4 {
- elm.push(open_circle(m, 8));
- consumed.extend(vec![
- top(),
- bottom(),
- go_left(2),
- go_right(2),
- top_left(),
- top_right(),
- bottom_left(),
- bottom_right(),
- ]);
- matched_circle = true;
- along_arc = false;
- } else {
- elm.extend(quadrants);
- }
- }
-
- // circle 2
- // .--.
- // ( + )
- // `--'
- if !matched_circle {
- let mut quadrants = vec![];
- let mut matched_quadrant1 = false;
- let mut matched_quadrant2 = false;
- let mut matched_quadrant3 = false;
- let mut matched_quadrant4 = false;
-
- // .-
- // ( +
- if self.top().is('-') && self.top().left().any(".,") && self.in_left(2).is('(') {
- quadrants.extend(vec![arc(&top().k(), &go_left(2).y(), 8)]);
- consumed.extend(vec![top_left(), go_left(2)]);
- matched_quadrant2 = true;
- }
-
- // ( +
- // `-
- if self.bottom().is('-') && self.bottom().left().any("`'") && self.in_left(2).is('(') {
- quadrants.extend(vec![arc(&go_left(2).e(), &bottom().k(), 8)]);
- consumed.extend(vec![bottom_left(), go_left(2)]);
- matched_quadrant3 = true;
- }
-
- // --.
- // + )
- if self.top().is('-') && self.top().right().is('-') && self.top().in_right(2).any(".,")
- && self.in_right(3).is(')')
- {
- quadrants.extend(vec![arc(&go_right(3).u(), &top().right().o(), 8)]);
- consumed.extend(vec![top().go_right(2), go_right(3)]);
- matched_quadrant1 = true;
- }
-
- // + )
- // --'
- if self.bottom().is('-') && self.bottom().right().is('-')
- && self.bottom().in_right(2).any("`'") && self.in_right(3).is(')')
- {
- quadrants.extend(vec![arc(&bottom().right().o(), &go_right(3).a(), 8)]);
- consumed.extend(vec![bottom().go_right(2), go_right(3)]);
- matched_quadrant4 = true;
- }
-
- // circle 2
- // .--.
- // ( + )
- // `--'
- if matched_quadrant1 && matched_quadrant2 && matched_quadrant3 && matched_quadrant4 {
- elm.push(open_circle(o, 10));
- matched_circle = true;
- along_arc = false;
-
- consumed.push(right()); // HACK:
- consumed.extend(vec![
- top(),
- top_left(),
- go_left(2),
- bottom_right(),
- bottom(),
- bottom_right(),
- bottom().go_right(2),
- go_right(3),
- top().go_right(2),
- top_right(),
- ]);
- } else {
- elm.extend(quadrants);
- }
- }
- ////////////////////////
- //
- // _
- // .' '.
- // ( 3 )
- // `._.'
- //
- /////////////////////////
- if !matched_circle {
- let mut quadrants = vec![];
- let mut matched_quadrant1 = false;
- let mut matched_quadrant2 = false;
- let mut matched_quadrant3 = false;
- let mut matched_quadrant4 = false;
- // _
- // .'|
- // (--+
- if self.in_top(2).is('_') && self.top().left().is('\'')
- && self.top().in_left(2).any(".,") && self.in_left(3).is('(')
- {
- quadrants.push(arc(&go_top(2).u(), &go_left(3).k(), 12));
-
- consumed.extend(vec![top().left(), top().go_left(2), go_left(3)]);
- matched_quadrant2 = true;
- }
- // _
- // |'.
- // +--)
- if self.in_top(2).is('_') && self.top().right().is('\'')
- && self.top().in_right(2).any(".,") && self.in_right(3).is(')')
- {
- quadrants.push(arc(&go_right(3).o(), &go_top(2).y(), 12));
-
- consumed.extend(vec![top().right(), top().go_right(2), go_right(3)]);
- matched_quadrant1 = true;
- }
- // (--+
- // `._
- //
- if self.in_left(3).is('(') && self.bottom().in_left(2).any("`'")
- && self.bottom().left().any(".,") && self.bottom().is('_')
- {
- quadrants.push(arc(&go_left(3).k(), &bottom().u(), 12));
- consumed.extend(vec![go_left(3), bottom().go_left(2), bottom().left()]);
- matched_quadrant3 = true;
- }
- // +--)
- // _.'
- if self.in_right(3).is(')') && self.bottom().in_left(2).any("`'")
- && self.bottom().left().any(".,")
- {
- quadrants.push(arc(&bottom().y(), &go_right(3).o(), 12));
- consumed.extend(vec![go_right(3), bottom().go_right(2), bottom().right()]);
- matched_quadrant4 = true;
- }
- if matched_quadrant1 && matched_quadrant2 && matched_quadrant3 && matched_quadrant4 {
- elm.push(open_circle(m, 12));
- consumed.extend(vec![go_top(2), bottom()]);
- matched_circle = true;
- } else {
- elm.extend(quadrants);
- }
- }
-
- /////////////////////////////
- // top left arc of circle 4
- // _.-
- // .' |
- // (----+
- //
- /////////////////////////////
- if !matched_circle {
- // if 4 of them match then consume all, and make a full circle
- let mut quadrants = vec![]; //temp storage for the arcs, replace with circle when all quadrants matched
- let mut matched_quadrant2 = false;
- let mut matched_quadrant1 = false;
- let mut matched_quadrant3 = false;
- let mut matched_quadrant4 = false;
- if self.in_left(5).is('(') && self.in_left(4).top().is('.')
- && self.in_left(3).top().is('\'')
- && self.in_left(2).in_top(2).is('_') && self.left().in_top(2).is('.')
- && self.in_top(2).is('-')
- {
- quadrants.push(arc(&go_top(2).m(), &go_left(4).m(), 18));
- matched_quadrant2 = true;
- consumed.extend(vec![
- go_left(5),
- go_left(4).top(),
- go_left(3).top(),
- go_left(2).go_top(2),
- left().go_top(2),
- go_top(2),
- ]);
- along_arc = false;
- }
- ///////////////////////////////
- // top right arc of the circle4
- // -._
- // | `.
- // +----)
- //////////////////////////////
- if self.in_right(5).is(')') && self.in_right(4).top().is('.')
- && self.in_right(3).top().any("`'")
- && self.in_right(2).in_top(2).is('_')
- && self.right().in_top(2).is('.') && self.in_top(2).is('-')
- {
- quadrants.push(arc(&go_right(4).m(), &go_top(2).m(), 18));
- matched_quadrant1 = true;
- consumed.extend(vec![
- go_right(5),
- go_right(4).top(),
- go_right(3).top(),
- go_right(2).go_top(2),
- right().go_top(2),
- go_top(2),
- ]);
- along_arc = false;
- }
- ////////////////////////////////
- // bottom_left arc of the circle4
- //
- // (----+
- // `._ |
- // `-
- ////////////////////////////////
- if self.in_left(5).is('(') && self.in_left(4).bottom().any("`'")
- && self.in_left(3).bottom().is('.')
- && self.in_left(2).bottom().is('_')
- && self.left().in_bottom(2).any("`'") && self.in_bottom(2).is('-')
- {
- quadrants.push(arc(&go_left(4).m(), &go_bottom(2).m(), 18));
- matched_quadrant3 = true;
- consumed.extend(vec![
- go_left(5),
- go_left(4).bottom(),
- go_left(3).bottom(),
- go_left(2).bottom(),
- left().go_bottom(2),
- go_bottom(2),
- ]);
- along_arc = false;
- }
- ///////////////////////////////////
- // bottom_right arc of the circle4
- // +----)
- // | _,'
- // -'
- //
- ////////////////////////////////////
- if self.in_right(5).is(')') && self.in_right(4).bottom().is('\'')
- && self.in_right(3).bottom().is(',')
- && self.in_right(2).bottom().is('_')
- && self.right().in_bottom(2).is('\'') && self.in_bottom(2).is('-')
- {
- quadrants.push(arc(&go_bottom(2).m(), &go_right(4).m(), 18));
- matched_quadrant4 = true;
- consumed.extend(vec![
- go_right(5),
- go_right(4).bottom(),
- go_right(3).bottom(),
- go_right(2).bottom(),
- right().go_bottom(2),
- go_bottom(2),
- ]);
- along_arc = false;
- }
- if matched_quadrant2 && matched_quadrant1 && matched_quadrant3 && matched_quadrant4 {
- elm.push(open_circle(m, 18));
- matched_circle = true;
- along_arc = false;
- } else {
- elm.extend(quadrants);
- }
- }
-
- ////////////////////////////////
- //
- // Circle 6
- //
- //////////////////////////////////
- if !matched_circle {
- let mut quadrants = vec![]; //temp storage for the arcs, replace with circle when all quadrants matched
- let mut matched_quadrant2 = false;
- let mut matched_quadrant1 = false;
- let mut matched_quadrant3 = false;
- let mut matched_quadrant4 = false;
- // _ _
- // ,'| .'|
- // / | / |
- // |---+ |---+
- if self.in_top(3).is('_') && self.in_top(2).left().any("`'")
- && self.in_top(2).in_left(2).any(".,")
- && self.top().in_left(3).is('/') && self.in_left(4).is('|')
- {
- quadrants.extend(vec![
- arc(&go_top(3).u(), &go_left(4).c(), 20),
- line(&go_left(4).c(), &go_left(4).w()),
- ]);
-
- consumed.extend(vec![
- go_top(2).left(),
- go_top(2).go_left(2),
- top().go_left(3),
- go_left(4),
- ]);
- along_arc = false;
- matched_quadrant2 = true;
- }
- // _
- // |`.
- // | \
- // +---|
- if self.in_top(3).is('_') && self.in_top(2).right().any("`'")
- && self.in_top(2).in_right(2).any(".,")
- && self.top().in_right(3).is('\\') && self.in_right(4).is('|')
- {
- quadrants.extend(vec![
- arc(&go_right(4).m(), &go_top(3).y(), 20),
- line(&go_right(4).c(), &go_right(4).w()),
- ]);
- consumed.extend(vec![
- go_top(2).right(),
- go_top(2).go_right(2),
- top().go_right(3),
- go_right(4),
- ]);
- along_arc = false;
- matched_quadrant1 = true;
- }
-
- ////////////////////////////////
- //
- // |---+
- // \ |
- // `._
- //
- ///////////////////////////////
- if self.in_left(4).is('|') && self.bottom().in_left(3).is('\\')
- && self.in_bottom(2).in_left(2).any("`'")
- && self.in_bottom(2).in_left(1).any(".,")
- && self.in_bottom(2).is('_')
- {
- quadrants.extend(vec![
- arc(&go_left(4).m(), &go_bottom(2).u(), 20),
- line(&go_left(4).m(), &go_left(4).c()),
- ]);
-
- consumed.extend(vec![
- go_left(4),
- bottom().go_left(3),
- go_bottom(2).go_left(2),
- go_bottom(2).go_left(1),
- ]);
- along_arc = false;
- matched_quadrant3 = true;
- }
- /////////////////////////////////
- //
- // +---| +---|
- // | / | /
- // _.' _,'
- //
- ////////////////////////////////
- if self.in_right(4).is('|') && self.bottom().in_right(3).is('/')
- && self.in_bottom(2).in_right(2).any("`'")
- && self.in_bottom(2).right().any(".,") && self.in_bottom(2).is('_')
- {
- quadrants.extend(vec![
- arc(&go_bottom(2).y(), &go_right(4).w(), 20),
- line(&go_right(4).w(), &go_right(4).c()),
- ]);
- consumed.extend(vec![
- go_right(4),
- bottom().go_right(3),
- go_bottom(2).go_right(2),
- go_bottom(2).right(),
- ]);
- along_arc = false;
- matched_quadrant4 = true;
- }
- if matched_quadrant2 && matched_quadrant1 && matched_quadrant3 && matched_quadrant4 {
- elm.push(open_circle(m, 24));
- matched_circle = true;
- println!("matched circle: {}", matched_circle);
- along_arc = false;
- } else {
- elm.extend(quadrants);
- }
- }
-
- (elm, consumed, along_arc)
- }
-}
diff --git a/svgbob/src/lib.rs b/svgbob/src/lib.rs
index 6b8f597..2a332e0 100644
--- a/svgbob/src/lib.rs
+++ b/svgbob/src/lib.rs
@@ -68,8 +68,6 @@ mod optimizer;
mod patterns;
mod box_drawing;
-mod enhance;
-mod enhance_circles;
mod fragments;
mod properties;
@@ -217,6 +215,8 @@ pub enum Feature {
Circle, //start
}
+
+
#[derive(Debug, PartialOrd, PartialEq, Clone)]
pub struct Point {
x: f32,
@@ -376,6 +376,17 @@ pub enum Element {
Path(Point, Point, String, Stroke),
}
+impl Ord for Element{
+ fn cmp(&self, other: &Self) -> Ordering{
+ if let Some(order) = self.partial_cmp(&other){
+ return order
+ }
+ Ordering::Less
+ }
+}
+impl Eq for Element{
+}
+
pub fn line(a: &Point, b: &Point) -> Element {
Element::Line(a.clone(), b.clone(), Solid, vec![])
}
@@ -429,16 +440,17 @@ impl Element {
if collinear(s, e, s2)
&& collinear(s, e, e2)
&& stroke == stroke2{
+
// line1 line2
// s-----e s2-----e2
// s----------------e2
if e == s2 {
// -----
// o----
- let cond1 = feature.is_empty() || feature.contains(&Circle);
+ let cond1 = feature.is_empty() || (feature.contains(&Circle) && feature.len() == 1);
// ------
// ------>
- let cond2 = feature2.is_empty() || feature2.contains(&Arrow) ;
+ let cond2 = feature2.is_empty() || (feature2.contains(&Arrow) && feature2.len() ==1);
if cond1 && cond2{
return Some(Element::Line(
s.clone(),
@@ -451,10 +463,10 @@ impl Element {
// line1 line2
// s------e e2-------s2
// s-------------------s2
- if e == e2{
+ else if e == e2{
// ------- --------
// o------ ---------
- if (feature.is_empty() || feature.contains(&Circle) )
+ if (feature.is_empty() || (feature.contains(&Circle) && feature.len() == 1))
&& feature2.is_empty(){
return Some(Element::Line(
s.clone(),
@@ -467,11 +479,11 @@ impl Element {
// line1 line2
// e------s s2------e2
// s------------------e2
- if s == s2{
+ else if s == s2{
// ------- -------
// ------- ------->
if feature.is_empty()
- && (feature2.is_empty() || feature2.contains(&Arrow)){
+ && (feature2.is_empty() || (feature2.contains(&Arrow) && feature2.len() ==1 )){
return Some(Element::Line(
e.clone(),
e2.clone(),
@@ -484,13 +496,13 @@ impl Element {
// e------s e2------s2
// e---------------------s2
//
- if s == e2{
+ else if s == e2{
// ----- -----
// ----- ----o
// <---- -----
// <---- ----o
-