mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 07:28:12 +08:00
use loose bbox for intersection
This commit is contained in:
@@ -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};
|
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,
|
/// 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.
|
/// by splitting the segment recursively until the size of the subsegment's bounding box is smaller than the accuracy.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[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)>) {
|
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 bbox1 = pathseg_loose_bbox(segment1.subsegment(min_t1..max_t1));
|
||||||
let bbox2 = segment2.subsegment(min_t2..max_t2).bounding_box();
|
let bbox2 = pathseg_loose_bbox(segment2.subsegment(min_t2..max_t2));
|
||||||
|
|
||||||
let mid_t1 = (min_t1 + max_t1) / 2.;
|
let mid_t1 = (min_t1 + max_t1) / 2.;
|
||||||
let mid_t2 = (min_t2 + max_t2) / 2.;
|
let mid_t2 = (min_t2 + max_t2) / 2.;
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
use glam::DVec2;
|
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 {
|
pub fn pathseg_tangent(segment: PathSeg, t: f64) -> DVec2 {
|
||||||
// NOTE: .deriv() method gives inaccurate result when it is 1.
|
// NOTE: .deriv() method gives inaccurate result when it is 1.
|
||||||
|
|||||||
Reference in New Issue
Block a user