summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2020-02-14 12:47:57 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2020-02-14 12:47:57 +0800
commit99e379b4eb0beffdbb27384a5ebc70b4c8f8993b (patch)
tree53e426083332d9169fce8e9528c7039569b9edb6
parentd5116c36e40df935f49eb74a9d5f9659e96c0717 (diff)
cargo fmt
-rw-r--r--svgbob/examples/demo.rs2
-rw-r--r--svgbob/src/buffer/cell_buffer/cell.rs73
-rw-r--r--svgbob/src/buffer/cell_buffer/contacts.rs17
-rw-r--r--svgbob/src/buffer/cell_buffer/endorse.rs8
-rw-r--r--svgbob/src/buffer/fragment_buffer.rs6
-rw-r--r--svgbob/src/buffer/fragment_buffer/fragment/line.rs62
-rw-r--r--svgbob/src/buffer/fragment_buffer/fragment/marker_line.rs14
-rw-r--r--svgbob/src/buffer/fragment_buffer/fragment/polygon.rs30
-rw-r--r--svgbob/src/buffer/fragment_buffer/fragment/rect.rs22
-rw-r--r--svgbob/src/buffer/fragment_buffer/fragment_tree.rs124
-rw-r--r--svgbob/src/util.rs78
11 files changed, 310 insertions, 126 deletions
diff --git a/svgbob/examples/demo.rs b/svgbob/examples/demo.rs
index 4057b7a..5c8a8b8 100644
--- a/svgbob/examples/demo.rs
+++ b/svgbob/examples/demo.rs
@@ -6,7 +6,7 @@ fn main() -> io::Result<()> {
let art = include_str!("../test_data/demo.bob");
let t1 = Instant::now();
fs::create_dir_all("out")?;
- fs::write("out/demo1.svg", svgbob::to_svg(art))?;
+ fs::write("out/demo.svg", svgbob::to_svg(art))?;
println!("took {}ms", t1.elapsed().as_millis());
Ok(())
}
diff --git a/svgbob/src/buffer/cell_buffer/cell.rs b/svgbob/src/buffer/cell_buffer/cell.rs
index ce2c85c..99bdade 100644
--- a/svgbob/src/buffer/cell_buffer/cell.rs
+++ b/svgbob/src/buffer/cell_buffer/cell.rs
@@ -56,7 +56,9 @@ macro_rules! cell_grid {
}
impl Cell {
- cell_grid!(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);
+ cell_grid!(
+ 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
+ );
pub fn new(x: i32, y: i32) -> Self {
Cell { x, y }
@@ -81,8 +83,10 @@ impl Cell {
}
pub fn snap_group(points: &[Point]) -> Self {
- let snaps: Vec<(Self, Point)> =
- points.iter().map(|point| Self::snap_point(*point)).collect();
+ let snaps: Vec<(Self, Point)> = points
+ .iter()
+ .map(|point| Self::snap_point(*point))
+ .collect();
let (cells, _snap_points): (Vec<Self>, Vec<Point>) = snaps.into_iter().unzip();
let min_cell: Self = cells.into_iter().min().expect("should have a min cell");
min_cell
@@ -118,9 +122,14 @@ impl Cell {
/// the bounding box of this cell
#[inline]
fn bounding_box(&self) -> AABB<f32> {
- let start = Point::new(self.x as f32 * Self::width(), self.y as f32 * Self::height());
- let end =
- Point::new((self.x + 1) as f32 * Self::width(), (self.y + 1) as f32 * Self::height());
+ let start = Point::new(
+ self.x as f32 * Self::width(),
+ self.y as f32 * Self::height(),
+ );
+ let end = Point::new(
+ (self.x + 1) as f32 * Self::width(),
+ (self.y + 1) as f32 * Self::height(),
+ );
AABB::new(*start, *end)
}
@@ -159,7 +168,13 @@ impl Cell {
pub fn is_intersected(&self, start: Point, end: Point) -> bool {
let pl = self.polyline();
let segment = Segment::new(*start, *end);
- let prox = proximity(&Isometry::identity(), &pl, &Isometry::identity(), &segment, 0.0);
+ let prox = proximity(
+ &Isometry::identity(),
+ &pl,
+ &Isometry::identity(),
+ &segment,
+ 0.0,
+ );
prox == Proximity::Intersecting
}
@@ -193,7 +208,8 @@ impl Cell {
}
pub fn clip_line_snap(&self, start: Point, end: Point) -> Option<(Point, Point)> {
- self.clip_line(start, end).map(|(s, e)| (Self::snap(s), Self::snap(e)))
+ self.clip_line(start, end)
+ .map(|(s, e)| (Self::snap(s), Self::snap(e)))
}
/// clip line then localize the points and snap to the nearest cell grid intersection
@@ -205,47 +221,70 @@ impl Cell {
/// The cell at the top left of this cell
#[inline]
pub fn top_left(&self) -> Self {
- Cell { x: self.x - 1, y: self.y - 1 }
+ Cell {
+ x: self.x - 1,
+ y: self.y - 1,
+ }
}
#[inline]
pub fn top(&self) -> Self {
- Cell { x: self.x, y: self.y - 1 }
+ Cell {
+ x: self.x,
+ y: self.y - 1,
+ }
}
#[inline]
pub fn top_right(&self) -> Self {
- Cell { x: self.x + 1, y: self.y - 1 }
+ Cell {
+ x: self.x + 1,
+ y: self.y - 1,
+ }
}
/// The cell at the left of this cell
#[inline]
pub fn left(&self) -> Self {
- Cell { x: self.x - 1, y: self.y }
+ Cell {
+ x: self.x - 1,
+ y: self.y,
+ }
}
#[inline]
pub fn right(&self) -> Self {
- Cell { x: self.x + 1, y: self.y }
+ Cell {
+ x: self.x + 1,
+ y: self.y,
+ }
}
#[inline]
pub fn bottom_left(&self) -> Self {
- Cell { x: self.x - 1, y: self.y + 1 }
+ Cell {
+ x: self.x - 1,
+ y: self.y + 1,
+ }
}
#[inline]
pub fn bottom(&self) -> Self {
- Cell { x: self.x, y: self.y + 1 }
+ Cell {
+ x: self.x,
+ y: self.y + 1,
+ }
}
#[inline]
pub fn bottom_right(&self) -> Self {
- Cell { x: self.x + 1, y: self.y + 1 }
+ Cell {
+ x: self.x + 1,
+ y: self.y + 1,
+ }
}
}
-
/// rearrange the bound of 2 cells
pub fn rearrange_bound(bound1: Cell, bound2: Cell) -> (Cell, Cell) {
let min_x = cmp::min(bound1.x, bound2.x);
diff --git a/svgbob/src/buffer/cell_buffer/contacts.rs b/svgbob/src/buffer/cell_buffer/contacts.rs
index 3b1d2a1..cb72770 100644
--- a/svgbob/src/buffer/cell_buffer/contacts.rs
+++ b/svgbob/src/buffer/cell_buffer/contacts.rs
@@ -31,11 +31,17 @@ impl Contacts {
/// We use `.rev()` on this list of fragment since it has a high change of matching at the last
/// added fragment of the next fragments to be checked.
pub(crate) fn is_contacting_frag(&self, other_frag: &Fragment) -> bool {
- self.as_ref().iter().rev().any(|frag| frag.is_contacting(other_frag))
+ self.as_ref()
+ .iter()
+ .rev()
+ .any(|frag| frag.is_contacting(other_frag))
}
pub(crate) fn is_contacting(&self, other: &Self) -> bool {
- other.as_ref().iter().any(|other_frag| self.is_contacting_frag(other_frag))
+ other
+ .as_ref()
+ .iter()
+ .any(|other_frag| self.is_contacting_frag(other_frag))
}
/// Endorse if the fragments in this group
@@ -53,7 +59,12 @@ impl Contacts {
}
pub(crate) fn absolute_position(&self, cell: Cell) -> Self {
- Contacts(self.as_ref().iter().map(|frag| frag.absolute_position(cell)).collect())
+ Contacts(
+ self.as_ref()
+ .iter()
+ .map(|frag| frag.absolute_position(cell))
+ .collect(),
+ )
}
}
diff --git a/svgbob/src/buffer/cell_buffer/endorse.rs b/svgbob/src/buffer/cell_buffer/endorse.rs
index 6288729..8f53fa3 100644
--- a/svgbob/src/buffer/cell_buffer/endorse.rs
+++ b/svgbob/src/buffer/cell_buffer/endorse.rs
@@ -184,8 +184,12 @@ mod tests {
println!("group: {:#?}", group);
assert_eq!(group, vec![(0, 2), (1, 3)]);
- let rect =
- endorse_rect(&vec![line_ae.clone(), line_au.clone(), line_uy.clone(), line_ey.clone()]);
+ let rect = endorse_rect(&vec![
+ line_ae.clone(),
+ line_au.clone(),
+ line_uy.clone(),
+ line_ey.clone(),
+ ]);
assert!(rect.is_some());
assert_eq!(rect, Some(Rect::new(a, y, false, false)));
assert!(is_rect(&vec![line_ae, line_au, line_uy, line_ey]));
diff --git a/svgbob/src/buffer/fragment_buffer.rs b/svgbob/src/buffer/fragment_buffer.rs
index da3ba46..7f3c780 100644
--- a/svgbob/src/buffer/fragment_buffer.rs
+++ b/svgbob/src/buffer/fragment_buffer.rs
@@ -150,7 +150,11 @@ impl FragmentBuffer {
fn merge_recursive(fragments: Vec<Fragment>) -> Vec<Fragment> {
let original_len = fragments.len();
let merged = Self::second_pass_merge(fragments);
- if merged.len() < original_len { Self::merge_recursive(merged) } else { merged }
+ if merged.len() < original_len {
+ Self::merge_recursive(merged)
+ } else {
+ merged
+ }
}
fn second_pass_merge(fragments: Vec<Fragment>) -> Vec<Fragment> {
diff --git a/svgbob/src/buffer/fragment_buffer/fragment/line.rs b/svgbob/src/buffer/fragment_buffer/fragment/line.rs
index 15b7326..7e654c9 100644
--- a/svgbob/src/buffer/fragment_buffer/fragment/line.rs
+++ b/svgbob/src/buffer/fragment_buffer/fragment/line.rs
@@ -39,7 +39,6 @@ pub struct Line {
pub is_broken: bool,
}
-
impl Direction {
/// diamon matches alongside for everything.
pub(crate) fn is_along_side(&self, tags: &[PolygonTag]) -> bool {
@@ -86,14 +85,22 @@ impl Line {
/// creates a new line and reorder the points swapping the end points if necessary
/// such that the start is the most top-left and end point is the most bottom-right
pub(in crate) fn new(start: Point, end: Point, is_broken: bool) -> Self {
- let mut line = Line { start, end, is_broken };
+ let mut line = Line {
+ start,
+ end,
+ is_broken,
+ };
line.sort_reorder_end_points();
line
}
/// creates a new line, but don't reorder the points
pub(in crate) fn new_noswap(start: Point, end: Point, is_broken: bool) -> Self {
- Line { start, end, is_broken }
+ Line {
+ start,
+ end,
+ is_broken,
+ }
}
/// reorder the end points swap end points such that
@@ -363,6 +370,9 @@ impl Line {
is_along_side && (is_close_start_point || is_close_end_point)
}
+ /// TODO: the get_marker function don't take into account the direction
+ /// of the line from start to end. The direction is not followed.
+ ///
/// merge this line to the marker line
pub(crate) fn merge_line_polygon(&self, polygon: &Polygon) -> Option<Fragment> {
if self.can_merge_polygon(polygon) {
@@ -430,9 +440,13 @@ impl Line {
panic!("There is no endpoint of the line is that close to the arrow");
};
-
- let marker_line =
- marker_line(new_line.start, new_line.end, new_line.is_broken, None, marker);
+ let marker_line = marker_line(
+ new_line.start,
+ new_line.end,
+ new_line.is_broken,
+ None,
+ marker,
+ );
Some(marker_line)
}
@@ -520,7 +534,11 @@ impl Line {
}
pub(crate) fn align(&self) -> Self {
- Line { start: self.start.align(), end: self.end.align(), is_broken: self.is_broken }
+ Line {
+ start: self.start.align(),
+ end: self.end.align(),
+ is_broken: self.is_broken,
+ }
}
/// extend the line by a length added to the end point
@@ -604,27 +622,45 @@ mod tests {
fn test_extend_line() {
let line1 = Line::new_noswap(Point::new(0.0, 0.0), Point::new(10.0, 0.0), false);
let extended = line1.extend(1.0);
- assert_eq!(extended, Line::new(Point::new(0.0, 0.0), Point::new(11.0, 0.0), false));
+ assert_eq!(
+ extended,
+ Line::new(Point::new(0.0, 0.0), Point::new(11.0, 0.0), false)
+ );
let extended2 = line1.extend(2.0);
- assert_eq!(extended2, Line::new(Point::new(0.0, 0.0), Point::new(12.0, 0.0), false));
+ assert_eq!(
+ extended2,
+ Line::new(Point::new(0.0, 0.0), Point::new(12.0, 0.0), false)
+ );
}
#[test]
fn test_extend_line_start() {
let line1 = Line::new_noswap(Point::new(0.0, 0.0), Point::new(10.0, 0.0), false);
let extended = line1.extend_start(1.0);
- assert_eq!(extended, Line::new(Point::new(-1.0, 0.0), Point::new(10.0, 0.0), false));
+ assert_eq!(
+ extended,
+ Line::new(Point::new(-1.0, 0.0), Point::new(10.0, 0.0), false)
+ );
let extended2 = line1.extend_start(2.0);
- assert_eq!(extended2, Line::new(Point::new(-2.0, 0.0), Point::new(10.0, 0.0), false));
+ assert_eq!(
+ extended2,
+ Line::new(Point::new(-2.0, 0.0), Point::new(10.0, 0.0), false)
+ );
}
#[test]
fn test_extend_line_vertical() {
let line1 = Line::new_noswap(Point::new(0.0, 0.0), Point::new(0.0, 10.0), false);
let extended = line1.extend(1.0);
- assert_eq!(extended, Line::new(Point::new(0.0, 0.0), Point::new(0.0, 11.0), false));
+ assert_eq!(
+ extended,
+ Line::new(Point::new(0.0, 0.0), Point::new(0.0, 11.0), false)
+ );
let extended2 = line1.extend(2.0);
- assert_eq!(extended2, Line::new(Point::new(0.0, 0.0), Point::new(0.0, 12.0), false));
+ assert_eq!(
+ extended2,
+ Line::new(Point::new(0.0, 0.0), Point::new(0.0, 12.0), false)
+ );
}
#[test]
diff --git a/svgbob/src/buffer/fragment_buffer/fragment/marker_line.rs b/svgbob/src/buffer/fragment_buffer/fragment/marker_line.rs
index df3fd07..5c446af 100644
--- a/svgbob/src/buffer/fragment_buffer/fragment/marker_line.rs
+++ b/svgbob/src/buffer/fragment_buffer/fragment/marker_line.rs
@@ -34,7 +34,6 @@ impl Marker {
}
}
-
#[derive(Debug, Clone, PartialEq)]
pub struct MarkerLine {
pub line: Line,
@@ -50,7 +49,11 @@ impl MarkerLine {
start_marker: Option<Marker>,
end_marker: Option<Marker>,
) -> Self {
- MarkerLine { line: Line::new_noswap(a, b, is_broken), start_marker, end_marker }
+ MarkerLine {
+ line: Line::new_noswap(a, b, is_broken),
+ start_marker,
+ end_marker,
+ }
}
pub fn absolute_position(&self, cell: Cell) -> Self {
@@ -159,11 +162,14 @@ impl fmt::Display for Marker {
impl fmt::Display for MarkerLine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{} {:?} {:?}", self.line, self.start_marker, self.end_marker)
+ write!(
+ f,
+ "{} {:?} {:?}",
+ self.line, self.start_marker, self.end_marker
+ )
}
}
-
impl Into<Node<()>> for MarkerLine {
fn into(self) -> Node<()> {
let mut node: Node<()> = self.line.into();
diff --git a/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs b/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs
index 0439eeb..ffafdec 100644
--- a/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs
+++ b/svgbob/src/buffer/fragment_buffer/fragment/polygon.rs
@@ -69,17 +69,33 @@ impl PolygonTag {
impl Polygon {
pub(in crate) fn new(points: Vec<Point>, is_filled: bool, tags: Vec<PolygonTag>) -> Self {
- Polygon { points, is_filled, tags }
+ Polygon {
+ points,
+ is_filled,
+ tags,
+ }
}
pub(in crate) fn absolute_position(&self, cell: Cell) -> Self {
- let points: Vec<Point> = self.points.iter().map(|p| cell.absolute_position(*p)).collect();
- Polygon { points, is_filled: self.is_filled, tags: self.tags.clone() }
+ let points: Vec<Point> = self
+ .points
+ .iter()
+ .map(|p| cell.absolute_position(*p))
+ .collect();
+ Polygon {
+ points,
+ is_filled: self.is_filled,
+ tags: self.tags.clone(),
+ }
}
pub(in crate) fn scale(&self, scale: f32) -> Self {
let points: Vec<Point> = self.points.iter().map(|p| p.scale(scale)).collect();
- Polygon { points, is_filled: self.is_filled, tags: self.tags.clone() }
+ Polygon {
+ points,
+ is_filled: self.is_filled,
+ tags: self.tags.clone(),
+ }
}
fn first(&self) -> Point {
@@ -110,7 +126,11 @@ impl fmt::Display for Polygon {
write!(
f,
"P {}",
- self.points.iter().map(|p| p.to_string()).collect::<Vec<String>>().join(" ")
+ self.points
+ .iter()
+ .map(|p| p.to_string())
+ .collect::<Vec<String>>()
+ .join(" ")
)
}
}
diff --git a/svgbob/src/buffer/fragment_buffer/fragment/rect.rs b/svgbob/src/buffer/fragment_buffer/fragment/rect.rs
index 9adedfb..d716dc7 100644
--- a/svgbob/src/buffer/fragment_buffer/fragment/rect.rs
+++ b/svgbob/src/buffer/fragment_buffer/fragment/rect.rs
@@ -23,7 +23,13 @@ impl Rect {
/// creates a new rect and reorder the points swapping the end points if necessary
/// such that the start is the most top-left and end point is the most bottom-right
pub(in crate) fn new(start: Point, end: Point, is_filled: bool, is_broken: bool) -> Self {
- let mut rect = Rect { start, end, is_filled, radius: None, is_broken };
+ let mut rect = Rect {
+ start,
+ end,
+ is_filled,
+ radius: None,
+ is_broken,
+ };
rect.sort_reorder_end_points();
rect
}
@@ -35,7 +41,13 @@ impl Rect {
radius: f32,
is_broken: bool,
) -> Self {
- let mut rect = Rect { start, end, is_filled, radius: Some(radius), is_broken };
+ let mut rect = Rect {
+ start,
+ end,
+ is_filled,
+ radius: Some(radius),
+ is_broken,
+ };
rect.sort_reorder_end_points();
rect
}
@@ -109,7 +121,11 @@ impl Into<Node<()>> for Rect {
("filled", self.is_filled),
("nofill", !self.is_filled),
]),
- if let Some(radius) = self.radius { rx(radius) } else { rx(0) },
+ if let Some(radius) = self.radius {
+ rx(radius)
+ } else {
+ rx(0)
+ },
],
vec![],
)
diff --git a/svgbob/src/buffer/fragment_buffer/fragment_tree.rs b/svgbob/src/buffer/fragment_buffer/fragment_tree.rs
index 84c7e8b..863dfad 100644
--- a/svgbob/src/buffer/fragment_buffer/fragment_tree.rs
+++ b/svgbob/src/buffer/fragment_buffer/fragment_tree.rs
@@ -15,7 +15,11 @@ pub struct FragmentTree {
impl FragmentTree {
pub(crate) fn new(fragment: Fragment) -> Self {
- FragmentTree { fragment, css_tag: vec![], enclosing: vec![] }
+ FragmentTree {
+ fragment,
+ css_tag: vec![],
+ enclosing: vec![],
+ }
}
fn can_fit(&self, other: &Self) -> bool {
@@ -62,23 +66,31 @@ impl FragmentTree {
}
pub(crate) fn enclose_fragments(fragments: Vec<Fragment>) -> Vec<Self> {
- let fragment_trees: Vec<Self> =
- fragments.into_iter().map(|frag| FragmentTree::new(frag)).collect();
+ let fragment_trees: Vec<Self> = fragments
+ .into_iter()
+ .map(|frag| FragmentTree::new(frag))
+ .collect();
Self::enclose_recursive(fragment_trees)
}
pub(crate) fn enclose_recursive(fragment_trees: Vec<Self>) -> Vec<Self> {
let original_len = fragment_trees.len();
let merged = Self::second_pass_enclose(fragment_trees);
- if merged.len() < original_len { Self::enclose_recursive(merged) } else { merged }
+ if merged.len() < original_len {
+ Self::enclose_recursive(merged)
+ } else {
+ merged
+ }
}
/// make all the fragments a fragment tree and try to fit each other
fn second_pass_enclose(fragment_trees: Vec<Self>) -> Vec<Self> {
let mut new_trees: Vec<Self> = vec![];
for frag_tree in fragment_trees {
- let is_enclosed =
- new_trees.iter_mut().rev().any(|new_tree| new_tree.enclose_deep_first(&frag_tree));
+ let is_enclosed = new_trees
+ .iter_mut()
+ .rev()
+ .any(|new_tree| new_tree.enclose_deep_first(&frag_tree));
if !is_enclosed {
new_trees.push(frag_tree);
}
@@ -102,11 +114,13 @@ impl FragmentTree {
/// css class of the contain fragment
pub(crate) fn fragments_to_node(fragments: Vec<Fragment>) -> Vec<Node<()>> {
let fragment_trees: Vec<FragmentTree> = Self::enclose_fragments(fragments);
- fragment_trees.into_iter().flat_map(|frag_tree| frag_tree.into_nodes()).collect()
+ fragment_trees
+ .into_iter()
+ .flat_map(|frag_tree| frag_tree.into_nodes())
+ .collect()
}
}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -119,10 +133,18 @@ mod tests {
#[test]
fn test_enclose() {
- let mut rect1 =
- FragmentTree::new(rect(Point::new(0.0, 0.0), Point::new(10.0, 10.0), false, false));
- let rect2 =
- FragmentTree::new(rect(Point::new(1.0, 1.0), Point::new(9.0, 9.0), false, false));
+ let mut rect1 = FragmentTree::new(rect(
+ Point::new(0.0, 0.0),
+ Point::new(10.0, 10.0),
+ false,
+ false,
+ ));
+ let rect2 = FragmentTree::new(rect(
+ Point::new(1.0, 1.0),
+ Point::new(9.0, 9.0),
+ false,
+ false,
+ ));
let text1 = FragmentTree::new(Fragment::CellText(CellText::new(
Cell::new(2, 2),
"{doc}".to_string(),
@@ -152,25 +174,28 @@ mod tests {
let fragment_trees = FragmentTree::enclose_fragments(fragments);
dbg!(&fragment_trees);
- assert_eq!(fragment_trees, vec![
- FragmentTree {
- fragment: rect(Point::new(0.0, 0.0), Point::new(10.0, 10.0), false, false),
- css_tag: vec![],
- enclosing: vec![FragmentTree {
- fragment: rect(Point::new(1.0, 1.0), Point::new(9.0, 9.0), false, false),
- css_tag: vec!["doc".to_string()],
+ assert_eq!(
+ fragment_trees,
+ vec![
+ FragmentTree {
+ fragment: rect(Point::new(0.0, 0.0), Point::new(10.0, 10.0), false, false),
+ css_tag: vec![],
+ enclosing: vec![FragmentTree {
+ fragment: rect(Point::new(1.0, 1.0), Point::new(9.0, 9.0), false, false),
+ css_tag: vec!["doc".to_string()],
+ enclosing: vec![],
+ },],
+ },
+ FragmentTree {
+ fragment: Fragment::CellText(CellText::new(
+ Cell::new(2, 2),
+ "This is a hello world!".to_string(),
+ )),
+ css_tag: vec![],
enclosing: vec![],
- },],
- },
- FragmentTree {
- fragment: Fragment::CellText(CellText::new(
- Cell::new(2, 2),
- "This is a hello world!".to_string(),
- )),
- css_tag: vec![],
- enclosing: vec![],
- },
- ]);
+ },
+ ]
+ );
}
#[test]
@@ -187,24 +212,27 @@ mod tests {
let fragment_trees = FragmentTree::enclose_fragments(fragments);
dbg!(&fragment_trees);
- assert_eq!(fragment_trees, vec![
- FragmentTree {
- fragment: rect(Point::new(0.0, 0.0), Point::new(10.0, 10.0), false, false),
- css_tag: vec![],
- enclosing: vec![FragmentTree {
- fragment: rect(Point::new(1.0, 1.0), Point::new(9.0, 9.0), false, false),
- css_tag: vec!["doc".to_string()],
+ assert_eq!(
+ fragment_trees,
+ vec![
+ FragmentTree {
+ fragment: rect(Point::new(0.0, 0.0), Point::new(10.0, 10.0), false, false),
+ css_tag: vec![],
+ enclosing: vec![FragmentTree {
+ fragment: rect(Point::new(1.0, 1.0), Point::new(9.0, 9.0), false, false),
+ css_tag: vec!["doc".to_string()],
+ enclosing: vec![],
+ },],
+ },
+ FragmentTree {
+ fragment: Fragment::CellText(CellText::new(
+ Cell::new(2, 2),
+ "This is a hello world!".to_string(),
+ )),
+ css_tag: vec![],
enclosing: vec![],
- },],
- },
- FragmentTree {
- fragment: Fragment::CellText(CellText::new(
- Cell::new(2, 2),
- "This is a hello world!".to_string(),
- )),
- css_tag: vec![],
- enclosing: vec![],
- },
- ]);
+ },
+ ]
+ );
}
}
diff --git a/svgbob/src/util.rs b/svgbob/src/util.rs
index 6e11735..27d1950 100644
--- a/svgbob/src/util.rs
+++ b/svgbob/src/util.rs
@@ -55,7 +55,11 @@ pub fn clip_line(aabb: &AABB<f32>, start: Point, end: Point) -> Option<(Point, P
if aabb.contains_point(identity, &end) {
clip_end = end;
}
- if clip_start == clip_end { None } else { Some((clip_start, clip_end)) }
+ if clip_start == clip_end {
+ None
+ } else {
+ Some((clip_start, clip_end))
+ }
} else {
None
}
@@ -71,7 +75,6 @@ pub fn pad(v: f32) -> f32 {
if v > 0.0 { v.ceil() } else { v.floor() }
}
-
/// this is parser module which provides parsing for identifier for
/// extracting the css tag of inside of a shape fragment
pub mod parser {
@@ -153,7 +156,6 @@ pub mod parser {
one_of(" \t\r\n").repeat(0..).discard()
}
-
/// a valid identifier
pub(crate) fn ident<'a>() -> Parser<'a, char, String> {
(is_a(alpha_or_underscore) + is_a(alphanum_or_underscore).repeat(0..))
@@ -222,7 +224,6 @@ pub mod parser {
css_legend_with_padding().parse(input)
}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -252,10 +253,13 @@ pub mod parser {
let input_chars: Vec<char> = input.chars().collect();
let css = css_style_list().parse(&input_chars).expect("should parse");
println!("css: {:?}", css);
- assert_eq!(css, vec![
- ("a".to_string(), "fill:blue; stroke:red;".to_string()),
- ("b".to_string(), "fill:red; stroke:black;".to_string())
- ]);
+ assert_eq!(
+ css,
+ vec![
+ ("a".to_string(), "fill:blue; stroke:red;".to_string()),
+ ("b".to_string(), "fill:red; stroke:black;".to_string())
+ ]
+ );
}
#[test]
@@ -264,12 +268,17 @@ pub mod parser {
a = {fill:blue; stroke:red;}\n\
b = {fill:red; stroke:black;}";
let input_chars: Vec<char> = input.chars().collect();
- let css = css_legend_with_padding().parse(&input_chars).expect("should parse");
+ let css = css_legend_with_padding()
+ .parse(&input_chars)
+ .expect("should parse");
println!("css: {:?}", css);
- assert_eq!(css, vec![
- ("a".to_string(), "fill:blue; stroke:red;".to_string()),
- ("b".to_string(), "fill:red; stroke:black;".to_string())
- ]);
+ assert_eq!(
+ css,
+ vec![
+ ("a".to_string(), "fill:blue; stroke:red;".to_string()),
+ ("b".to_string(), "fill:red; stroke:black;".to_string())
+ ]
+ );
}
#[test]
@@ -278,12 +287,17 @@ pub mod parser {
big_circle = {fill:blue;}\n\
red = {stroke:red;}\n\n\n";
let input_chars: Vec<char> = input.chars().collect();
- let css = css_legend_with_padding().parse(&input_chars).expect("should parse");
+ let css = css_legend_with_padding()
+ .parse(&input_chars)
+ .expect("should parse");
println!("css: {:?}", css);
- assert_eq!(css, vec![
- ("big_circle".to_string(), "fill:blue;".to_string()),
- ("red".to_string(), "stroke:red;".to_string())
- ]);
+ assert_eq!(
+ css,
+ vec![
+ ("big_circle".to_string(), "fill:blue;".to_string()),
+ ("red".to_string(), "stroke:red;".to_string())
+ ]
+ );
}
#[test]
fn test_css_legend3() {
@@ -291,12 +305,17 @@ pub mod parser {
big_circle = {fill:blue;}\n\
red = {stroke:red;}\n";
let input_chars: Vec<char> = input.chars().collect();
- let css = css_legend_with_padding().parse(&input_chars).expect("should parse");
+ let css = css_legend_with_padding()
+ .parse(&input_chars)
+ .expect("should parse");
println!("css: {:?}", css);
- assert_eq!(css, vec![
- ("big_circle".to_string(), "fill:blue;".to_string()),
- ("red".to_string(), "stroke:red;".to_string())
- ]);
+ assert_eq!(
+ css,
+ vec![
+ ("big_circle".to_string(), "fill:blue;".to_string()),
+ ("red".to_string(), "stroke:red;".to_string())
+ ]
+ );
}
#[test]
@@ -308,10 +327,13 @@ pub mod parser {
let input_chars: Vec<char> = input.chars().collect();
let css = css_legend().parse(&input_chars).expect("should parse");
println!("css: {:?}", css);
- assert_eq!(css, vec![
- ("a".to_string(), "fill:blue; stroke:red;".to_string()),
- ("b".to_string(), "fill:red; stroke:black;".to_string())
- ]);
+ assert_eq!(
+ css,
+ vec![
+ ("a".to_string(), "fill:blue; stroke:red;".to_string()),
+ ("b".to_string(), "fill:red; stroke:black;".to_string())
+ ]
+ );
}
#[test]
@@ -369,8 +391,6 @@ mod tests {
use super::*;
use crate::buffer::CellGrid;
-
-
#[test]
fn test_collinear() {
let a = CellGrid::a();