Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions node-graph/gcore/src/vector/algorithms/intersection.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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.;
Expand Down
17 changes: 16 additions & 1 deletion node-graph/gcore/src/vector/algorithms/util.rs
Original file line number Diff line number Diff line change
@@ -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<Rect>, 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.
Expand Down
Loading