From f277e1c05289b9a2c162dcc0fda7ea32eb4746f9 Mon Sep 17 00:00:00 2001 From: indierusty Date: Wed, 20 Aug 2025 10:06:50 +0530 Subject: [PATCH] use loose bbox for intersection --- .../gcore/src/vector/algorithms/intersection.rs | 6 +++--- node-graph/gcore/src/vector/algorithms/util.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/node-graph/gcore/src/vector/algorithms/intersection.rs b/node-graph/gcore/src/vector/algorithms/intersection.rs index 222033e97f..c751c88e23 100644 --- a/node-graph/gcore/src/vector/algorithms/intersection.rs +++ b/node-graph/gcore/src/vector/algorithms/intersection.rs @@ -1,4 +1,4 @@ -use super::contants::MIN_SEPARATION_VALUE; +use super::{contants::MIN_SEPARATION_VALUE, util::pathseg_loose_bbox}; use kurbo::{BezPath, DEFAULT_ACCURACY, ParamCurve, PathSeg, Shape}; /// Calculates the intersection points the bezpath has with a given segment and returns a list of `(usize, f64)` tuples, @@ -63,8 +63,8 @@ pub fn subsegment_intersections(segment1: PathSeg, min_t1: f64, max_t1: f64, seg /// by splitting the segment recursively until the size of the subsegment's bounding box is smaller than the accuracy. #[allow(clippy::too_many_arguments)] fn segment_intersections_inner(segment1: PathSeg, min_t1: f64, max_t1: f64, segment2: PathSeg, min_t2: f64, max_t2: f64, accuracy: f64, intersections: &mut Vec<(f64, f64)>) { - let bbox1 = segment1.subsegment(min_t1..max_t1).bounding_box(); - let bbox2 = segment2.subsegment(min_t2..max_t2).bounding_box(); + let bbox1 = pathseg_loose_bbox(segment1.subsegment(min_t1..max_t1)); + let bbox2 = pathseg_loose_bbox(segment2.subsegment(min_t2..max_t2)); let mid_t1 = (min_t1 + max_t1) / 2.; let mid_t2 = (min_t2 + max_t2) / 2.; diff --git a/node-graph/gcore/src/vector/algorithms/util.rs b/node-graph/gcore/src/vector/algorithms/util.rs index 0c2eacf7ce..d91bfbbff9 100644 --- a/node-graph/gcore/src/vector/algorithms/util.rs +++ b/node-graph/gcore/src/vector/algorithms/util.rs @@ -1,5 +1,20 @@ use glam::DVec2; -use kurbo::{ParamCurve, ParamCurveDeriv, PathSeg}; +use kurbo::{ParamCurve, ParamCurveDeriv, PathSeg, Rect}; + +use crate::vector::misc::pathseg_points_vec; + +pub fn pathseg_loose_bbox(segment: PathSeg) -> Rect { + pathseg_points_vec(segment) + .iter() + .fold(None, |bbox: Option, point| { + if let Some(bbox) = bbox { + Some(Rect::new(bbox.x0.min(point.x), bbox.y0.min(point.y), bbox.x1.max(point.x), bbox.y1.max(point.y))) + } else { + Some(Rect::new(point.x, point.y, point.x, point.y)) + } + }) + .unwrap() +} pub fn pathseg_tangent(segment: PathSeg, t: f64) -> DVec2 { // NOTE: .deriv() method gives inaccurate result when it is 1.