summaryrefslogtreecommitdiffstats
path: root/svgbob/src/point.rs
diff options
context:
space:
mode:
Diffstat (limited to 'svgbob/src/point.rs')
-rw-r--r--svgbob/src/point.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/svgbob/src/point.rs b/svgbob/src/point.rs
index 26a67ea..18a8015 100644
--- a/svgbob/src/point.rs
+++ b/svgbob/src/point.rs
@@ -1,5 +1,6 @@
use crate::buffer::CellGrid;
use crate::util;
+use crate::Cell;
use nalgebra::{Point2, Vector2};
use std::{
cmp::Ordering,
@@ -73,6 +74,27 @@ impl Point {
let u = units * CellGrid::unit_y();
Self::new(self.x + t, self.y + u)
}
+
+ /// test if the point lie on an edge of a cell
+ /// that is the fractional part is 0.0
+ pub fn is_edge_x(&self) -> bool {
+ self.x.fract() == 0.0
+ }
+ pub fn is_edge_y(&self) -> bool {
+ (self.y / 2.0).fract() == 0.0
+ }
+ pub fn is_mid_x(&self) -> bool {
+ self.x.fract() == 0.5
+ }
+ pub fn is_mid_y(&self) -> bool {
+ (self.y / 2.0).fract() == 0.5
+ }
+
+ /// return the cell where this point fall to
+ pub fn cell(&self) -> Cell {
+ let (cell, _) = Cell::snap_point(*self);
+ cell
+ }
}
impl From<Point2<f32>> for Point {