Skip to content

Commit 57853f7

Browse files
indierustyKeavon
andauthored
Fix box selection regression where only intersected, not contained, objects get selected (#3093)
* fix insideness checking * fix selection insideness checking * Revert changes to comments * Revert unneed rename --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent a744499 commit 57853f7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

node-graph/gcore/src/vector/algorithms/bezpath_algorithms.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,9 @@ pub fn round_line_join(bezpath1: &BezPath, bezpath2: &BezPath, center: DVec2) ->
608608
}
609609

610610
/// Returns `true` if the `bezpath1` is completely inside the `bezpath2`.
611+
/// NOTE: `bezpath2` must be a closed path to get correct results.
611612
pub fn bezpath_is_inside_bezpath(bezpath1: &BezPath, bezpath2: &BezPath, accuracy: Option<f64>, minimum_separation: Option<f64>) -> bool {
612-
// Eliminate any possibility of one being inside the other, if either of them is empty
613+
// Eliminate any possibility of one being inside the other, if either of them are empty
613614
if bezpath1.is_empty() || bezpath2.is_empty() {
614615
return false;
615616
}
@@ -621,7 +622,7 @@ pub fn bezpath_is_inside_bezpath(bezpath1: &BezPath, bezpath2: &BezPath, accurac
621622
// Reasoning:
622623
// If the inner bezpath bounding box is larger than the outer bezpath bounding box in any direction
623624
// then the inner bezpath is intersecting with or outside the outer bezpath.
624-
if !outer_bbox.contains_rect(inner_bbox) {
625+
if !outer_bbox.contains_rect(inner_bbox) && outer_bbox.intersect(inner_bbox).is_zero_area() {
625626
return false;
626627
}
627628

node-graph/gcore/src/vector/click_target.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use super::algorithms::intersection::filtered_segment_intersections;
1+
use super::algorithms::{bezpath_algorithms::bezpath_is_inside_bezpath, intersection::filtered_segment_intersections};
22
use super::misc::dvec2_to_point;
33
use crate::math::math_ext::QuadExt;
44
use crate::math::quad::Quad;
55
use crate::subpath::Subpath;
66
use crate::vector::PointId;
77
use crate::vector::misc::point_to_dvec2;
88
use glam::{DAffine2, DMat2, DVec2};
9-
use kurbo::{Affine, ParamCurve, PathSeg, Point, Shape};
9+
use kurbo::{Affine, BezPath, ParamCurve, PathSeg, Shape};
1010

1111
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
1212
pub struct FreePoint {
@@ -125,9 +125,11 @@ impl ClickTarget {
125125
return true;
126126
}
127127

128+
let mut selection = BezPath::from_path_segments(bezier_iter());
129+
selection.close_path();
130+
128131
// Check if shape is entirely within selection
129-
let any_point_from_subpath = subpath.manipulator_groups().first().map(|manipulators| manipulators.anchor);
130-
any_point_from_subpath.is_some_and(|shape_point| bezier_iter().map(|bezier| bezier.winding(Point::new(shape_point.x, shape_point.y))).sum::<i32>() != 0)
132+
bezpath_is_inside_bezpath(&subpath.to_bezpath(), &selection, None, None)
131133
}
132134
ClickTargetType::FreePoint(point) => bezier_iter().map(|bezier: PathSeg| bezier.winding(dvec2_to_point(point.position))).sum::<i32>() != 0,
133135
}

0 commit comments

Comments
 (0)