Improve snapping performance (#3067)

* Use lyon_geom for intersection calculation of bezier segments

* Implement approximate nearest point calculation and loosen bounding boxes

* Add algorithm explanation

* Update editor/src/messages/tool/common_functionality/snapping/layer_snapper.rs

Co-authored-by: Keavon Chambers <keavon@keavon.com>

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2025-08-20 10:47:58 +02:00
committed by GitHub
co-authored by Keavon Chambers
parent b44a4fba1e
commit 7c30f6168b
7 changed files with 186 additions and 8 deletions
@@ -161,6 +161,17 @@ impl DocumentMetadata {
.reduce(Quad::combine_bounds)
}
/// Get the loose bounding box of the click target of the specified layer in the specified transform space
pub fn loose_bounding_box_with_transform(&self, layer: LayerNodeIdentifier, transform: DAffine2) -> Option<[DVec2; 2]> {
self.click_targets(layer)?
.iter()
.filter_map(|click_target| match click_target.target_type() {
ClickTargetType::Subpath(subpath) => subpath.loose_bounding_box_with_transform(transform),
ClickTargetType::FreePoint(_) => click_target.bounding_box_with_transform(transform),
})
.reduce(Quad::combine_bounds)
}
/// Calculate the corners of the bounding box but with a nonzero size.
///
/// If the layer bounds are `0` in either axis then they are changed to be `1`.