summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2018-07-30 17:36:18 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2018-07-30 17:36:18 +0800
commitc6cd41659011e89759d8b4a379c1d49931e24f14 (patch)
treed7a1d535f825b14d3d8c622be0fae4ec5d9e3f3a
parent44ccf2a6604c92e69d1a789abb17d5bbffd302f6 (diff)
Add indicator for box drawing and text that can be dynamically used as text or drawing
-rw-r--r--svgbob/src/enhance.rs43
-rw-r--r--svgbob/src/focus_char.rs53
-rw-r--r--svgbob/src/location.rs6
-rw-r--r--svgbob/src/properties.rs38
4 files changed, 90 insertions, 50 deletions
diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs
index dce0fd7..c4138b5 100644
--- a/svgbob/src/enhance.rs
+++ b/svgbob/src/enhance.rs
@@ -40,6 +40,7 @@ impl<'g> Enhance for FocusChar<'g> {
let _x = &PointBlock::block(X);
let y = &PointBlock::block(Y);
+ let this = || Location::this();
let top = || Location::go(Top);
let bottom = || Location::go(Bottom);
let left = || Location::go(Left);
@@ -59,24 +60,6 @@ impl<'g> Enhance for FocusChar<'g> {
if self.left().any("|]") {
elm.push(line(y, &left().w()));
}
- // _
- // |
- if self.bottom_left().any("|]") {
- elm.push(line(y, &left().w()));
- }
- // _
- // |
- if self.bottom_right().any("|[") {
- elm.push(line(u, &right().w()));
- }
- // /_
- if self.left().is('/') {
- elm.push(line(y, &left().u()));
- }
- if self.right().is('\\') {
- // _\
- elm.push(line(u, &right().y()));
- }
}
else if self.any("`'") {
// for circuitries
@@ -156,6 +139,16 @@ impl<'g> Enhance for FocusChar<'g> {
if self.top().any("><") {
elm.push(line(w, &top().m()));
}
+ // _
+ // |
+ if self.top_right().is('_') {
+ elm.extend(vec![line(c,w),line(c, e)]);
+ }
+ // _
+ // |
+ if self.top_left().is('_') {
+ elm.extend(vec![line(c,w),line(a,c)]);
+ }
} else if self.is('/') {
// >
// /
@@ -190,6 +183,7 @@ impl<'g> Enhance for FocusChar<'g> {
&& self.right().can_strongly_connect(&K)
{
elm.extend(vec![arc(c, w, 5), line(k, o)]);
+ //consumed.push(this());
}
// circuitries jump
// |
@@ -202,19 +196,8 @@ impl<'g> Enhance for FocusChar<'g> {
&& self.right().can_strongly_connect(&K)
{
elm.extend(vec![arc(w, c, 5), line(k, o)]);
+ //consumed.push(this());
}
- /*
- // 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()));
- }
- if self.left().is(' ') && self.in_left(2).is('-'){
- elm.push(dashed_line(o, &left().left().k()));
- }
- }
- */
(elm, consumed)
}
diff --git a/svgbob/src/focus_char.rs b/svgbob/src/focus_char.rs
index c96d045..97d30cc 100644
--- a/svgbob/src/focus_char.rs
+++ b/svgbob/src/focus_char.rs
@@ -20,7 +20,7 @@ use enhance::Enhance;
#[derive(Debug, Clone)]
pub struct FocusChar<'g> {
- loc: Loc,
+ pub loc: Loc,
ch: char,
grid: &'g Grid,
}
@@ -65,28 +65,38 @@ impl<'g> FocusChar<'g> {
self.ch.any(s)
}
- /// check if the the surrounding character can connect to this character
+ /// if it's properties is static such as unicode box drawing
+ /// they are automatically used as drawing element
+ /// otherwise, check if the the surrounding character can connect to this character
fn used_as_drawing(&self)-> bool {
- // --
- (self.can_strongly_connect(&Block::O) && self.right().can_pass_medium_connect(&Block::K))
- || (self.can_strongly_connect(&Block::K) && self.left().can_pass_medium_connect(&Block::O))
- // |
- // |
- || (self.can_strongly_connect(&Block::C) && self.top().can_pass_medium_connect(&Block::W))
- || (self.can_strongly_connect(&Block::W) && self.bottom().can_pass_medium_connect(&Block::C))
- // \
- // \
- || (self.can_strongly_connect(&Block::A) && self.top_left().can_pass_medium_connect(&Block::Y))
- || (self.can_strongly_connect(&Block::Y) && self.bottom_right().can_pass_medium_connect(&Block::A))
- // /
- // /
- || (self.can_strongly_connect(&Block::E) && self.top_right().can_pass_medium_connect(&Block::U))
- || (self.can_strongly_connect(&Block::U) && self.bottom_left().can_pass_medium_connect(&Block::E))
- // __
- || (self.can_strongly_connect(&Block::U) && self.top_right().can_pass_medium_connect(&Block::Y))
- || (self.can_strongly_connect(&Block::Y) && self.bottom_left().can_pass_medium_connect(&Block::U))
+ // all box uncide drawing are static
+ if self.ch.is_static() {
+ true
+ }
+ else{
+ // --
+ (self.can_strongly_connect(&Block::O) && self.right().can_pass_medium_connect(&Block::K))
+ || (self.can_strongly_connect(&Block::K) && self.left().can_pass_medium_connect(&Block::O))
+ // |
+ // |
+ || (self.can_strongly_connect(&Block::C) && self.top().can_pass_medium_connect(&Block::W))
+ || (self.can_strongly_connect(&Block::W) && self.bottom().can_pass_medium_connect(&Block::C))
+ // \
+ // \
+ || (self.can_strongly_connect(&Block::A) && self.top_left().can_pass_medium_connect(&Block::Y))
+ || (self.can_strongly_connect(&Block::Y) && self.bottom_right().can_pass_medium_connect(&Block::A))
+ // /
+ // /
+ || (self.can_strongly_connect(&Block::E) && self.top_right().can_pass_medium_connect(&Block::U))
+ || (self.can_strongly_connect(&Block::U) && self.bottom_left().can_pass_medium_connect(&Block::E))
+ // __
+ || (self.can_strongly_connect(&Block::U) && self.left().can_pass_medium_connect(&Block::Y))
+ || (self.can_strongly_connect(&Block::Y) && self.right().can_pass_medium_connect(&Block::U))
+ }
}
+ /// determine if the character at this location
+ /// is used as text or not
fn used_as_text(&self) -> bool {
if self.used_as_drawing(){
false
@@ -263,12 +273,15 @@ impl<'g> FocusChar<'g> {
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;
}
// intended behaviors when signals are strong
// after applying the intensifiers
// do only when enhancements is not matched
+ // TODO: if nothing is consumed in the enhance
+ // allow the rest to do the matching
if !matched_enhance {
for &(ref blocks, ref fragments) in &character.intended_behavior {
let meet = blocks.iter().all(|ref b| self.can_be_strong_block(&b));
diff --git a/svgbob/src/location.rs b/svgbob/src/location.rs
index d339a2b..686a7f3 100644
--- a/svgbob/src/location.rs
+++ b/svgbob/src/location.rs
@@ -29,6 +29,12 @@ impl Location {
Self::jump(direction, 1)
}
+ // this location
+ // TODO: hacky fix these
+ pub fn this()-> Self{
+ Self::jump(Right, 0)
+ }
+
pub fn jump(direction: Direction, step: usize) -> Self {
Location(vec![(direction, step)])
}
diff --git a/svgbob/src/properties.rs b/svgbob/src/properties.rs
index 0242007..6c1b3f2 100644
--- a/svgbob/src/properties.rs
+++ b/svgbob/src/properties.rs
@@ -50,6 +50,9 @@ pub struct Characteristic {
/// are strong
/// then use these fragments instead
pub intended_behavior: Vec<(Vec<Block>, Vec<Fragment>)>,
+ /// typing characters are dynamic
+ /// while box uncide drawing are static
+ pub is_static: bool,
}
impl Characteristic {
@@ -76,6 +79,8 @@ pub trait Properties {
fn is(&self, ch: char) -> bool;
+ fn is_static(&self) -> bool;
+
fn any(&self, s: &str) -> bool;
fn in_any(&self, ch: Vec<char>) -> bool;
@@ -105,6 +110,14 @@ impl Properties for char {
fn is(&self, ch: char) -> bool {
*self == ch
}
+ fn is_static(&self) -> bool {
+ if let Some(characteristic) = self.get_characteristic(){
+ characteristic.is_static
+ }
+ else{
+ false
+ }
+ }
fn any(&self, s: &str) -> bool {
s.contains(*self)
@@ -172,6 +185,7 @@ impl Properties for char {
/////////////////////////////////
if self.is('|') {
Some(Characteristic {
+ is_static: false,
properties: vec![(C, Strong, vec![line(c, w)]), (W, Strong, vec![line(c, w)])],
intensify: vec![
// |
@@ -252,6 +266,7 @@ impl Properties for char {
/////////////////////////////
else if self.is('-') {
Some(Characteristic {
+ is_static: false,
properties: vec![(K, Strong, vec![line(k, o)]), (O, Strong, vec![line(k, o)])],
intensify: vec![],
intended_behavior: vec![],
@@ -264,6 +279,7 @@ impl Properties for char {
//////////////////////////////
else if self.is('~'){
Some(Characteristic {
+ is_static: false,
properties: vec![(K, Strong, vec![dashed_line(k, o)]), (O, Strong, vec![dashed_line(k, o)])],
intensify: vec![],
intended_behavior: vec![],
@@ -276,6 +292,7 @@ impl Properties for char {
///////////////////////////////
else if self.is('=') {
Some(Characteristic {
+ is_static: false,
properties: vec![
(K, Strong, vec![line(&k.adjust(0.0, 1.0), &o.adjust(0.0, 1.0))]),
(O, Strong, vec![line(&k.adjust(0.0, 1.0), &o.adjust(0.0, 1.0))]),
@@ -293,6 +310,7 @@ impl Properties for char {
////////////////////////////////
else if self.is('_') {
Some(Characteristic {
+ is_static: false,
properties: vec![(U, Strong, vec![line(u, y)]), (Y, Strong, vec![line(u, y)])],
intensify: vec![
],
@@ -307,6 +325,7 @@ impl Properties for char {
////////////////////////////
else if self.is('/') {
Some(Characteristic {
+ is_static: false,
properties: vec![(E, Strong, vec![line(u, e)]), (U, Strong, vec![line(u, e)])],
intensify: vec![
// |
@@ -375,6 +394,7 @@ impl Properties for char {
////////////////////////////////
else if self.is('\\') {
Some(Characteristic {
+ is_static: false,
properties: vec![(A, Strong, vec![line(a, y)]), (Y, Strong, vec![line(a, y)])],
intensify: vec![
// \
@@ -443,6 +463,7 @@ impl Properties for char {
/////////////////////////////////
else if self.is('+') {
Some(Characteristic {
+ is_static: false,
properties: vec![
// emits medium signal if Block C is strong, if connecting from C, then the line will be M to C
(C, Medium, vec![line(m, c)]),
@@ -538,6 +559,7 @@ impl Properties for char {
////////////////////////////
else if self.any("xX") {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// \
// x
@@ -628,6 +650,7 @@ impl Properties for char {
///////////////////////////
else if self.any(".,") {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// -. +.
(
@@ -807,6 +830,7 @@ impl Properties for char {
//////////////////////////
else if self.any("`'") {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// -' +'
(
@@ -914,6 +938,7 @@ impl Properties for char {
//////////////////////
else if self.is('*') {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// |
// *
@@ -1006,6 +1031,7 @@ impl Properties for char {
//////////////////////////
else if self.is('o') {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// |
// o
@@ -1098,6 +1124,7 @@ impl Properties for char {
////////////////////////////
else if self.is('O') {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// |
// O
@@ -1208,6 +1235,7 @@ impl Properties for char {
///////////////////////////////
else if self.is('<') {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// <- <+ <' <.
(
@@ -1260,6 +1288,7 @@ impl Properties for char {
////////////////////////////
else if self.is('>') {
Some(Characteristic {
+ is_static: false,
intensify: vec![
// -> +> .> '>
(
@@ -1312,6 +1341,7 @@ impl Properties for char {
///////////////////////
else if self.is('^') {
Some(Characteristic {
+ is_static: false,
properties: vec![
(W, Medium, vec![arrow_line(w, h)]),
(U, Medium, vec![arrow_line(u, i)]),
@@ -1398,6 +1428,7 @@ impl Properties for char {
//////////////////////////
else if self.any("vV") {
Some(Characteristic {
+ is_static: false,
properties: vec![
(C, Medium, vec![arrow_line(c, r)]),
(A, Medium, vec![arrow_line(a, s)]),
@@ -1446,6 +1477,7 @@ impl Properties for char {
//////////////////////////
else if self.is('(') {
Some(Characteristic {
+ is_static: false,
intensify: vec![],
intended_behavior: vec![],
properties: vec![
@@ -1465,6 +1497,7 @@ impl Properties for char {
///////////////////////////////
else if self.is(')') {
Some(Characteristic {
+ is_static: false,
intensify: vec![],
intended_behavior: vec![],
properties: vec![
@@ -1484,6 +1517,7 @@ impl Properties for char {
///////////////////////////////
else if self.is('[') {
Some(Characteristic {
+ is_static: false,
intensify: vec![],
intended_behavior: vec![],
properties: vec![
@@ -1499,6 +1533,7 @@ impl Properties for char {
////////////////////////////
else if self.is(']') {
Some(Characteristic {
+ is_static: false,
intensify: vec![],
intended_behavior: vec![],
properties: vec![
@@ -1514,6 +1549,7 @@ impl Properties for char {
//////////////////////////////
else if self.is(':'){
Some(Characteristic{
+ is_static: false,
intensify: vec![],
intended_behavior: vec![],
properties: vec![
@@ -1529,6 +1565,7 @@ impl Properties for char {
//////////////////////////////
else if self.is('!'){
Some(Characteristic{
+ is_static: false,
intensify: vec![],
intended_behavior: vec![],
properties: vec![
@@ -1546,6 +1583,7 @@ impl Properties for char {
}
if !properties.is_empty() {
Some(Characteristic {
+ is_static: true, // all of box drawing are static
intensify: vec![],
intended_behavior: vec![],
properties: properties,