Reuse click target bounding boxes for document bounds

This commit is contained in:
Dennis Kobert
2025-09-11 11:36:30 +02:00
parent e67b1c0699
commit d9e8a71cd0
4 changed files with 4 additions and 19 deletions
@@ -154,21 +154,7 @@ impl DocumentMetadata {
pub fn bounding_box_with_transform(&self, layer: LayerNodeIdentifier, transform: DAffine2) -> Option<[DVec2; 2]> { pub fn bounding_box_with_transform(&self, layer: LayerNodeIdentifier, transform: DAffine2) -> Option<[DVec2; 2]> {
self.click_targets(layer)? self.click_targets(layer)?
.iter() .iter()
.filter_map(|click_target| match click_target.target_type() { .filter_map(|click_target| click_target.bounding_box_with_transform(transform))
ClickTargetType::Subpath(subpath) => subpath.bounding_box_with_transform(transform),
ClickTargetType::FreePoint(_) => click_target.bounding_box_with_transform(transform),
})
.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) .reduce(Quad::combine_bounds)
} }
@@ -3564,8 +3564,7 @@ impl NodeNetworkInterface {
} }
self.document_metadata self.document_metadata
.click_targets .click_targets(layer)
.get(&layer)
.map(|click| click.iter().map(ClickTarget::target_type)) .map(|click| click.iter().map(ClickTarget::target_type))
.map(|target_types| Vector::from_target_types(target_types, true)) .map(|target_types| Vector::from_target_types(target_types, true))
} }
@@ -333,7 +333,7 @@ impl SnapManager {
return; return;
} }
// We use a loose bounding box here since these are potential candidates which will be filtered later anyway // We use a loose bounding box here since these are potential candidates which will be filtered later anyway
let Some(bounds) = document.metadata().loose_bounding_box_with_transform(layer, DAffine2::IDENTITY) else { let Some(bounds) = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY) else {
return; return;
}; };
let layer_bounds = document.metadata().transform_to_document(layer) * Quad::from_box(bounds); let layer_bounds = document.metadata().transform_to_document(layer) * Quad::from_box(bounds);
+1 -1
View File
@@ -40,7 +40,7 @@ pub struct ClickTarget {
impl ClickTarget { impl ClickTarget {
pub fn new_with_subpath(subpath: Subpath<PointId>, stroke_width: f64) -> Self { pub fn new_with_subpath(subpath: Subpath<PointId>, stroke_width: f64) -> Self {
let bounding_box = subpath.loose_bounding_box(); let bounding_box = subpath.bounding_box();
Self { Self {
target_type: ClickTargetType::Subpath(subpath), target_type: ClickTargetType::Subpath(subpath),
stroke_width, stroke_width,