diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2020-02-13 22:55:01 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2020-02-13 22:55:01 +0800 |
commit | 867f96ab4effc49ea428274163f177d0fc73f782 (patch) | |
tree | 5a7011d362eb27359906b52fb293df1dba1c488e | |
parent | 3fd28a3f5b40af7204e9609223fc41b6e3ae1cad (diff) |
Add more connection to flexible character behavior: *,0,Xo
-rw-r--r-- | svgbob/src/buffer/cell_buffer.rs | 2 | ||||
-rw-r--r-- | svgbob/src/buffer/cell_buffer/settings.rs | 3 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment.rs | 22 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment/circle.rs | 17 | ||||
-rw-r--r-- | svgbob/src/map/ascii_map.rs | 137 | ||||
-rw-r--r-- | svgbob/test_data/demo.bob | 26 |
6 files changed, 187 insertions, 20 deletions
diff --git a/svgbob/src/buffer/cell_buffer.rs b/svgbob/src/buffer/cell_buffer.rs index aa20104..c2f9239 100644 --- a/svgbob/src/buffer/cell_buffer.rs +++ b/svgbob/src/buffer/cell_buffer.rs @@ -229,7 +229,7 @@ impl CellBuffer { fill: {background}; }} .nofill{{ - fill: none; + fill: {background}; }} text {{ diff --git a/svgbob/src/buffer/cell_buffer/settings.rs b/svgbob/src/buffer/cell_buffer/settings.rs index 06a8d76..ce2c924 100644 --- a/svgbob/src/buffer/cell_buffer/settings.rs +++ b/svgbob/src/buffer/cell_buffer/settings.rs @@ -14,6 +14,8 @@ pub struct Settings { pub stroke_width: f32, /// the scale multiplier pub scale: f32, + /// flag whether to enhace circuitries or not, default true + pub enhance_circuitries: bool, } impl Settings { /// the inverse of the default scale 10 @@ -32,6 +34,7 @@ impl Default for Settings { stroke_color: "black".into(), stroke_width: 2.0, scale: 10.0, + enhance_circuitries: true, } } } diff --git a/svgbob/src/buffer/fragment_buffer/fragment.rs b/svgbob/src/buffer/fragment_buffer/fragment.rs index 01f6972..a968e1e 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment.rs @@ -60,7 +60,6 @@ pub trait Bounds { } } - impl Fragment { /// get the character that matches the shape present on this cell pub fn match_unicode(fragments: &Vec<Self>) -> Option<char> { @@ -124,10 +123,14 @@ impl Fragment { mline.can_merge_polygon(polygon) } + //TODO: make a function level2 merge where it merges fragments into + // marker_lines + /* // line and circle (Fragment::Line(line), Fragment::Circle(circle)) => line.can_merge_circle(circle), // circle and line (Fragment::Circle(circle), Fragment::Line(line)) => line.can_merge_circle(circle), + */ // cell_text and cell_text (Fragment::CellText(ctext), Fragment::CellText(other_ctext)) => { ctext.can_merge(other_ctext) @@ -192,7 +195,11 @@ impl Fragment { let original_len = fragments.len(); let merged = Self::second_pass_merge(fragments); // if has merged continue merging untila nothing can be merged - if merged.len() < original_len { Self::merge_recursive(merged) } else { merged } + if merged.len() < original_len { + Self::merge_recursive(merged) + } else { + merged + } } /// second pass merge is operating on fragments comparing to other spans @@ -521,7 +528,6 @@ pub fn rounded_rect( Fragment::Rect(Rect::rounded_new(start, end, is_filled, radius, is_broken)) } - /// creates a cell text meant to be stored /// in a cell of a fragment_buffer, pub fn cell_text(ch: char) -> Fragment { @@ -692,8 +698,14 @@ mod tests { #[test] fn equal_lines() { - assert_eq!(line(CellGrid::a(), CellGrid::y()), line(CellGrid::y(), CellGrid::a())); - assert_eq!(line(CellGrid::k(), CellGrid::o()), line(CellGrid::o(), CellGrid::k())); + assert_eq!( + line(CellGrid::a(), CellGrid::y()), + line(CellGrid::y(), CellGrid::a()) + ); + assert_eq!( + line(CellGrid::k(), CellGrid::o()), + line(CellGrid::o(), CellGrid::k()) + ); } #[test] diff --git a/svgbob/src/buffer/fragment_buffer/fragment/circle.rs b/svgbob/src/buffer/fragment_buffer/fragment/circle.rs index b1bf69c..585de64 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment/circle.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment/circle.rs @@ -15,7 +15,11 @@ pub struct Circle { impl Circle { pub(in crate) fn new(center: Point, radius: f32, is_filled: bool) -> Self { - Circle { center, radius, is_filled } + Circle { + center, + radius, + is_filled, + } } /// the top most point of this circle for sorting. @@ -30,11 +34,18 @@ impl Circle { /// offset the circles parameter from the arg cell pub(in crate) fn absolute_position(&self, cell: Cell) -> Self { - Circle { center: cell.absolute_position(self.center), ..*self } + Circle { + center: cell.absolute_position(self.center), + ..*self + } } pub(in crate) fn scale(&self, scale: f32) -> Self { - Circle { center: self.center.scale(scale), radius: self.radius * scale, ..*self } + Circle { + center: self.center.scale(scale), + radius: self.radius * scale, + ..*self + } } } diff --git a/svgbob/src/map/ascii_map.rs b/svgbob/src/map/ascii_map.rs index fad9d56..3d6d404 100644 --- a/svgbob/src/map/ascii_map.rs +++ b/svgbob/src/map/ascii_map.rs @@ -111,7 +111,15 @@ lazy_static! { Arc::new( move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ - (true, vec![line(k, o)]), + (true, vec![line(k,o)]), + /* + // | + // .-. + // | + (settings.enhance_circuitries && left.is('.') && right.is('.') && top.line_strongly_overlap(r,w) && bottom.line_strongly_overlap(c,h), + vec![arc(o,k,unit4),line(c,w)] + ), + */ ] } ) @@ -154,6 +162,10 @@ lazy_static! { (right.line_overlap(u,v), vec![line(w,y)]), // _| (left.line_overlap(x,y), vec![line(u,w)]), + // |- + (right.line_strongly_overlap(k,l), vec![line(m,o)]), + // -| + (left.line_strongly_overlap(n,o), vec![line(k,m)]), // TODO: restrict lef, right, bottom, top_right, is not connecting to // here // | @@ -209,7 +221,7 @@ lazy_static! { ( '+', vec![ - (Strong, vec![line(c,w),line(k,o)]), + (Medium, vec![line(c,w),line(k,o)]), (Weak, vec![line(a,y), line(u,e)]), ], Arc::new( @@ -258,12 +270,37 @@ lazy_static! { Arc::new( move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ + /* // \ X // X \ (top_left.line_overlap(s,y) || bottom_right.line_overlap(a,g), vec![line(a, y)]), // / X // X / (top_right.line_overlap(q,u) || bottom_left.line_overlap(e,i), vec![line(e, u)]), + */ + + // -x + (left.line_strongly_overlap(m,o), vec![line(m,k)]), + // x- + (right.line_strongly_overlap(k,l), vec![line(m,o)]), + // | + // x + (top.line_strongly_overlap(r,w), vec![line(m,c)]), + // x + // | + (bottom.line_strongly_overlap(c,h), vec![line(m,w)]), + // \ + // x + (top_left.line_strongly_overlap(s,y), vec![line(m,a)]), + // / + // x + (top_right.line_strongly_overlap(u,q), vec![line(m,e)]), + // x + // / + (bottom_left.line_strongly_overlap(e,i), vec![line(m,u)]), + // x + // \ + (bottom_right.line_strongly_overlap(a,g), vec![line(m,y)]), ] } ) @@ -282,6 +319,28 @@ lazy_static! { move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (true, vec![circle(m,unit2, true)]), + // -* + (left.line_strongly_overlap(m,o), vec![line(m,k)]), + // *- + (right.line_strongly_overlap(k,l), vec![line(m,o)]), + // | + // * + (top.line_strongly_overlap(r,w), vec![line(m,c)]), + // * + // | + (bottom.line_strongly_overlap(c,h), vec![line(m,w)]), + // \ + // * + (top_left.line_strongly_overlap(s,y), vec![line(m,a)]), + // / + // * + (top_right.line_strongly_overlap(u,q), vec![line(m,e)]), + // * + // / + (bottom_left.line_strongly_overlap(e,i), vec![line(m,u)]), + // * + // \ + (bottom_right.line_strongly_overlap(a,g), vec![line(m,y)]), ] } ) @@ -334,6 +393,28 @@ lazy_static! { || top_left.line_strongly_overlap(s,y)|| bottom_right.line_strongly_overlap(a,g) || bottom_left.line_strongly_overlap(u,q) || top_right.line_strongly_overlap(e,i), vec![circle(m,unit1,false)]), + // -o + (left.line_strongly_overlap(m,o), vec![line(m,k)]), + // o- + (right.line_strongly_overlap(k,l), vec![line(m,o)]), + // | + // o + (top.line_strongly_overlap(r,w), vec![line(m,c)]), + // o + // | + (bottom.line_strongly_overlap(c,h), vec![line(m,w)]), + // \ + // o + (top_left.line_strongly_overlap(s,y), vec![line(m,a)]), + // / + // o + (top_right.line_strongly_overlap(u,q), vec![line(m,e)]), + // o + // / + (bottom_left.line_strongly_overlap(e,i), vec![line(m,u)]), + // o + // \ + (bottom_right.line_strongly_overlap(a,g), vec![line(m,y)]), ] } ) @@ -360,6 +441,28 @@ lazy_static! { || left.line_strongly_overlap(n,o) || right.line_strongly_overlap(k,l) || top_left.line_strongly_overlap(s,y)|| bottom_right.line_strongly_overlap(a,g) || bottom_left.line_strongly_overlap(u,q) || top_right.line_strongly_overlap(e,i), vec![circle(m,unit2,false)]), + // -O + (left.line_strongly_overlap(m,o), vec![line(m,k)]), + // O- + (right.line_strongly_overlap(k,l), vec![line(m,o)]), + // | + // O + (top.line_strongly_overlap(r,w), vec![line(m,c)]), + // O + // | + (bottom.line_strongly_overlap(c,h), vec![line(m,w)]), + // \ + // O + (top_left.line_strongly_overlap(s,y), vec![line(m,a)]), + // / + // O + (top_right.line_strongly_overlap(u,q), vec![line(m,e)]), + // O + // / + (bottom_left.line_strongly_overlap(e,i), vec![line(m,u)]), + // O + // \ + (bottom_right.line_strongly_overlap(a,g), vec![line(m,y)]), ] } ) @@ -660,7 +763,7 @@ lazy_static! { ) ), ////////////////////// - // forward slash / + // forward slash / slant line ////////////////////// ( '/', @@ -670,7 +773,14 @@ lazy_static! { Arc::new( move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ - (true, vec![line(u,e)]), + (!bottom.line_strongly_overlap(c,h), vec![line(u,e)]), + // /- + (settings.enhance_circuitries && right.line_strongly_overlap(k,l), vec![line(m,o)]), + // -/ + (settings.enhance_circuitries && left.line_strongly_overlap(n,o), vec![line(m,k)]), + // / + // | + (settings.enhance_circuitries && bottom.line_strongly_overlap(c,h), vec![line(e,m),line(m,w)]), ]} ) ), @@ -696,6 +806,10 @@ lazy_static! { // \ // | (bottom.line_overlap(c,m), vec![line(a,m),line(m,w)]), + // \- + (settings.enhance_circuitries && right.line_strongly_overlap(k,l), vec![line(m,o)]), + // -\ + (settings.enhance_circuitries && left.line_strongly_overlap(n,o), vec![line(m,k)]), ] } ) @@ -710,7 +824,13 @@ lazy_static! { Arc::new( move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ - (true, vec![arc(e,y,unit8)]), + (!top.line_overlap(r,w) && !bottom.line_overlap(c,h), vec![arc(e,y,unit8)]), + // | + // ( + // | + (settings.enhance_circuitries && top.line_overlap(r,w) && bottom.line_overlap(c,h), vec![arc(c,w,unit6)]), + // -(- + (settings.enhance_circuitries && left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), ] } ) @@ -725,14 +845,13 @@ lazy_static! { Arc::new( move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ - (!top.is('|') && !bottom.is('|'), vec![arc(u,a,unit8)]), + (!top.line_overlap(r,w) && !bottom.line_overlap(c,h), vec![arc(u,a,unit8)]), // | // ) // | - (top.is('|') && bottom.is('|'), vec![arc(w,c,unit8)]), - // TODO: this should be gated with Settings.enhance_circuitries + (settings.enhance_circuitries && top.line_overlap(r,w) && bottom.line_overlap(c,h), vec![arc(w,c,unit6)]), // -)- - (left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), + (settings.enhance_circuitries && left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), ] } ) diff --git a/svgbob/test_data/demo.bob b/svgbob/test_data/demo.bob index 0106b72..4e259a3 100644 --- a/svgbob/test_data/demo.bob +++ b/svgbob/test_data/demo.bob @@ -1,6 +1,28 @@ + \ | / + \|/ + -----o----- + /|\ + / | \ + + \ / + \ / + o + / \ + / \ + + \ | / + \|/ + X ---X---- + \ /|\ + / | \ + + * + \ + \ + ◆--------- ---------◆ @@ -357,7 +379,7 @@ What can it do? / | \ . | . | | | - 20 |---------+---------| + 20 | --------+-------- | | | | \ | / `._ | _.' @@ -369,7 +391,7 @@ o-> Pie chart / . \ | / . \ . '. \ | / .' . | '.\|/.' 30% | - |---------+---------| + | --------+-------- | | .'/|\'. | \ .' / | \ '. / `._ / | \ _.' |