summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2018-07-29 17:12:09 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2018-07-29 17:12:09 +0800
commit48e7f46732fef1a40138e3d3771d6187065ce529 (patch)
treeba0e294011f05a722296f07d2c769590f6795fc0
parentd053c331bf2c1dd76c4def1825dbee55e018619c (diff)
remove unused warnings
-rw-r--r--svgbob/src/element.rs25
-rw-r--r--svgbob/src/focus_char.rs2
-rw-r--r--svgbob/src/fragments.rs1
-rw-r--r--svgbob/src/grid.rs136
-rw-r--r--svgbob/src/lib.rs6
-rw-r--r--svgbob/src/loc_block.rs17
-rw-r--r--svgbob/src/location.rs15
-rw-r--r--svgbob/src/optimizer.rs66
-rw-r--r--svgbob/src/point.rs2
-rw-r--r--svgbob/src/point_block.rs1
-rw-r--r--svgbob/src/properties.rs5
-rw-r--r--svgbob/src/svg_element.rs5
12 files changed, 17 insertions, 264 deletions
diff --git a/svgbob/src/element.rs b/svgbob/src/element.rs
index 5676f2a..8fb31ab 100644
--- a/svgbob/src/element.rs
+++ b/svgbob/src/element.rs
@@ -3,12 +3,8 @@ use svg_element::SvgElement;
use svg::Node;
use svg::node::element::{
Circle as SvgCircle,
- Definitions,
Line as SvgLine,
- Marker,
Path as SvgPath,
- Rectangle as SvgRect,
- Style,
Text as SvgText,
};
use grid::svg_escape;
@@ -30,7 +26,6 @@ pub enum Element {
Line(Point, Point, Stroke, Vec<Feature>),
Arc(Point, Point, f32, ArcFlag, bool, Stroke, Vec<Feature>),
Text(Loc, String),
- Path(Point, Point, String, Stroke),
}
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
@@ -74,11 +69,11 @@ pub fn solid_circle(c: &Point, r: f32) -> Element {
Element::Circle(c.clone(), r, "solid".to_string())
}
-pub fn arrow_arc(a: &Point, b: &Point, r: f32) -> Element {
+pub fn _arrow_arc(a: &Point, b: &Point, r: f32) -> Element {
Element::Arc(a.clone(), b.clone(), r, Minor, false, Solid, vec![Arrow])
}
-pub fn arrow_sweep_arc(a: &Point, b: &Point, r: f32) -> Element {
+pub fn _arrow_sweep_arc(a: &Point, b: &Point, r: f32) -> Element {
Element::Arc(a.clone(), b.clone(), r.clone(), Minor, true, Solid, vec![Arrow])
}
@@ -86,7 +81,7 @@ pub fn arc(a: &Point, b: &Point, r: f32) -> Element {
Element::Arc(a.clone(), b.clone(), r, Minor, false, Solid, vec![])
}
-pub fn arc_major(a: &Point, b: &Point, r: f32) -> Element {
+pub fn _arc_major(a: &Point, b: &Point, r: f32) -> Element {
Element::Arc(a.clone(), b.clone(), r, Major, false, Solid, vec![])
}
@@ -106,9 +101,6 @@ pub fn text(loc: &Loc, txt: &str) -> Element {
Element::Text(loc.clone(), svg_escape(txt))
}
-pub fn blank_text(loc: &Loc) -> Element {
- text(loc, " ".into())
-}
impl Element {
// if this element can reduce the other, return the new reduced element
@@ -296,17 +288,6 @@ impl Element {
svg_text.append(text_node);
SvgElement::Text(svg_text)
}
- Element::Path(_, _, ref d, ref stroke) => {
- let mut path = SvgPath::new().set("d", d.to_owned()).set("fill", "none");
-
- match *stroke {
- Solid => (),
- Dashed => {
- path.assign("stroke-dasharray", (3, 3));
- }
- };
- SvgElement::Path(path)
- }
}
}
}
diff --git a/svgbob/src/focus_char.rs b/svgbob/src/focus_char.rs
index cfadb2b..be43a2a 100644
--- a/svgbob/src/focus_char.rs
+++ b/svgbob/src/focus_char.rs
@@ -254,7 +254,7 @@ 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 {
+ 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());
diff --git a/svgbob/src/fragments.rs b/svgbob/src/fragments.rs
index dc485e2..436ef7d 100644
--- a/svgbob/src/fragments.rs
+++ b/svgbob/src/fragments.rs
@@ -1,7 +1,6 @@
use self::Fragment::{Arc, ArrowLine, Line, OpenCircle, SolidCircle, StartArrowLine};
use point_block::PointBlock;
-use std::cmp::Ordering;
/// These are non-final drawing elements
diff --git a/svgbob/src/grid.rs b/svgbob/src/grid.rs
index d8fb129..c8d933f 100644
--- a/svgbob/src/grid.rs
+++ b/svgbob/src/grid.rs
@@ -5,14 +5,11 @@ use svg_element::SvgElement;
use svg::node::element::SVG;
use svg::Node;
use svg::node::element::{
- Circle as SvgCircle,
Definitions,
- Line as SvgLine,
Marker,
Path as SvgPath,
Rectangle as SvgRect,
Style,
- Text as SvgText,
};
use element::Element;
use pom::TextInput;
@@ -74,30 +71,6 @@ impl Grid {
}
}
- /// reassemble the Grid content into a string
- /// trimming unneeded whitespace to the right for every line
- pub fn to_string(&self) -> String {
- let mut buff = String::new();
- let mut do_ln = false;
- for row in self.index.iter() {
- let mut line = String::new();
- if do_ln {
- //first line don't do \n
- buff.push('\n');
- } else {
- do_ln = true;
- }
- for cell in row {
- if cell == "\0" {
-; //easy make over the full-width hack of the string
- } else {
- line.push_str(cell);
- }
- }
- buff.push_str(&line);
- }
- buff
- }
pub fn rows(&self) -> usize {
self.index.len()
@@ -120,116 +93,7 @@ impl Grid {
}
}
- /// put a text into this location
- /// prepare the grid for this location first
- pub fn put(&mut self, loc: &Loc, s: &str) {
- let new_loc = self.accomodate(loc);
- if let Some(row) = self.index.get_mut(new_loc.y as usize) {
- if let Some(cell) = row.get_mut(new_loc.x as usize) {
- *cell = s.to_owned();
- } else {
- panic!("no cell on this {}", new_loc.x);
- }
- } else {
- panic!("no row on this {}", new_loc.y);
- }
- }
-
- /// insert a new line to at this point
- pub fn insert_line(&mut self, line: usize) {
- self.accomodate(&Loc::new(0, line as i32));
- self.index.insert(line, vec![]);
- }
-
- /// join this line to the previous line
- pub fn join_line(&mut self, line: usize) {
- let mut row = self.index.remove(line);
- self.index
- .get_mut(line - 1)
- .map(|prev| prev.append(&mut row));
- }
-
- /// get the line len at this index
- pub fn get_line_len(&self, line: usize) -> Option<usize> {
- self.index.get(line).map(|r| r.len())
- }
-
- /// prepare the grid to accomodate this loc
- /// if loc.y < 0 => insert abs(loc.y) rows at element 0 to self.index
- /// if loc.y > row.y => append (loc.y-row.y) rows to the self.x
- /// if loc.x < 0 => insert abs(loc.x) columns at element 0, to all rows
- /// if loc.x > row.x => append (loc.x-row.x) elements to the row
- /// returns the corrected location, -1,-1 will be on 0,0
- pub fn accomodate(&mut self, loc: &Loc) -> Loc {
- let mut new_loc = loc.clone();
- if loc.y < 0 {
- let lack_row = (0 - loc.y) as usize; // 0 - -5 = 5
- for _ in 0..lack_row {
- self.index.insert(0, vec![]);
- }
- new_loc.y = 0;
- }
- if loc.x < 0 {
- let lack_cell = (0 - loc.x) as usize;
- let add_cells: String = " ".repeat(lack_cell);
- // insert add_cells to all rows at 0
- for row in self.index.iter_mut() {
- row.insert(0, add_cells.clone());
- }
- new_loc.x = 0;
- }
-
- // check again using the new location adjusted
- // for missing cells
- if new_loc.y >= self.index.len() as i32 {
- let lack_row = new_loc.y - self.index.len() as i32 + 1;
- let mut add_rows: Vec<Vec<String>> = Vec::with_capacity(lack_row as usize);
- for _ in 0..lack_row {
- add_rows.push(vec![]);
- }
- self.index.append(&mut add_rows);
- }
- // IMPORTANT NOTE:
- // using new_loc as adjusted when -negative
- // is important since the priliminary rows inserted
- // are just empty rows
- if let Some(row) = self.index.get_mut(new_loc.y as usize) {
- if new_loc.x >= row.len() as i32 {
- let lack_cell = new_loc.x - row.len() as i32 + 1;
- let mut add_cells: Vec<String> = Vec::with_capacity(lack_cell as usize);
- for _ in 0..lack_cell {
- add_cells.push(" ".to_string()); // use space for empty cells
- }
- (&mut *row).append(&mut add_cells);
- }
- }
- new_loc
- }
-
- /// Vector arranged in row x col
- pub fn get_text_in_range(&self, loc1: &Loc, loc2: &Loc) -> Vec<Vec<Option<&String>>> {
- let x1 = std::cmp::min(loc1.x, loc2.x);
- let y1 = std::cmp::min(loc1.y, loc2.y);
- let x2 = std::cmp::max(loc2.x, loc1.x);
- let y2 = std::cmp::max(loc2.y, loc1.y);
- let mut text = Vec::with_capacity((y2 - y1 + 1) as usize);
- for j in y1..y2 + 1 {
- let mut row = Vec::with_capacity((x2 - x1 + 1) as usize);
- for i in x1..x2 + 1 {
- let loc = Loc::new(i, j);
- let cell = self.get(&loc);
- row.push(cell);
- }
- text.push(row);
- }
- text
- }
- pub fn get_all_text(&self) -> Vec<Vec<Option<&String>>> {
- let loc1 = Loc::new(0, 0);
- let loc2 = Loc::new((self.columns() - 1) as i32, (self.rows() - 1) as i32);
- self.get_text_in_range(&loc1, &loc2)
- }
/// get the focus char at this location
pub fn get_focuschar(&self, loc: &Loc) -> FocusChar {
diff --git a/svgbob/src/lib.rs b/svgbob/src/lib.rs
index 19b7d0e..af0affc 100644
--- a/svgbob/src/lib.rs
+++ b/svgbob/src/lib.rs
@@ -29,7 +29,7 @@
//! </svg>
//!
//!
-//#![deny(warnings)]
+#![deny(warnings)]
#![feature(extern_prelude)]
extern crate pom;
#[cfg(test)]
@@ -38,8 +38,8 @@ extern crate pretty_assertions;
extern crate svg;
extern crate unicode_width;
-use grid::Grid;
-use settings::Settings;
+pub use grid::Grid;
+pub use settings::Settings;
use svg::node::element::SVG;
mod optimizer;
diff --git a/svgbob/src/loc_block.rs b/svgbob/src/loc_block.rs
index e5a28b1..074edef 100644
--- a/svgbob/src/loc_block.rs
+++ b/svgbob/src/loc_block.rs
@@ -1,27 +1,10 @@
-use properties::Characteristic;
-use properties::Signal;
-use element::Element;
-use grid::Grid;
use loc::Loc;
use point::Point;
use settings::Settings;
-
-use block::Block;
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 location::Location;
use point_block::PointBlock;
-use fragments::Fragment;
-use fragments::Fragment::Text;
-
-use properties::Can;
-use properties::Properties;
-use properties::Signal::{Medium, Strong, Weak};
-
-use element::{arc, arrow_line, start_arrow_line, line, open_circle, solid_circle, text};
-
-use properties::Can::{ConnectTo, Is, IsStrongAll};
pub struct LocBlock {
pub loc: Loc,
diff --git a/svgbob/src/location.rs b/svgbob/src/location.rs
index 98f6d93..d339a2b 100644
--- a/svgbob/src/location.rs
+++ b/svgbob/src/location.rs
@@ -1,4 +1,4 @@
-use self::Direction::{Top,Bottom,Left,Right,TopLeft,TopRight,BottomLeft,BottomRight};
+use self::Direction::{Top,Bottom,Left,Right};
use point_block::PointBlock;
use block::{Block::{self,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}};
/// a location in the grid
@@ -33,11 +33,8 @@ impl Location {
Location(vec![(direction, step)])
}
- pub fn go_to(&mut self, direction: Direction) {
- self.jump_to(direction, 1);
- }
- pub fn jump_to(&mut self, direction: Direction, step: usize) {
+ fn jump_to(&mut self, direction: Direction, step: usize) {
self.0.push((direction, step));
}
@@ -47,16 +44,16 @@ impl Location {
loc
}
- pub fn go_top(&self, step: usize) -> Self {
+ fn go_top(&self, step: usize) -> Self {
self.go_jump(Top, step)
}
- pub fn go_left(&self, step: usize) -> Self {
+ fn go_left(&self, step: usize) -> Self {
self.go_jump(Left, step)
}
- pub fn go_bottom(&self, step: usize) -> Self {
+ fn go_bottom(&self, step: usize) -> Self {
self.go_jump(Bottom, step)
}
- pub fn go_right(&self, step: usize) -> Self {
+ fn go_right(&self, step: usize) -> Self {
self.go_jump(Right, step)
}
diff --git a/svgbob/src/optimizer.rs b/svgbob/src/optimizer.rs
index b8e7240..930f158 100644
--- a/svgbob/src/optimizer.rs
+++ b/svgbob/src/optimizer.rs
@@ -1,10 +1,8 @@
use element::Element;
use element::Feature;
use loc::Loc;
-use point::Point;
use settings::Settings;
use element::Stroke;
-use element::ArcFlag;
pub struct Optimizer {
elements: Vec<Vec<Vec<Element>>>,
@@ -56,7 +54,6 @@ impl Optimizer {
let bottom = loc.bottom();
let bottom_right = loc.bottom_right();
let bottom_left = loc.bottom_left();
- let top_right = loc.top_right();
if let Some((all_reduced, elm_index)) = self.reduce(element, &right){
let mut all_consumed:Vec<(Loc, usize)> = vec![];
let mut only_reduced = vec![];
@@ -198,13 +195,8 @@ impl Optimizer {
}
},
Element::Text(_, _) => text.push(elm.clone()),
- Element::Path(_, _, _, _) => {
- merged.push(elm.clone());
- }
}
}
- //merged.push(unify(solid_paths, Stroke::Solid));
- //merged.push(unify(dashed_paths, Stroke::Dashed));
merged.extend(solid_lines);
merged.extend(dashed_lines);
merged.extend(solid_arcs);
@@ -216,61 +208,3 @@ impl Optimizer {
}
}
-/// cramp all paths that can be connected here
-fn _unify(elements: Vec<Element>, stroke: Stroke) -> Element {
- let mut paths = String::new();
- let mut last_loc = None;
- let mut start = None;
- for elm in elements {
- match elm {
- Element::Line(s, e, _, _) => {
- if start.is_none() {
- start = Some(s.clone());
- }
- let match_last_loc = match last_loc {
- Some(last_loc) => s == last_loc,
- None => false,
- };
- if match_last_loc {
- paths.push_str(&format!(" L {} {}", e.x, e.y));
- } else {
- paths.push_str(&format!(" M {} {} L {} {}", s.x, s.y, e.x, e.y));
- }
- last_loc = Some(e.clone());
- }
- Element::Arc(s, e, r, large, sw, _, _) => {
- if start.is_none() {
- start = Some(s.clone());
- }
- let match_last_loc = match last_loc {
- Some(last_loc) => s == last_loc,
- None => false,
- };
- let sweep = if sw { 1 } else { 0 };
- let large = match large {
- ArcFlag::Major => 1,
- ArcFlag::Minor => 0,
- };
- if match_last_loc {
- paths.push_str(&format!(" A {} {} 0 0 {} {} {}", r, r, sweep, e.x, e.y));
- } else {
- paths.push_str(&format!(
- " M {} {} A {} {} 0 {} {} {} {}",
- s.x, s.y, r, r, large, sweep, e.x, e.y
- ));
- }
- last_loc = Some(e.clone());
- }
- _ => panic!("only lines are arc can be unified"),
- }
- }
- let el_start = match start {
- Some(start) => start.clone(),
- None => Point::new(0.0, 0.0),
- };
- let el_end = match last_loc {
- Some(last_loc) => last_loc.clone(),
- None => Point::new(0.0, 0.0),
- };
- Element::Path(el_start, el_end, paths, stroke)
-}
diff --git a/svgbob/src/point.rs b/svgbob/src/point.rs
index b26ac38..106b251 100644
--- a/svgbob/src/point.rs
+++ b/svgbob/src/point.rs
@@ -32,6 +32,6 @@ pub fn collinear(a: &Point, b: &Point, c: &Point) -> bool {
a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) == 0.0
}
-pub fn distance(a: &Point, b: &Point) -> f32{
+pub fn _distance(a: &Point, b: &Point) -> f32{
((b.x - a.x ).powi(2) + (b.y - a.y).powi(2)).sqrt()
}
diff --git a/svgbob/src/point_block.rs b/svgbob/src/point_block.rs
index b656dfd..1488f0a 100644
--- a/svgbob/src/point_block.rs
+++ b/svgbob/src/point_block.rs
@@ -1,7 +1,6 @@
use location::{Location,Direction};
use block::Block;
use std::cmp::Ordering;
-use loc::Loc;
/// An exact point in the grid
/// relative to the focused char
diff --git a/svgbob/src/properties.rs b/svgbob/src/properties.rs
index 9e74bd7..cd0a08b 100644
--- a/svgbob/src/properties.rs
+++ b/svgbob/src/properties.rs
@@ -1,4 +1,4 @@
-use location::{Direction,Location};
+use location::{Location};
use block::Block;
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};
@@ -12,7 +12,6 @@ use box_drawing;
use location::Direction::{Bottom, BottomLeft, BottomRight, Left, Right, Top, TopLeft, TopRight};
use self::Can::{ConnectTo, Is, IsStrongAll};
-use std::cmp::{Ordering,Ord};
/// the strength of signal
/// whether or not connects to the direction
@@ -225,6 +224,8 @@ impl Properties for char {
// \
// |
(vec![A], vec![line(w, m), line(m, a)]),
+ // |-
+ (vec![O], vec![line(o, m)]),
],
})
}
diff --git a/svgbob/src/svg_element.rs b/svgbob/src/svg_element.rs
index 92a6786..f5f65e6 100644
--- a/svgbob/src/svg_element.rs
+++ b/svgbob/src/svg_element.rs
@@ -1,13 +1,8 @@
use std;
use svg::node::element::Circle as SvgCircle;
-use svg::node::element::Definitions;
use svg::node::element::Line as SvgLine;
-use svg::node::element::Marker;
use svg::node::element::Path as SvgPath;
-use svg::node::element::Rectangle as SvgRect;
-use svg::node::element::Style;
use svg::node::element::Text as SvgText;
-use svg::node::element::SVG;
pub enum SvgElement {
Circle(SvgCircle),