From 3e6021fb8fcc912164134314c3c1b6cf09a7f104 Mon Sep 17 00:00:00 2001 From: mTvare Date: Sun, 13 Apr 2025 16:21:40 +0530 Subject: [PATCH] Fix inability to drag axis-aligned lines (#2561) * Fix 1 and 3 * Fix 2 * Shape tools refactor --------- Co-authored-by: Keavon Chambers --- .../document/utility_types/document_metadata.rs | 9 ++++++--- editor/src/messages/tool/common_functionality/pivot.rs | 2 +- .../tool/common_functionality/transformation_cage.rs | 2 +- node-graph/gcore/src/graphic_element/renderer.rs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/editor/src/messages/portfolio/document/utility_types/document_metadata.rs b/editor/src/messages/portfolio/document/utility_types/document_metadata.rs index 875ec39c..2c17a431 100644 --- a/editor/src/messages/portfolio/document/utility_types/document_metadata.rs +++ b/editor/src/messages/portfolio/document/utility_types/document_metadata.rs @@ -142,14 +142,17 @@ impl DocumentMetadata { /// /// If the layer bounds are `0` in either axis then they are changed to be `1`. pub fn nonzero_bounding_box(&self, layer: LayerNodeIdentifier) -> [DVec2; 2] { - let [bounds_min, mut bounds_max] = self.bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default(); + let [mut bounds_min, mut bounds_max] = self.bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default(); let bounds_size = bounds_max - bounds_min; + let bounds_midpoint = bounds_min.midpoint(bounds_max); if bounds_size.x < 1e-10 { - bounds_max.x = bounds_min.x + 1.; + bounds_max.x = bounds_midpoint.x + 0.5; + bounds_min.x = bounds_midpoint.x - 0.5; } if bounds_size.y < 1e-10 { - bounds_max.y = bounds_min.y + 1.; + bounds_max.y = bounds_midpoint.y + 0.5; + bounds_min.y = bounds_midpoint.y - 0.5; } [bounds_min, bounds_max] diff --git a/editor/src/messages/tool/common_functionality/pivot.rs b/editor/src/messages/tool/common_functionality/pivot.rs index 11856589..f9efcf84 100644 --- a/editor/src/messages/tool/common_functionality/pivot.rs +++ b/editor/src/messages/tool/common_functionality/pivot.rs @@ -35,7 +35,7 @@ impl Default for Pivot { impl Pivot { /// Calculates the transform that gets from normalized pivot to viewspace. fn get_layer_pivot_transform(layer: LayerNodeIdentifier, document: &DocumentMessageHandler) -> DAffine2 { - let [min, max] = document.metadata().nonzero_bounding_box(layer); + let [min, max] = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default(); let bounds_transform = DAffine2::from_translation(min) * DAffine2::from_scale(max - min); let layer_transform = document.metadata().transform_to_viewport(layer); diff --git a/editor/src/messages/tool/common_functionality/transformation_cage.rs b/editor/src/messages/tool/common_functionality/transformation_cage.rs index 91abb4e4..09d4097b 100644 --- a/editor/src/messages/tool/common_functionality/transformation_cage.rs +++ b/editor/src/messages/tool/common_functionality/transformation_cage.rs @@ -794,7 +794,7 @@ impl BoundingBoxManager { } match edges { - Some((top, bottom, left, right)) if !self.is_bounds_flat() => match (top, bottom, left, right) { + Some((top, bottom, left, right)) => match (top, bottom, left, right) { (true, _, false, false) | (_, true, false, false) => MouseCursorIcon::NSResize, (false, false, true, _) | (false, false, _, true) => MouseCursorIcon::EWResize, (true, _, true, _) | (_, true, _, true) => MouseCursorIcon::NWSEResize, diff --git a/node-graph/gcore/src/graphic_element/renderer.rs b/node-graph/gcore/src/graphic_element/renderer.rs index d30c8e08..71cf6e4d 100644 --- a/node-graph/gcore/src/graphic_element/renderer.rs +++ b/node-graph/gcore/src/graphic_element/renderer.rs @@ -88,7 +88,7 @@ impl ClickTarget { // This bounding box is not very accurate as it is the axis aligned version of the transformed bounding box. However it is fast. if !self .bounding_box - .is_some_and(|loose| (loose[0] - loose[1]).abs().cmpgt(DVec2::splat(1e-4)).all() && intersects((layer_transform * Quad::from_box(loose)).bounding_box(), target_bounds)) + .is_some_and(|loose| (loose[0] - loose[1]).abs().cmpgt(DVec2::splat(1e-4)).any() && intersects((layer_transform * Quad::from_box(loose)).bounding_box(), target_bounds)) { return false; }