diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-07-08 04:59:35 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-07-08 04:59:35 +0800 |
commit | 5358abe1d4b8809fac9e5a845cddbba33bdf3abd (patch) | |
tree | 05d313997099d41310c8e121cfd5962912f7a4b7 | |
parent | 0963aea5052ae8d4905cf0abb51dfe601c12b7e6 (diff) |
Improve implementation of is_intersecting
-rw-r--r-- | svgbob/TODO.md | 1 | ||||
-rw-r--r-- | svgbob/src/buffer/fragment_buffer/fragment.rs | 15 |
2 files changed, 13 insertions, 3 deletions
diff --git a/svgbob/TODO.md b/svgbob/TODO.md index 852008d..6d3ca81 100644 --- a/svgbob/TODO.md +++ b/svgbob/TODO.md @@ -6,6 +6,7 @@ - [x] Make a swap out interface. - useful for detecting broken lines such as - - - and replace it with ~~~~~. This way it will be easier to process by the fragment emitter + - [ ] Fix broken line implementation - [ ] Group traced elements together, then reduce as needed - [x] Add `#` as square start marker for lines - [x] Support for geometric shapes https://en.wikipedia.org/wiki/Geometric_Shapes diff --git a/svgbob/src/buffer/fragment_buffer/fragment.rs b/svgbob/src/buffer/fragment_buffer/fragment.rs index 8eeacac..34685c5 100644 --- a/svgbob/src/buffer/fragment_buffer/fragment.rs +++ b/svgbob/src/buffer/fragment_buffer/fragment.rs @@ -4,12 +4,13 @@ pub use arc::Arc; pub use circle::Circle; pub use line::Line; pub use marker_line::{Marker, MarkerLine}; +use ncollide2d::bounding_volume::BoundingVolume; use ncollide2d::query::PointQuery; use ncollide2d::{ bounding_volume::AABB, math::Isometry, query::{proximity, Proximity}, - shape::{Polyline, Segment}, + shape::{Polyline, Segment, Shape}, }; pub use polygon::{Polygon, PolygonTag}; pub use rect::Rect; @@ -293,11 +294,11 @@ impl Fragment { } pub fn hit(&self, start: Point, end: Point) -> bool { - self.is_intersecting(AABB::new(*start, *end)) + self.is_intersecting(&AABB::new(*start, *end)) } /// check if this fragment is intersecting with this bounding box - pub fn is_intersecting(&self, bbox: AABB<f32>) -> bool { + pub fn is_intersecting(&self, bbox: &AABB<f32>) -> bool { let bbox: Polyline<f32> = Polyline::new( vec![ *bbox.mins(), @@ -320,6 +321,7 @@ impl Fragment { == Proximity::Intersecting } Fragment::Circle(circle) => { + // do not include the small circles let polyline: Polyline<f32> = circle.clone().into(); proximity(&identity, &polyline, &identity, &bbox, 0.0) == Proximity::Intersecting @@ -328,6 +330,13 @@ impl Fragment { } } + /// check if this fragment can be contain in the specified bounding box `bbox` + pub fn is_inside(&self, bbox: &AABB<f32>) -> bool { + let (start, end) = self.bounds(); + let frag_bound = AABB::new(*start, *end); + bbox.contains(&frag_bound) + } + /// recompute the end points of this fragment /// offset by the cell location pub fn absolute_position(&self, cell: Cell) -> Self { |