summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2018-07-29 05:33:04 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2018-07-29 05:33:04 +0800
commit2024d615b9d0d7ae52cabc74f8f127132a441daf (patch)
tree719a8c65ed770d6a96c6725aef370c63ad0d40db
parent038f0ccfe8b3de8500c13d15a57f4dc204f0b32d (diff)
Added arrowstart marker
-rw-r--r--svgbob/src/lib.rs13
-rw-r--r--svgbob/src/optimizer.rs6
-rw-r--r--svgbob/src/patterns.rs14
-rw-r--r--svgbob/src/properties.rs83
4 files changed, 77 insertions, 39 deletions
diff --git a/svgbob/src/lib.rs b/svgbob/src/lib.rs
index 2a332e0..a093075 100644
--- a/svgbob/src/lib.rs
+++ b/svgbob/src/lib.rs
@@ -40,7 +40,7 @@ extern crate unicode_width;
use pom::parser::*;
use pom::TextInput;
-use self::Feature::Arrow;
+use self::Feature::{Arrow,ArrowStart};
use self::Feature::Circle;
use self::Stroke::Dashed;
use self::Stroke::Solid;
@@ -211,6 +211,7 @@ pub enum Stroke {
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
pub enum Feature {
+ ArrowStart, // start arrow
Arrow, //end
Circle, //start
}
@@ -419,6 +420,10 @@ pub fn arrow_line(s: &Point, e: &Point) -> Element {
Element::Line(s.clone(), e.clone(), Solid, vec![Arrow])
}
+pub fn start_arrow_line(s: &Point, e: &Point) -> Element {
+ Element::Line(s.clone(), e.clone(), Solid, vec![ArrowStart, Arrow])
+}
+
pub fn text(loc: &Loc, txt: &str) -> Element {
Element::Text(loc.clone(), svg_escape(txt))
}
@@ -561,6 +566,9 @@ impl Element {
Arrow => {
svg_line.assign("marker-end", "url(#triangle)");
}
+ ArrowStart => {
+ svg_line.assign("marker-start", "url(#triangle)");
+ }
Circle => {
svg_line.assign("marker-start", "url(#circle)");
}
@@ -592,6 +600,9 @@ impl Element {
Arrow => {
svg_arc.assign("marker-end", "url(#triangle)");
}
+ ArrowStart => {
+ svg_arc.assign("marker-start", "url(#triangle)");
+ }
Circle => {
svg_arc.assign("marker-start", "url(#circle)");
}
diff --git a/svgbob/src/optimizer.rs b/svgbob/src/optimizer.rs
index 3dd5f26..a28676c 100644
--- a/svgbob/src/optimizer.rs
+++ b/svgbob/src/optimizer.rs
@@ -155,6 +155,9 @@ impl Optimizer {
Feature::Arrow => {
arrows.push(elm.clone());
}
+ Feature::ArrowStart => {
+ arrows.push(elm.clone());
+ }
// circle at the end rather than arrow
Feature::Circle => {
arrows.push(elm.clone());
@@ -176,6 +179,9 @@ impl Optimizer {
Feature::Arrow => {
arrows.push(elm.clone());
}
+ Feature::ArrowStart => {
+ arrows.push(elm.clone());
+ }
Feature::Circle => {
arrows.push(elm.clone());
}
diff --git a/svgbob/src/patterns.rs b/svgbob/src/patterns.rs
index 7913f6b..ac7d2cc 100644
--- a/svgbob/src/patterns.rs
+++ b/svgbob/src/patterns.rs
@@ -18,7 +18,7 @@ use properties::Can;
use properties::Properties;
use properties::Signal::{Medium, Strong, Weak};
-use {arc, arrow_line, line, open_circle, solid_circle, text};
+use {arc, arrow_line, start_arrow_line, line, open_circle, solid_circle, text};
use properties::Can::{ConnectTo, Is, IsStrongAll};
@@ -369,7 +369,7 @@ impl<'g> FocusChar<'g> {
Fragment::Line(p1, p2) => line(&self.point(&p1), &self.point(&p2)),
Fragment::ArrowLine(p1, p2) => arrow_line(&self.point(&p1), &self.point(&p2)),
- Fragment::StartArrowLine(p1, p2) => arrow_line(&self.point(&p1), &self.point(&p2)),
+ Fragment::StartArrowLine(p1, p2) => start_arrow_line(&self.point(&p1), &self.point(&p2)),
Fragment::Arc(p1, p2, m) => arc(&self.point(&p1), &self.point(&p2), m as f32 * unit_x),
@@ -485,14 +485,14 @@ impl<'g> FocusChar<'g> {
let mut matched = false;
if enable_default_properties {
if !matched_intended {
- for &(ref block, ref _signal, ref fragments) in &character.properties {
- // draw when used as text but intensified
- if self.is_intensified(&block) && !self.used_as_text() {
+ for &(ref block, ref signal, ref fragments) in &character.properties {
+ // draw when a strong block and not used as text
+ if self.is_strong_block(&block) && !self.used_as_text() {
elm.extend(fragments.clone());
matched = true;
}
- // draw when a strong block and not used as text
- else if self.is_strong_block(&block) && !self.used_as_text() {
+ // draw when used as text but intensified
+ else if self.is_intensified(&block) && !self.used_as_text() {
elm.extend(fragments.clone());
matched = true;
}
diff --git a/svgbob/src/properties.rs b/svgbob/src/properties.rs
index 92157be..13c9f02 100644
--- a/svgbob/src/properties.rs
+++ b/svgbob/src/properties.rs
@@ -228,6 +228,8 @@ impl PointBlock {
#[derive(Debug)]
pub struct Characteristic {
/// these are the default behavior of the fragment
+ /// describe the signal strength: Signal of connection from certain blocks: Block
+ /// if connecting from this block: Block the line is descibed by the fragments: Vec<Fragments>
pub properties: Vec<(Block, Signal, Vec<Fragment>)>,
/// if condition is met, the block becomes a strong signal
pub intensify: Vec<(Block, Condition)>,
@@ -419,9 +421,9 @@ impl Properties for char {
/////////////////////////////
else if self.is('-') {
Some(Characteristic {
+ properties: vec![(K, Strong, vec![line(k, o)]), (O, Strong, vec![line(k, o)])],
intensify: vec![],
intended_behavior: vec![],
- properties: vec![(K, Strong, vec![line(k, o)]), (O, Strong, vec![line(k, o)])],
})
}
///////////////////////////////
@@ -431,14 +433,14 @@ impl Properties for char {
///////////////////////////////
else if self.is('=') {
Some(Characteristic {
- intensify: vec![],
- intended_behavior: vec![],
properties: vec![
(K, Strong, vec![line(k, o)]),
(O, Strong, vec![line(k, o)]),
(F, Strong, vec![line(f, j)]),
(J, Strong, vec![line(f, j)]),
],
+ intensify: vec![],
+ intended_behavior: vec![],
})
}
/////////////////////////////////
@@ -448,9 +450,9 @@ impl Properties for char {
////////////////////////////////
else if self.is('_') {
Some(Characteristic {
+ properties: vec![(U, Strong, vec![line(u, y)]), (Y, Strong, vec![line(u, y)])],
intensify: vec![],
intended_behavior: vec![],
- properties: vec![(U, Strong, vec![line(u, y)]), (Y, Strong, vec![line(u, y)])],
})
}
/////////////////////////////
@@ -460,6 +462,7 @@ impl Properties for char {
////////////////////////////
else if self.is('/') {
Some(Characteristic {
+ properties: vec![(E, Strong, vec![line(u, e)]), (U, Strong, vec![line(u, e)])],
intensify: vec![
// |
// /
@@ -488,7 +491,6 @@ impl Properties for char {
// |
(vec![W], vec![line(m, w), line(m, e)]),
],
- properties: vec![(E, Strong, vec![line(u, e)]), (U, Strong, vec![line(e, u)])],
})
}
////////////////////////////////
@@ -498,6 +500,7 @@ impl Properties for char {
////////////////////////////////
else if self.is('\\') {
Some(Characteristic {
+ properties: vec![(A, Strong, vec![line(a, y)]), (Y, Strong, vec![line(a, y)])],
intensify: vec![
// \
// |
@@ -526,7 +529,6 @@ impl Properties for char {
// \
(vec![C], vec![line(y, m), line(m, c)]),
],
- properties: vec![(A, Strong, vec![line(y, a)]), (Y, Strong, vec![line(a, y)])],
})
}
/////////////////////////////////
@@ -536,6 +538,19 @@ impl Properties for char {
/////////////////////////////////
else if self.is('+') {
Some(Characteristic {
+ 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)]),
+ (K, Medium, vec![line(m, k)]),
+ (O, Medium, vec![line(m, o)]),
+ (W, Medium, vec![line(m, w)]),
+ // emits a weak signal if Block A is strong, if connecting from A line will be
+ // M to A
+ (A, Weak, vec![line(m, a)]),
+ (E, Weak, vec![line(m, e)]),
+ (U, Weak, vec![line(m, u)]),
+ (Y, Weak, vec![line(m, y)]),
+ ],
intensify: vec![
// | .
// + +
@@ -609,16 +624,6 @@ impl Properties for char {
),
],
intended_behavior: vec![],
- properties: vec![
- (C, Medium, vec![line(m, c)]),
- (K, Medium, vec![line(m, k)]),
- (O, Medium, vec![line(m, o)]),
- (W, Medium, vec![line(m, w)]),
- (A, Weak, vec![line(m, a)]),
- (E, Weak, vec![line(m, e)]),
- (U, Weak, vec![line(m, u)]),
- (Y, Weak, vec![line(m, y)]),
- ],
})
}
////////////////////////////
@@ -1293,7 +1298,7 @@ impl Properties for char {
}
////////////////////////////////
//
- // < less than sign
+ // < less than sign, arrow left
//
///////////////////////////////
else if self.is('<') {
@@ -1325,6 +1330,14 @@ impl Properties for char {
can: ConnectTo(A, Strong),
},
),
+ // -<
+ (
+ K,
+ Condition {
+ loc: left(),
+ can: ConnectTo(O, Strong),
+ }
+ )
],
intended_behavior: vec![],
properties: vec![
@@ -1337,7 +1350,7 @@ impl Properties for char {
}
////////////////////////////
//
- // > greather than sign
+ // > greater than sign, arrow right
//
////////////////////////////
else if self.is('>') {
@@ -1369,8 +1382,16 @@ impl Properties for char {
can: ConnectTo(E, Strong),
},
),
+ // >-
+ ( O,
+ Condition {
+ loc: right(),
+ can: ConnectTo(K, Strong),
+ }
+ ),
+ ],
+ intended_behavior: vec![
],
- intended_behavior: vec![],
properties: vec![
(K, Medium, vec![arrow_line(k, m)]),
(O, Weak, vec![start_arrow_line(k, m)]),
@@ -1386,6 +1407,13 @@ impl Properties for char {
///////////////////////
else if self.is('^') {
Some(Characteristic {
+ properties: vec![
+ (W, Medium, vec![arrow_line(w, h)]),
+ (U, Medium, vec![arrow_line(u, i)]),
+ (Y, Medium, vec![arrow_line(y, g)]),
+ (K, Weak, vec![arrow_line(k, i)]),
+ (O, Weak, vec![arrow_line(o, g)]),
+ ],
intensify: vec![
// ^
// |
@@ -1456,13 +1484,6 @@ impl Properties for char {
// / \
(vec![U, Y], vec![line(u, m), line(m, y)]),
],
- properties: vec![
- (W, Medium, vec![arrow_line(w, h)]),
- (U, Medium, vec![arrow_line(u, i)]),
- (Y, Medium, vec![arrow_line(y, g)]),
- (K, Weak, vec![arrow_line(k, i)]),
- (O, Weak, vec![arrow_line(o, g)]),
- ],
})
}
//////////////////////////
@@ -1472,6 +1493,11 @@ impl Properties for char {
//////////////////////////
else if self.any("vV") {
Some(Characteristic {
+ properties: vec![
+ (C, Medium, vec![arrow_line(c, r)]),
+ (A, Medium, vec![arrow_line(a, s)]),
+ (E, Medium, vec![arrow_line(e, q)]),
+ ],
intensify: vec![
// | .
// v v
@@ -1506,11 +1532,6 @@ impl Properties for char {
// v
(vec![A, E], vec![line(a, m), line(m, e)]),
],
- properties: vec![
- (C, Medium, vec![arrow_line(c, r)]),
- (A, Medium, vec![arrow_line(a, s)]),
- (E, Medium, vec![arrow_line(e, q)]),
- ],
})
}
///////////////////////////