summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2018-08-02 02:58:11 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2018-08-02 02:58:11 +0800
commit09bf3a78c05da6f06f5b4f8c8d58fce508eeb651 (patch)
treeac7df683b60fdec5f71bb2770a00876849c9eea6
parent1cfc2804d95eebac927b0ea7a14a15c7ccbb3bf1 (diff)
enhance doesn't need to check if the character has characteristic or not
-rw-r--r--svgbob/src/enhance.rs74
-rw-r--r--svgbob/src/focus_char.rs50
-rw-r--r--svgbob/src/loc.rs14
3 files changed, 90 insertions, 48 deletions
diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs
index 027fc34..75331e9 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, dashed_line};
+use fragments::{self, line, arc, open_circle, arrow_line, dashed_line};
pub trait Enhance {
fn enhance(&self) -> (Vec<Fragment>, Vec<Location>);
@@ -26,7 +26,7 @@ impl<'g> Enhance for FocusChar<'g> {
let _j = &PointBlock::block(J);
let k = &PointBlock::block(K);
let l = &PointBlock::block(L);
- let _m = &PointBlock::block(M);
+ let m = &PointBlock::block(M);
let n = &PointBlock::block(N);
let o = &PointBlock::block(O);
let _p = &PointBlock::block(P);
@@ -49,6 +49,8 @@ impl<'g> Enhance for FocusChar<'g> {
let top_right = || Location::go(TopRight);
let bottom_left = || Location::go(BottomLeft);
let bottom_right = || Location::go(BottomRight);
+ let left2 = || Location::jump(Left,2);
+ let right2 = || Location::jump(Right,2);
// _ underscore
if self.is('_') {
@@ -61,7 +63,7 @@ impl<'g> Enhance for FocusChar<'g> {
elm.push(line(y, &left().w()));
}
}
- else if self.any("`'") {
+ if self.any("`'") {
// for circuitries
// + + \
// `> '> `>
@@ -109,7 +111,8 @@ impl<'g> Enhance for FocusChar<'g> {
consumed.push(right());
consumed.push(this());
}
- } else if self.any(".,") {
+ }
+ if self.any(".,") {
// for circuitries
// <. <,
// + \
@@ -134,7 +137,7 @@ impl<'g> Enhance for FocusChar<'g> {
}
}
// transistor complimentary enhancement
- else if self.is('|') {
+ if self.is('|') {
// | |
// < >
if self.bottom().any("><") {
@@ -159,7 +162,8 @@ impl<'g> Enhance for FocusChar<'g> {
elm.extend(vec![line(c,w),line(a,c)]);
consumed.push(this());
}
- } else if self.is('/') {
+ }
+ if self.is('/') {
// >
// /
if self.top_right().is('>') {
@@ -172,7 +176,8 @@ impl<'g> Enhance for FocusChar<'g> {
elm.push(line(e, &bottom_left().m()));
consumed.push(this());
}
- } else if self.is('\\') {
+ }
+ if self.is('\\') {
// \
// >
if self.bottom_right().is('>') {
@@ -191,7 +196,7 @@ impl<'g> Enhance for FocusChar<'g> {
// -(-
// |
//
- else if self.is('(') && self.top().can_strongly_connect(&W)
+ 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)
@@ -204,7 +209,7 @@ impl<'g> Enhance for FocusChar<'g> {
// -)-
// |
//
- else if self.is(')') && self.top().can_strongly_connect(&W)
+ 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)
@@ -212,6 +217,57 @@ impl<'g> Enhance for FocusChar<'g> {
elm.extend(vec![arc(w, c, 5), line(k, o)]);
consumed.push(this());
}
+ // circle1
+ // _
+ // (_)
+ //
+ if self.is('_')
+ && self.left().is('(') && self.right().is(')')
+ && self.top().is('_'){
+ elm.push(open_circle(m, 4));
+ consumed.extend(vec![this(), left(), right(),top()]);
+ }
+
+ // circle2
+ // .-.
+ // ( + )
+ // '-'
+ if self.in_left(2).is('(')
+ && self.in_right(2).is(')')
+ && self.top().is('-')
+ && self.bottom().is('-')
+ && self.bottom_left().any("`'")
+ && self.bottom_right().is('\'')
+ && self.top_left().any(".,")
+ && self.top_right().is('.'){
+ println!("circle2 matched");
+
+ elm.push(open_circle(m,6));
+ consumed.extend(vec![left2(), right2(), top(), bottom(),
+ bottom_left(), bottom_right(), top_left(), top_right()]);
+ }
+ // .--.
+ // ( + )
+ // `--'
+ //
+ // _
+ // .' '.
+ // ( 3 )
+ // `._.'
+ // ___
+ // ,' `.
+ // / \
+ // | |
+ // \ /
+ // `.___,'
+ //
+ // ______
+ // ,' `.
+ // / \
+ // | |
+ // | |
+ // \ /
+ // `.______,'
(elm, consumed)
}
diff --git a/svgbob/src/focus_char.rs b/svgbob/src/focus_char.rs
index 46b1b25..a16563e 100644
--- a/svgbob/src/focus_char.rs
+++ b/svgbob/src/focus_char.rs
@@ -279,23 +279,11 @@ impl<'g> FocusChar<'g> {
}
fn get_enhance_fragments(&self) -> (Vec<Fragment>, Vec<Location>) {
- let character: Option<Characteristic> = self.ch.get_characteristic();
let mut elm: Vec<Fragment> = vec![];
let mut consumed: Vec<Location> = vec![];
-
- let mut matched_intended = false;
- let mut matched_enhance = false;
-
-
- if let Some(character) = character {
- let (enhanced, enhance_consumed) = self.enhance();
- if !enhanced.is_empty() && !self.used_as_text() {
- elm.extend(enhanced);
- let has_consumed = enhance_consumed.len() > 0;
- consumed.extend(enhance_consumed);
- matched_enhance = true;
- }
- }
+ let (enhanced, enhance_consumed) = self.enhance();
+ elm.extend(enhanced);
+ consumed.extend(enhance_consumed);
elm.sort();
elm.dedup();
consumed.sort();
@@ -369,34 +357,18 @@ impl<'g> FocusChar<'g> {
self.get(&self.loc.left())
}
- pub fn in_left(&self, n: usize) -> Self {
- let mut fc = self.left();
- for _i in 0..n - 1 {
- fc = fc.left();
- }
- fc
+ pub fn in_left(&self, n: i32) -> Self {
+ self.get(&self.loc.in_left(n))
}
- pub fn in_right(&self, n: usize) -> Self {
- let mut fc = self.right();
- for _i in 0..n - 1 {
- fc = fc.right();
- }
- fc
+ pub fn in_right(&self, n: i32) -> Self {
+ self.get(&self.loc.in_right(n))
}
- pub fn in_top(&self, n: usize) -> Self {
- let mut fc = self.top();
- for _i in 0..n - 1 {
- fc = fc.top();
- }
- fc
+ pub fn in_top(&self, n: i32) -> Self {
+ self.get(&self.loc.in_top(n))
}
- pub fn in_bottom(&self, n: usize) -> Self {
- let mut fc = self.bottom();
- for _i in 0..n - 1 {
- fc = fc.bottom();
- }
- fc
+ pub fn in_bottom(&self, n: i32) -> Self {
+ self.get(&self.loc.in_bottom(n))
}
pub fn right(&self) -> Self {
diff --git a/svgbob/src/loc.rs b/svgbob/src/loc.rs
index fa83d11..27f88e6 100644
--- a/svgbob/src/loc.rs
+++ b/svgbob/src/loc.rs
@@ -4,6 +4,7 @@ use location::Direction::{Top,Bottom,Left,Right,TopLeft,TopRight,BottomLeft,Bott
/// Location of Block relative to the Grid
/// This the equivalent to the cell cation in the grid
+/// 0,0 is the top left most
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq)]
pub struct Loc {
pub x: i32,
@@ -65,6 +66,13 @@ impl Loc {
y: self.y - 1,
}
}
+ pub fn in_top(&self, n: i32) -> Loc {
+ Loc {
+ x: self.x,
+ y: self.y - n,
+ }
+ }
+
pub fn left(&self) -> Loc {
Loc {
x: self.x - 1,
@@ -83,6 +91,12 @@ impl Loc {
y: self.y + 1,
}
}
+ pub fn in_bottom(&self, n: i32) -> Loc {
+ Loc {
+ x: self.x,
+ y: self.y + n,
+ }
+ }
pub fn right(&self) -> Loc {
Loc {
x: self.x + 1,