summaryrefslogtreecommitdiffstats
path: root/svgbob/src/buffer/cell_buffer
diff options
context:
space:
mode:
Diffstat (limited to 'svgbob/src/buffer/cell_buffer')
-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
3 files changed, 76 insertions, 22 deletions
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]));