summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2019-04-12 16:16:01 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2019-04-12 16:16:01 +0800
commitc3e84c87094550d8cdc6fc48b40a00712b2951cb (patch)
tree5dfe4e08f98bfd672e691a675ebda4fa74bbfee5
parent43fb0364e989d0e9a7656b148c947d47cc769622 (diff)
cargo fmt
-rw-r--r--svgbob/src/block.rs1
-rw-r--r--svgbob/src/box_drawing.rs25
-rw-r--r--svgbob/src/element.rs228
-rw-r--r--svgbob/src/enhance.rs119
-rw-r--r--svgbob/src/enhance_circle.rs383
-rw-r--r--svgbob/src/focus_char.rs85
-rw-r--r--svgbob/src/fragments.rs9
-rw-r--r--svgbob/src/grid.rs104
-rw-r--r--svgbob/src/lib.rs37
-rw-r--r--svgbob/src/loc.rs22
-rw-r--r--svgbob/src/loc_block.rs6
-rw-r--r--svgbob/src/location.rs12
-rw-r--r--svgbob/src/optimizer.rs91
-rw-r--r--svgbob/src/point.rs12
-rw-r--r--svgbob/src/point_block.rs9
-rw-r--r--svgbob/src/properties.rs178
-rw-r--r--svgbob/src/settings.rs4
17 files changed, 705 insertions, 620 deletions
diff --git a/svgbob/src/block.rs b/svgbob/src/block.rs
index 11f0d79..cef5b5c 100644
--- a/svgbob/src/block.rs
+++ b/svgbob/src/block.rs
@@ -1,4 +1,3 @@
-
/// exact location of point
/// relative to the Character Block
/// The block is divided in to 5x5 small blocks
diff --git a/svgbob/src/box_drawing.rs b/svgbob/src/box_drawing.rs
index 3e7ce75..b589958 100644
--- a/svgbob/src/box_drawing.rs
+++ b/svgbob/src/box_drawing.rs
@@ -203,24 +203,23 @@ pub fn box_drawing(ch: &char) -> (Vec<Block>, Vec<Fragment>) {
)
} else if ch.is('╨') {
(vec![K, O, B, D], vec![line(k, o), line(b, l), line(d, n)])
- }
- // ◜
- else if ch.is('◜'){
- (vec![E,W], vec![arc(e, m, 4), line(m, w)])
+ }
+ // ◜
+ else if ch.is('◜') {
+ (vec![E, W], vec![arc(e, m, 4), line(m, w)])
}
// ◝
- else if ch.is('◝'){
- (vec![A,W], vec![arc(m, a, 4), line(m, w)])
+ else if ch.is('◝') {
+ (vec![A, W], vec![arc(m, a, 4), line(m, w)])
}
- // ◟
- else if ch.is('◟'){
- (vec![C,Y], vec![arc(m, y, 4), line(c, m)])
+ // ◟
+ else if ch.is('◟') {
+ (vec![C, Y], vec![arc(m, y, 4), line(c, m)])
}
// ◞
- else if ch.is('◞'){
- (vec![C,U], vec![arc(u, m, 4), line(m, c)])
- }
- else {
+ else if ch.is('◞') {
+ (vec![C, U], vec![arc(u, m, 4), line(m, c)])
+ } else {
(vec![], vec![])
}
}
diff --git a/svgbob/src/element.rs b/svgbob/src/element.rs
index 7fa3889..5b9b177 100644
--- a/svgbob/src/element.rs
+++ b/svgbob/src/element.rs
@@ -1,33 +1,23 @@
-use std::cmp::Ordering;
-use svg_element::SvgElement;
-use svg::Node;
-use svg::node::element::{
- Circle as SvgCircle,
- Line as SvgLine,
- Path as SvgPath,
- Text as SvgText,
-};
use grid::svg_escape;
use point::collinear;
use settings::Settings;
+use std::cmp::Ordering;
+use svg::node::element::{Circle as SvgCircle, Line as SvgLine, Path as SvgPath, Text as SvgText};
+use svg::Node;
+use svg_element::SvgElement;
-use point::Point;
-use loc::Loc;
use element::{
- Stroke::{Solid,Dashed},
- ArcFlag::{Minor,Major},
- Feature::{Arrow,
- Circle,ClearArrow,
- Square,OpenCircle,
- BigOpenCircle,Nothing},
+ ArcFlag::{Major, Minor},
+ Feature::{Arrow, BigOpenCircle, Circle, ClearArrow, Nothing, OpenCircle, Square},
+ Stroke::{Dashed, Solid},
};
+use loc::Loc;
+use point::Point;
use unicode_width::UnicodeWidthStr;
//use point;
use svg;
-
-
-#[derive(Debug, Clone, PartialEq, PartialOrd )]
+#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum Element {
Circle(Point, f32),
// start, end, stroke , start_feature, end feature
@@ -37,7 +27,6 @@ pub enum Element {
Text(Loc, String),
}
-
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
pub enum Stroke {
Solid,
@@ -47,20 +36,19 @@ pub enum Stroke {
//TODO: rename to marker
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
pub enum Feature {
- Arrow, //end
+ Arrow, //end
ClearArrow,
- Circle, //start
- Square, //start
- OpenCircle, //start
+ Circle, //start
+ Square, //start
+ OpenCircle, //start
BigOpenCircle, //start
Nothing,
}
impl Feature {
-
fn get_marker(&self) -> Option<&str> {
match *self {
- Nothing => None,
+ Nothing => None,
Arrow => Some("url(#triangle)"),
ClearArrow => Some("url(#clear_triangle)"),
Circle => Some("url(#circle)"),
@@ -71,24 +59,21 @@ impl Feature {
}
}
-
-
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum ArcFlag {
Major,
Minor,
}
-impl Ord for Element{
- fn cmp(&self, other: &Self) -> Ordering{
- if let Some(order) = self.partial_cmp(&other){
- return order
+impl Ord for Element {
+ fn cmp(&self, other: &Self) -> Ordering {
+ if let Some(order) = self.partial_cmp(&other) {
+ return order;
}
Ordering::Less
}
}
-impl Eq for Element{
-}
+impl Eq for Element {}
pub fn line(a: &Point, b: &Point) -> Element {
Element::Line(a.clone(), b.clone(), Solid, Nothing, Nothing)
@@ -113,12 +98,19 @@ pub fn big_circle_open_line(a: &Point, b: &Point) -> Element {
Element::Line(a.clone(), b.clone(), Solid, BigOpenCircle, Nothing)
}
-
pub fn arc(a: &Point, b: &Point, r: f32) -> Element {
- Element::Arc(a.clone(), b.clone(), r, Minor, false, Solid, Nothing, Nothing)
+ Element::Arc(
+ a.clone(),
+ b.clone(),
+ r,
+ Minor,
+ false,
+ Solid,
+ Nothing,
+ Nothing,
+ )
}
-
pub fn open_circle(c: &Point, r: f32) -> Element {
Element::Circle(c.clone(), r.clone())
}
@@ -139,34 +131,24 @@ pub fn text(loc: &Loc, txt: &str) -> Element {
Element::Text(loc.clone(), svg_escape(txt))
}
-
impl Element {
-
pub fn shares_endpoints(&self, other: &Element) -> bool {
- match *self{
- Element::Line(ref s, ref e, _, _,_) => {
- match *other{
- Element::Line(ref s2, ref e2, _, _,_) => {
- s == s2 || e == e2 || s == e2 || s2 == e
- }
- Element::Arc(ref s2, ref e2, _,_,_,_,_,_) => {
- s == s2 || e == e2 || s == e2 || s2 == e
- }
- _ => false
+ match *self {
+ Element::Line(ref s, ref e, _, _, _) => match *other {
+ Element::Line(ref s2, ref e2, _, _, _) => s == s2 || e == e2 || s == e2 || s2 == e,
+ Element::Arc(ref s2, ref e2, _, _, _, _, _, _) => {
+ s == s2 || e == e2 || s == e2 || s2 == e
}
- }
- Element::Arc(ref s, ref e, _,_,_,_,_,_) => {
- match *other{
- Element::Line(ref s2, ref e2, _, _,_) => {
- s == s2 || e == e2 || s == e2 || s2 == e
- }
- Element::Arc(ref s2, ref e2, _,_,_,_,_,_) => {
- s == s2 || e == e2 || s == e2 || s2 == e
- }
- _ => false
+ _ => false,
+ },
+ Element::Arc(ref s, ref e, _, _, _, _, _, _) => match *other {
+ Element::Line(ref s2, ref e2, _, _, _) => s == s2 || e == e2 || s == e2 || s2 == e,
+ Element::Arc(ref s2, ref e2, _, _, _, _, _, _) => {
+ s == s2 || e == e2 || s == e2 || s2 == e
}
- }
- _ => false
+ _ => false,
+ },
+ _ => false,
}
}
// if this element can reduce the other, return the new reduced element
@@ -174,22 +156,29 @@ impl Element {
// for text, the other text should apear on the right side of this text
pub fn reduce(&self, other: &Element) -> Option<Element> {
// if same then return one
- if self == other{
- return Some(other.clone())
+ if self == other {
+ return Some(other.clone());
}
match *self {
Element::Line(ref s, ref e, ref stroke, ref start_feature, ref end_feature) => {
match *other {
- Element::Line(ref s2, ref e2, ref stroke2, ref start_feature2, ref end_feature2) => {
+ Element::Line(
+ ref s2,
+ ref e2,
+ ref stroke2,
+ ref start_feature2,
+ ref end_feature2,
+ ) => {
// note: dual 3 point check for trully collinear lines
- if collinear(s, e, s2)
- && collinear(s, e, e2)
- && stroke == stroke2{
+ if collinear(s, e, s2) && collinear(s, e, e2) && stroke == stroke2 {
// same length line
- if s == s2 && e == e2 && start_feature == start_feature2 && end_feature == end_feature2 {
- return Some(other.clone())
+ if s == s2
+ && e == e2
+ && start_feature == start_feature2
+ && end_feature == end_feature2
+ {
+ return Some(other.clone());
}
-
// extend 1 with 2
// line1 line2
// s-----e s2-----e2
@@ -199,72 +188,74 @@ impl Element {
// o----
// ------
// ------>
- if *end_feature == Nothing && *start_feature2 == Nothing{
+ if *end_feature == Nothing && *start_feature2 == Nothing {
return Some(Element::Line(
- s.clone(),
- e2.clone(),
- stroke.clone(),
- start_feature.clone(),
- end_feature2.clone()
- ));
+ s.clone(),
+ e2.clone(),
+ stroke.clone(),
+ start_feature.clone(),
+ end_feature2.clone(),
+ ));
}
}
// extend 1 with flip 2
// line1 line2
// s------e e2-------s2
// s-------------------s2
- else if e == e2{
+ else if e == e2 {
// ------- --------
// o------ ---------
- if *end_feature == Nothing && *end_feature2 == Nothing{
+ if *end_feature == Nothing && *end_feature2 == Nothing {
return Some(Element::Line(
- s.clone(),
- s2.clone(),
- stroke.clone(),
- start_feature.clone(),
- start_feature2.clone(),
- ));
+ s.clone(),
+ s2.clone(),
+ stroke.clone(),
+ start_feature.clone(),
+ start_feature2.clone(),
+ ));
}
}
// flip1 extend 2
// line1 line2
// e------s s2------e2
// s------------------e2
- else if s == s2{
+ else if s == s2 {
// ------- -------
// ------- ------->
// except for line 1 has arrow at the end
- if *start_feature == Nothing && *start_feature2 == Nothing && *end_feature != Arrow {
+ if *start_feature == Nothing
+ && *start_feature2 == Nothing
+ && *end_feature != Arrow
+ {
return Some(Element::Line(
- e.clone(),
- e2.clone(),
- stroke.clone(),
- end_feature.clone(),
- end_feature2.clone(),
- ));
- }
+ e.clone(),
+ e2.clone(),
+ stroke.clone(),
+ end_feature.clone(),
+ end_feature2.clone(),
+ ));
+ }
}
// extend 2 with 1
// line1 line2
// e------s e2------s2
// e---------------------s2
//
- else if s == e2{
+ else if s == e2 {
// ----- -----
// ----- ----o
// <---- -----
// <---- ----o
- if *start_feature == Nothing && *end_feature2 == Nothing{
+ if *start_feature == Nothing && *end_feature2 == Nothing {
return Some(Element::Line(
- s2.clone(),
- e.clone(),
- stroke.clone(),
- start_feature2.clone(),
- end_feature.clone(),
- ));
+ s2.clone(),
+ e.clone(),
+ stroke.clone(),
+ start_feature2.clone(),
+ end_feature.clone(),
+ ));
}
}
-
}
return None;
}
@@ -291,7 +282,6 @@ impl Element {
}
}
-
/// convert drawing element to SVG element
pub fn to_svg(&self, settings: &Settings) -> SvgElement {
match *self {
@@ -312,21 +302,30 @@ impl Element {
.set("x2", e.x)
.set("y2", e.y);
- if let Some(marker) = start_feature.get_marker(){
+ if let Some(marker) = start_feature.get_marker() {
svg_line.assign("marker-start", marker);
}
- if let Some(marker) = end_feature.get_marker(){
+ if let Some(marker) = end_feature.get_marker() {
svg_line.assign("marker-end", marker);
}
match *stroke {
Solid => (),
Dashed => {
- svg_line.assign("class","fg_stroke dashed");
+ svg_line.assign("class", "fg_stroke dashed");
}
};
SvgElement::Line(svg_line)
}
- Element::Arc(ref s, ref e, radius, ref arc_flag, sweep, _, ref start_feature, ref end_feature) => {
+ Element::Arc(
+ ref s,
+ ref e,
+ radius,
+ ref arc_flag,
+ sweep,
+ _,
+ ref start_feature,
+ ref end_feature,
+ ) => {
let sweept = if sweep { "1" } else { "0" };
let arc_flag = match *arc_flag {
Major => "1",
@@ -336,13 +335,11 @@ impl Element {
"M {} {} A {} {} 0 {} {} {} {}",
s.x, s.y, radius, radius, arc_flag, sweept, e.x, e.y
);
- let mut svg_arc = SvgPath::new()
- .set("class","fg_stroke no_fill")
- .set("d", d);
- if let Some(marker) = start_feature.get_marker(){
+ let mut svg_arc = SvgPath::new().set("class", "fg_stroke no_fill").set("d", d);
+ if let Some(marker) = start_feature.get_marker() {
svg_arc.assign("marker-start", marker);
}
- if let Some(marker) = end_feature.get_marker(){
+ if let Some(marker) = end_feature.get_marker() {
svg_arc.assign("marker-end", marker);
}
SvgElement::Path(svg_arc)
@@ -351,7 +348,7 @@ impl Element {
let sx = loc.x as f32 * settings.text_width + settings.text_width / 8.0;
let sy = loc.y as f32 * settings.text_height + settings.text_height * 3.0 / 4.0;
let mut svg_text = SvgText::new()
- .set("class","fg_fill")
+ .set("class", "fg_fill")
.set("x", sx)
.set("y", sy);
let text_node = svg::node::Text::new(string.to_string());
@@ -361,4 +358,3 @@ impl Element {
}
}
}
-
diff --git a/svgbob/src/enhance.rs b/svgbob/src/enhance.rs
index 3ca21ec..20af4c4 100644
--- a/svgbob/src/enhance.rs
+++ b/svgbob/src/enhance.rs
@@ -1,17 +1,16 @@
+use block::Block::{A, C, E, F, J, K, M, O, P, Q, S, T, U, W, Y};
use focus_char::FocusChar;
use fragments::Fragment;
-use location::Location;
+use fragments::{arc, arrow_line, clear_arrow_line, line, open_circle};
use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight};
-use block::Block::{A, C, E, F, J, K, M, O, P, Q, S, T, U, W, Y};
+use location::Location;
use point_block::PointBlock;
-use fragments::{line, arc, arrow_line, open_circle, clear_arrow_line};
pub trait Enhance {
fn enhance(&self) -> (Vec<Fragment>, Vec<Location>);
}
impl<'g> Enhance for FocusChar<'g> {
-
fn enhance(&self) -> (Vec<Fragment>, Vec<Location>) {
let mut elm = vec![];
let mut consumed = vec![];
@@ -71,13 +70,13 @@ impl<'g> Enhance for FocusChar<'g> {
// |
// _
// V
- if self.bottom().any("vV") && self.top().is('|'){
+ if self.bottom().any("vV") && self.top().is('|') {
elm.push(clear_arrow_line(c, w));
consumed.extend(vec![this(), bottom()]);
}
}
- if self.is('∀'){
- if self.top().is('|'){
+ if self.is('∀') {
+ if self.top().is('|') {
elm.push(clear_arrow_line(c, w));
consumed.extend(vec![this(), top()]);
}
@@ -108,7 +107,7 @@ impl<'g> Enhance for FocusChar<'g> {
// <'
if self.top_right().is('/') && self.left().is('<') {
elm.push(arrow_line(&top_right().c(), &left().j()));
- consumed.extend(vec![this(), left(),top_right()]);
+ consumed.extend(vec![this(), left(), top_right()]);
}
// For diamond rectangle
// .
@@ -126,12 +125,12 @@ impl<'g> Enhance for FocusChar<'g> {
// .'
if self.left().any(".,") {
elm.push(line(c, &left().m()));
- consumed.extend(vec![this(),left()]);
+ consumed.extend(vec![this(), left()]);
}
// '.
if self.right().any(".,") {
elm.push(line(c, &right().m()));
- consumed.extend(vec![this(),right()]);
+ consumed.extend(vec![this(), right()]);
}
}
if self.any(".,") {
@@ -140,58 +139,58 @@ impl<'g> Enhance for FocusChar<'g> {
// + +
if self.bottom_right().is('+') && self.left().is('<') {
elm.push(arrow_line(&bottom_right().m(), &left().t()));
- consumed.extend(vec![this(),left()]);
+ consumed.extend(vec![this(), left()]);
}
// <, <.
// \ \
if self.bottom_right().is('\\') && self.left().is('<') {
elm.push(arrow_line(&bottom_right().w(), &left().t()));
- consumed.extend(vec![this(),left(), bottom_right()]);
+ consumed.extend(vec![this(), left(), bottom_right()]);
}
//
// .> ,>
// + +
if self.bottom_left().is('+') && self.right().is('>') {
elm.push(arrow_line(&bottom_left().m(), &right().p()));
- consumed.extend(vec![this(),right()]);
+ consumed.extend(vec![this(), right()]);
}
//
// ,>
// /
if self.bottom_left().is('/') && self.right().is('>') {
elm.push(arrow_line(&bottom_left().w(), &right().p()));
- consumed.extend(vec![this(),right(), bottom_left()]);
+ consumed.extend(vec![this(), right(), bottom_left()]);
}
}
// transistor complimentary enhancement
if self.is('|') {
// as long as the bottom is NOT |
- if !self.bottom().is('|'){
+ if !self.bottom().is('|') {
// |
// \
- if self.bottom_right().is('\\'){
- elm.extend(vec![line(c,m), line(m,y)]);
+ if self.bottom_right().is('\\') {
+ elm.extend(vec![line(c, m), line(m, y)]);
consumed.extend(vec![this()]);
}
// |
// /
- if self.bottom_left().is('/'){
- elm.extend(vec![line(c,m), line(m,u)]);
+ if self.bottom_left().is('/') {
+ elm.extend(vec![line(c, m), line(m, u)]);
consumed.extend(vec![this()]);
}
}
// top should not be |
- if !self.top().is('|'){
+ if !self.top().is('|') {
// /
// |
- if self.top_right().is('/'){
- elm.extend(vec![line(w, m), line(m,e)]);
+ if self.top_right().is('/') {
+ elm.extend(vec![line(w, m), line(m, e)]);
consumed.extend(vec![this()]);
}
// \
// |
- if self.top_left().is('\\'){
- elm.extend(vec![line(w,m), line(m,a)]);
+ if self.top_left().is('\\') {
+ elm.extend(vec![line(w, m), line(m, a)]);
consumed.extend(vec![this()]);
}
}
@@ -210,28 +209,28 @@ impl<'g> Enhance for FocusChar<'g> {
// _
// |
if self.top_right().is('_') {
- elm.extend(vec![line(c,w),line(c, e)]);
+ elm.extend(vec![line(c, w), line(c, e)]);
consumed.push(this());
}
// _
// |
if self.top_left().is('_') {
- elm.extend(vec![line(c,w),line(a,c)]);
+ elm.extend(vec![line(c, w), line(a, c)]);
consumed.push(this());
}
// |>
- if self.right().is('>') && self.left().is('-'){
- elm.push(clear_arrow_line(k,o));
+ if self.right().is('>') && self.left().is('-') {
+ elm.push(clear_arrow_line(k, o));
consumed.extend(vec![this(), right()]);
}
// <|
- if self.left().is('<') && self.right().is('-'){
+ if self.left().is('<') && self.right().is('-') {
elm.push(clear_arrow_line(o, k));
consumed.extend(vec![this(), left()]);
}
// A
// |
- if self.top().is('A'){
+ if self.top().is('A') {
elm.push(clear_arrow_line(w, c));
consumed.extend(vec![this(), top()]);
}
@@ -265,24 +264,24 @@ 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('`'){
+ 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('\''){
+ 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.is('^') {
// ^
// `.
- if self.bottom_right().is('`') && self.bottom().in_right(2).is('.'){
+ if self.bottom_right().is('`') && self.bottom().in_right(2).is('.') {
elm.push(arrow_line(&bottom_right2().t(), m));
consumed.push(this());
}
@@ -298,7 +297,8 @@ impl<'g> Enhance for FocusChar<'g> {
// -(-
// |
//
- 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)
@@ -311,7 +311,8 @@ impl<'g> Enhance for FocusChar<'g> {
// -)-
// |
//
- 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)
@@ -321,53 +322,57 @@ impl<'g> Enhance for FocusChar<'g> {
}
// railroad diagram
// _◞_
- if self.is('◞') && self.left().is('_') && self.right().is('_'){
- elm.extend(vec![line(u,y)]);
+ if self.is('◞') && self.left().is('_') && self.right().is('_') {
+ elm.extend(vec![line(u, y)]);
}
// railroad diagram
// _◟_
- if self.is('◟') && self.left().is('_') && self.right().is('_'){
- elm.extend(vec![line(u,y)]);
+ if self.is('◟') && self.left().is('_') && self.right().is('_') {
+ elm.extend(vec![line(u, y)]);
}
// railroad diagram
//
// -╯- -╰- -╭- -╮-
//
- if self.any("╯╮╰╭") && self.left().is('-') && self.right().is('-'){
- elm.extend(vec![line(k,o)]);
+ if self.any("╯╮╰╭") && self.left().is('-') && self.right().is('-') {
+ elm.extend(vec![line(k, o)]);
}
// | |
// ╰ ╯
// | |
- if self.any("╰╯") && self.top().is('|') && self.bottom().is('|'){
- elm.extend(vec![line(c,w)]);
+ if self.any("╰╯") && self.top().is('|') && self.bottom().is('|') {
+ elm.extend(vec![line(c, w)]);
}
// railroad start
// O_
- if self.is('O') && self.right().is('_'){
- elm.extend(vec![open_circle(m,3), arc(t,&right().y(),4)]);
+ if self.is('O') && self.right().is('_') {
+ elm.extend(vec![open_circle(m, 3), arc(t, &right().y(), 4)]);
consumed.extend(vec![this(), right()]);
}
// railroad end
// _O
- if self.is('O') && self.left().is('_'){
- elm.extend(vec![open_circle(m,3), arc(&left().u(), p,4)]);
+ if self.is('O') && self.left().is('_') {
+ elm.extend(vec![open_circle(m, 3), arc(&left().u(), p, 4)]);
consumed.extend(vec![this(), left()]);
}
// railroad start
// o_
- if self.is('o') && self.right().is('_'){
- elm.extend(vec![open_circle(m,2),
- arc(s,&right().w(),4),
- line(&right().w(), &right().y())]);
+ if self.is('o') && self.right().is('_') {
+ elm.extend(vec![
+ open_circle(m, 2),
+ arc(s, &right().w(), 4),
+ line(&right().w(), &right().y()),
+ ]);
consumed.extend(vec![this(), right()]);
}
// railroad end
// _o
- if self.is('o') && self.left().is('_'){
- elm.extend(vec![open_circle(m,2),
- arc(&left().w(), q, 4),
- line(&left().w(), &left().u())]);
+ if self.is('o') && self.left().is('_') {
+ elm.extend(vec![
+ open_circle(m, 2),
+ arc(&left().w(), q, 4),
+ line(&left().w(), &left().u()),
+ ]);
consumed.extend(vec![this(), left()]);
}
(elm, consumed)
diff --git a/svgbob/src/enhance_circle.rs b/svgbob/src/enhance_circle.rs
index 3794a67..1d5c3a8 100644
--- a/svgbob/src/enhance_circle.rs
+++ b/svgbob/src/enhance_circle.rs
@@ -1,18 +1,16 @@
-
+use block::Block::{K, M, O, W, Y};
use focus_char::FocusChar;
+use fragments::open_circle;
use fragments::Fragment;
-use location::Location;
use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight};
-use block::Block::{K, M, O, W, Y};
+use location::Location;
use point_block::PointBlock;
-use fragments::open_circle;
pub trait EnhanceCircle {
fn enhance_circle(&self) -> (Vec<Fragment>, Vec<Location>);
}
impl<'g> EnhanceCircle for FocusChar<'g> {
-
fn enhance_circle(&self) -> (Vec<Fragment>, Vec<Location>) {
let mut elm = vec![];
let mut consumed = vec![];
@@ -53,54 +51,54 @@ impl<'g> EnhanceCircle for FocusChar<'g> {
let bottom_left = || Location::go(BottomLeft);
let bottom_right = || Location::go(BottomRight);
- let top2 = || Location::jump(Top,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 top2 = || Location::jump(Top, 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);