From bb99d8ec8bb537a6de395598724239041afe2db7 Mon Sep 17 00:00:00 2001 From: Jovansonlee Cesar Date: Wed, 8 Aug 2018 21:57:57 +0800 Subject: Add circles up to 24 radius disable reduction of elements in optimizer --- svgbob/src/enhance.rs | 31 ++++- svgbob/src/enhance_circle.rs | 283 +++++++++++++++++++++++++++++++++++++++++-- svgbob/src/optimizer.rs | 4 +- 3 files changed, 302 insertions(+), 16 deletions(-) diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs index ba41017..abb72e5 100644 --- a/svgbob/src/enhance.rs +++ b/svgbob/src/enhance.rs @@ -2,7 +2,7 @@ use focus_char::FocusChar; use fragments::Fragment; use location::Location; use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight}; -use block::Block::{A, C, E, J, K, M, O, S, U, W, Y}; +use block::Block::{A, C, E, F, J, K, M, O, P, S, U, W, Y}; use point_block::PointBlock; use fragments::{line, arc, arrow_line}; @@ -20,7 +20,7 @@ impl<'g> Enhance for FocusChar<'g> { let c = &PointBlock::block(C); //let _d = &PointBlock::block(D); let e = &PointBlock::block(E); - //let _f = &PointBlock::block(F); + let f = &PointBlock::block(F); //let _g = &PointBlock::block(G); //let _h = &PointBlock::block(H); //let _i = &PointBlock::block(I); @@ -30,7 +30,7 @@ impl<'g> Enhance for FocusChar<'g> { let m = &PointBlock::block(M); //let _n = &PointBlock::block(N); let o = &PointBlock::block(O); - //let _p = &PointBlock::block(P); + let p = &PointBlock::block(P); //let _q = &PointBlock::block(Q); //let _r = &PointBlock::block(R); let s = &PointBlock::block(S); @@ -52,6 +52,9 @@ impl<'g> Enhance for FocusChar<'g> { let bottom_right = || Location::go(BottomRight); let top_left2 = || top().go_left(2); + let top_right2 = || top().go_right(2); + let bottom_right2 = || bottom().go_right(2); + let bottom_left2 = || bottom().go_left(2); // _ underscore @@ -176,13 +179,33 @@ impl<'g> Enhance for FocusChar<'g> { } } - if self.any("vV◢"){ + if self.any("vV"){ // `. // V if self.top_left().is('.') && self.top().in_left(2).is('`'){ elm.push(arrow_line(&top_left2().c(), j)); consumed.push(this()) } + // .' + // V + if self.top_right().is('.') && self.top().in_right(2).is('\''){ + elm.push(arrow_line(&top_right2().c(), f)); + consumed.push(this()) + } + } + if self.is('^'){ + // ^ + // `. + if self.bottom_right().is('`') && self.bottom().in_right(2).is('.'){ + elm.push(arrow_line(&bottom_right2().t(), m)); + consumed.push(this()); + } + // ^ + // .' + if self.bottom_left().is('\'') && self.bottom().in_left(2).is('.') { + elm.push(arrow_line(&bottom_left2().p(), m)); + consumed.push(this()); + } } // circuitries jump // | diff --git a/svgbob/src/enhance_circle.rs b/svgbob/src/enhance_circle.rs index b1f8d40..140be02 100644 --- a/svgbob/src/enhance_circle.rs +++ b/svgbob/src/enhance_circle.rs @@ -3,7 +3,7 @@ use focus_char::FocusChar; use fragments::Fragment; use location::Location; use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight}; -use block::Block::{K, M, O}; +use block::Block::{K, M, O, W, Y}; use point_block::PointBlock; use fragments::open_circle; @@ -39,9 +39,9 @@ impl<'g> EnhanceCircle for FocusChar<'g> { //let _t = &PointBlock::block(T); //let u = &PointBlock::block(U); //let _v = &PointBlock::block(V); - //let w = &PointBlock::block(W); + let w = &PointBlock::block(W); //let _x = &PointBlock::block(X); - //let y = &PointBlock::block(Y); + let y = &PointBlock::block(Y); let this = || Location::this(); let top = || Location::go(Top); @@ -54,7 +54,27 @@ impl<'g> EnhanceCircle for FocusChar<'g> { let bottom_right = || Location::go(BottomRight); let top2 = || Location::jump(Top,2); - //let bottom2 = || Location::jump(Bottom,2); + let top2_right = || Location::jump(Top,2).right(); + let top2_right2 = || Location::jump(Top,2).go_right(2); + let top2_right3 = || Location::jump(Top,2).go_right(3); + let top2_right4 = || Location::jump(Top,2).go_right(4); + let top2_right5 = || Location::jump(Top,2).go_right(5); + let top2_left = || Location::jump(Top,2).left(); + let top2_left2 = || Location::jump(Top,2).go_left(2); + let top2_left3 = || Location::jump(Top,2).go_left(3); + let top2_left4 = || Location::jump(Top,2).go_left(4); + let bottom2 = || Location::jump(Bottom,2); + let bottom2_left = || Location::jump(Bottom,2).left(); + let bottom2_left2 = || Location::jump(Bottom,2).go_left(2); + let bottom2_left3 = || Location::jump(Bottom,2).go_left(3); + let bottom2_left4 = || Location::jump(Bottom,2).go_left(4); + let bottom2_left5 = || Location::jump(Bottom,2).go_left(5); + let bottom2_right = || Location::jump(Bottom, 2).right(); + let bottom2_right2 = || Location::jump(Bottom, 2).go_right(2); + let bottom2_right3 = || Location::jump(Bottom, 2).go_right(3); + let bottom2_right4 = || Location::jump(Bottom, 2).go_right(4); + let bottom2_right5 = || Location::jump(Bottom, 2).go_right(5); + let bottom2_right6 = || Location::jump(Bottom, 2).go_right(6); let left2 = || Location::jump(Left,2); let right2 = || Location::jump(Right,2); let top_right2 = || top().go_right(2); @@ -62,14 +82,66 @@ impl<'g> EnhanceCircle for FocusChar<'g> { let bottom_right2 = || bottom().go_right(2); let bottom_left2 = || bottom().go_left(2); - //let top3 = || Location::jump(Top,3); - //let bottom3 = || Location::jump(Bottom,3); + let top3 = || Location::jump(Top,3); + let top3_left = || Location::jump(Top,3).left(); + let top3_left2 = || Location::jump(Top,3).go_left(2); + let top3_right = || Location::jump(Top,3).right(); + let top3_right2 = || Location::jump(Top,3).go_right(2); + let top3_right3 = || Location::jump(Top,3).go_right(3); + let bottom3 = || Location::jump(Bottom,3); + let bottom3_right = || Location::jump(Bottom, 3).right(); + let bottom3_right2 = || Location::jump(Bottom,3).go_right(2); + let bottom3_right3 = || Location::jump(Bottom,3).go_right(3); + let bottom3_right4 = || Location::jump(Bottom,3).go_right(4); + let bottom3_right5 = || Location::jump(Bottom,3).go_right(5); + let bottom3_left = || Location::jump(Bottom, 3).left(); + let bottom3_left2 = || Location::jump(Bottom,3).go_left(2); + let bottom3_left3 = || Location::jump(Bottom,3).go_left(3); + let bottom3_left4 = || Location::jump(Bottom,3).go_left(4); + let bottom3_left5 = || Location::jump(Bottom,3).go_left(5); let left3 = || Location::jump(Left,3); let right3 = || Location::jump(Right,3); - //let top_right3 = || top().go_right(3); - //let top_left3 = || top().go_left(3); - //let bottom_right3 = || bottom().go_right(3); - //let bottom_left3 = || bottom().go_left(3); + let top_right3 = || top().go_right(3); + let top_left3 = || top().go_left(3); + let bottom_right3 = || bottom().go_right(3); + let bottom_left3 = || bottom().go_left(3); + + let top4 = || Location::jump(Top,4); + let bottom4 = || Location::jump(Bottom,4); + let left4 = || Location::jump(Left,4); + let right4 = || Location::jump(Right,4); + let top_right4 = || top().go_right(4); + let top_left4 = || top().go_left(4); + let bottom_right4 = || bottom().go_right(4); + let bottom_left4 = || bottom().go_left(4); + + let top5 = || Location::jump(Top,5); + let bottom5 = || Location::jump(Bottom,5); + let left5 = || Location::jump(Left,5); + let right5 = || Location::jump(Right,5); + let top_right5 = || top().go_right(5); + let top_left5 = || top().go_left(5); + let bottom_right5 = || bottom().go_right(5); + let bottom_left5 = || bottom().go_left(5); + + let top6 = || Location::jump(Top,6); + let bottom6 = || Location::jump(Bottom,6); + let left6 = || Location::jump(Left,6); + let right6 = || Location::jump(Right,6); + let top_right6 = || top().go_right(6); + let top_left6 = || top().go_left(6); + let bottom_right6 = || bottom().go_right(6); + let bottom_left6 = || bottom().go_left(6); + + let top7 = || Location::jump(Top,7); + let bottom7 = || Location::jump(Bottom,7); + let left7 = || Location::jump(Left,7); + let right7 = || Location::jump(Right,7); + let top_right7 = || top().go_right(7); + let top_left7 = || top().go_left(7); + let bottom_right7 = || bottom().go_right(7); + let bottom_left7 = || bottom().go_left(7); + // circle 4 // _ @@ -159,18 +231,98 @@ impl<'g> EnhanceCircle for FocusChar<'g> { // ( + ) 14 // `.__,' // + if self.in_left(3).is('(') + && self.in_right(4).is(')') + && self.in_top(2).is('_') + && self.in_top(2).right().is('_') + && self.bottom().is('_') + && self.bottom_right().is('_') + && self.top().in_left(2).is(',') + && self.top_left().is('\'') + && self.top().in_right(2).is('`') + && self.top().in_right(3).is('.') + && self.bottom().in_left(2).is('`') + && self.bottom_left().is('.') + && self.bottom().in_right(2).is(',') + && self.bottom().in_right(3).is('\''){ + + elm.push(open_circle(o, 14)); + consumed.extend(vec![ + left3(), right4(), top2(), top2_right(), bottom(), bottom_right(), + top_left2(), top_left(), top_right2(), top_right3(), bottom_left2(), + bottom_left(), bottom_right2(), bottom_right3() + ]); + } // ___ // ,' `. // / + \ 16 // \ / // `.___,' // + if self.in_left(4).is('/') + && self.top().in_left(3).is(',') + && self.top().in_left(2).is('\'') + && self.in_top(2).left().is('_') + && self.in_top(2).is('_') + && self.in_top(2).right().is('_') + && self.top().in_right(2).is('`') + && self.top().in_right(3).is('.') + && self.in_right(4).is('\\') + && self.bottom().in_right(4).is('/') + && self.in_bottom(2).in_right(3).is('\'') + && self.in_bottom(2).in_right(2).is(',') + && self.in_bottom(2).right().is('_') + && self.in_bottom(2).is('_') + && self.in_bottom(2).left().is('_') + && self.in_bottom(2).in_left(2).is('.') + && self.in_bottom(2).in_left(3).is('`') + && self.bottom().in_left(4).is('\\'){ + + elm.push(open_circle(w,16)); + consumed.extend(vec![ + left4(), top_left3(), top_left2(), top2_left(), top2(), + top2_right(), top_right2(), top_right3(), + right4(), bottom_right4(), bottom2_right3(), + bottom2_right2(), bottom2_right(), bottom2(), + bottom2_left(), bottom2_left2(), bottom2_left3(), + bottom_left4() + ]); + } // ____ // ,' `. // / + \ 18 // \ / // `.____,' // + if self.in_left(4).is('/') + && self.top().in_left(3).any(".,") + && self.top().in_left(2).is('\'') + && self.in_top(2).left().is('_') + && self.in_top(2).is('_') + && self.in_top(2).right().is('_') + && self.in_top(2).in_right(2).is('_') + && self.top().in_right(3).is('`') + && self.top().in_right(4).is('.') + && self.in_right(5).is('\\') + && self.bottom().in_right(5).is('/') + && self.in_bottom(2).in_right(4).is('\'') + && self.in_bottom(2).in_right(3).any(".,") + && self.in_bottom(2).in_right(2).is('_') + && self.in_bottom(2).right().is('_') + && self.in_bottom(2).is('_') + && self.in_bottom(2).left().is('_') + && self.in_bottom(2).in_left(2).is('.') + && self.in_bottom(2).in_left(3).is('`') + && self.bottom().in_left(4).is('\\') { + elm.push(open_circle(y, 18)); + consumed.extend(vec![ + left4(), top_left3(), top_left2(), top2_left(), top2(), + top2_right(), top2_right2(), top_right3(), top_right4(), + right5(), bottom_right5(), bottom2_right4(), bottom2_right3(), + bottom2_right2(), bottom2_right(), bottom2(), bottom2_left(), + bottom2_left2(), bottom2_left3(), bottom_left4() + ]); + } // ____ // ,' `. // / \ @@ -178,6 +330,39 @@ impl<'g> EnhanceCircle for FocusChar<'g> { // \ / // `.____,' // + if self.in_left(5).is('(') + && self.top().in_left(4).is('/') + && self.in_top(2).in_left(3).any(",.") + && self.in_top(2).in_left(2).is('\'') + && self.in_top(3).left().is('_') + && self.in_top(3).is('_') + && self.in_top(3).right().is('_') + && self.in_top(3).in_right(2).is('_') + && self.in_top(2).in_right(3).is('`') + && self.in_top(2).in_right(4).is('.') + && self.top().in_right(5).is('\\') + && self.in_right(6).is(')') + && self.bottom().in_right(5).is('/') + && self.in_bottom(2).in_right(4).is('\'') + && self.in_bottom(2).in_right(3).any(",.") + && self.in_bottom(2).in_right(2).is('_') + && self.in_bottom(2).right().is('_') + && self.in_bottom(2).is('_') + && self.in_bottom(2).left().is('_') + && self.in_bottom(2).in_left(2).is('.') + && self.in_bottom(2).in_left(3).any("`'") + && self.bottom().in_left(4).is('\\'){ + elm.push(open_circle(o, 20)); + consumed.extend(vec![ + left5(), top_left4(), top2_left3(), top2_left2(), + top3_left(), top3(), top3_right(), top3_right2(), + top2_right3(), top2_right4(), top_right5(), + right6(), bottom_right5(), bottom2_right4(), + bottom2_right3(), bottom2_right2(), bottom2_right(), + bottom2(), bottom2_left(), bottom2_left2(), + bottom2_left3(), bottom_left4(), + ]); + } // // _____ // ,' `. @@ -186,6 +371,42 @@ impl<'g> EnhanceCircle for FocusChar<'g> { // \ / // `._____,' // + if self.in_left(6).is('(') + && self.top().in_left(5).is('/') + && self.in_top(2).in_left(4).any(",.") + && self.in_top(2).in_left(3).is('\'') + && self.in_top(3).in_left(2).is('_') + && self.in_top(3).left().is('_') + && self.in_top(3).is('_') + && self.in_top(3).right().is('_') + && self.in_top(3).in_right(2).is('_') + && self.in_top(2).in_right(3).is('`') + && self.in_top(2).in_right(4).is('.') + && self.top().in_right(5).is('\\') + && self.in_right(6).is(')') + && self.bottom().in_right(5).is('/') + && self.in_bottom(2).in_right(4).is('\'') + && self.in_bottom(2).in_right(3).any(".,") + && self.in_bottom(2).in_right(2).is('_') + && self.in_bottom(2).right().is('_') + && self.in_bottom(2).is('_') + && self.in_bottom(2).left().is('_') + && self.in_bottom(2).in_left(2).is('_') + && self.in_bottom(2).in_left(3).is('.') + && self.in_bottom(2).in_left(4).is('`') + && self.bottom().in_left(5).is('\\') { + + elm.push(open_circle(m, 22)); + consumed.extend(vec![ + left6(), top_left5(), top2_left4(), top2_left3(), + top2_left2(), top3_left2(), top3_left(), top3(), + top3_right(), top3_right2(), top2_right3(), top2_right4(), + top_right5(), right6(), bottom_right5(), + bottom2_right4(), bottom2_right3(), bottom2_right2(), bottom2_right(), + bottom2(), bottom2_left(), bottom2_left2(), bottom2_left3(), + bottom2_left4(), bottom_left5() + ]); + } // // ______ // ,' `. @@ -195,6 +416,48 @@ impl<'g> EnhanceCircle for FocusChar<'g> { // \ / // `.______,' // + if self.in_left(6).is('|') + && self.top().in_left(5).is('/') + && self.in_top(2).in_left(4).any(".,") + && self.in_top(2).in_left(3).is('\'') + && self.in_top(3).in_left(2).is('_') + && self.in_top(3).left().is('_') + && self.in_top(3).is('_') + && self.in_top(3).right().is('_') + && self.in_top(3).in_right(2).is('_') + && self.in_top(3).in_right(3).is('_') + && self.in_top(2).in_right(4).is('`') + && self.in_top(2).in_right(5).is('.') + && self.top().in_right(6).is('\\') + && self.in_right(7).is('|') + && self.bottom().in_right(7).is('|') + && self.in_bottom(2).in_right(6).is('/') + && self.in_bottom(3).in_right(5).is('\'') + && self.in_bottom(3).in_right(4).any(".,") + && self.in_bottom(3).in_right(3).is('_') + && self.in_bottom(3).in_right(2).is('_') + && self.in_bottom(3).right().is('_') + && self.in_bottom(3).is('_') + && self.in_bottom(3).left().is('_') + && self.in_bottom(3).in_left(2).is('_') + && self.in_bottom(3).in_left(3).is('.') + && self.in_bottom(3).in_left(4).is('`') + && self.in_bottom(2).in_left(5).is('\\') + && self.bottom().in_left(6).is('|') + { + elm.push(open_circle(y,24)); + consumed.extend(vec![ + left6(), top_left5(), top2_left4(), top2_left3(), + top3_left2(), top3_left(), top3(), + top3_right(), top3_right2(), top3_right3(), + top2_right4(), top2_right5(), top_right6(), + right7(), bottom_right7(), + bottom2_right6(), bottom3_right5(), bottom3_right4(), + bottom3_right3(), bottom3_right2(), bottom3_right(), + bottom3(), bottom3_left(), bottom3_left2(), bottom3_left3(), + bottom3_left4(), bottom2_left5(), bottom_left6() + ]); + } (elm, consumed) } } diff --git a/svgbob/src/optimizer.rs b/svgbob/src/optimizer.rs index 6c9aeb7..326f26a 100644 --- a/svgbob/src/optimizer.rs +++ b/svgbob/src/optimizer.rs @@ -153,8 +153,8 @@ impl Optimizer { for (y, line) in self.elements.iter().enumerate() { for (x, cell) in line.iter().enumerate() { let loc = &Loc::new(x as i32, y as i32); - let reduced = self.reduce_cell_elements(&cell); - for (elm_index, elm) in reduced.iter().enumerate() { + //let reduced = self.reduce_cell_elements(&cell); + for (elm_index, elm) in cell.iter().enumerate() { if !tracing_consumed_locs.contains(&(loc.clone(),elm_index)){ let (traced, consumed) = self.trace_elements(elm, loc); optimized.extend(traced); -- cgit v1.2.3