From 779b536f71002d2e723f25d1553c4c6a3fccfeb7 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 29 Nov 2026 15:23:46 +0100 Subject: [PATCH] Perspective Crop: a document of broken size snaps the drag start neither to a corner nor to an edge Co-Authored-By: Claude Opus 5.5 --- crates/draw/src/ui/crop/perspective_tool.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/draw/src/ui/crop/perspective_tool.rs b/crates/draw/src/ui/crop/perspective_tool.rs index 2d391a97a5..b5c095234d 100644 --- a/crates/draw/src/ui/crop/perspective_tool.rs +++ b/crates/draw/src/ui/crop/perspective_tool.rs @@ -133,11 +133,14 @@ fn boxed(anchor: Point, to: Point) -> PerspectiveQuad { /// Where a box drag pressed at `press` starts. While the canvas snaps to the document bounds /// ([`ToolContext::snaps_to_document_bounds`]), a press beyond a document corner (outside on both axes) starts at that /// corner, and one within the snap distance of an edge starts on the nearest edge ([`ToolContext::snap_of`]). Any other -/// press starts where it was. Clicked corners don't come here: they keep their place. +/// press, and every press on a document whose size is negative or not finite, starts where it was. Clicked corners +/// don't come here: they keep their place. fn drag_start(press: Point, cx: &ToolContext<'_>) -> Point { - let document = cx.space().and_then(|space| space.document()); - // A size that is negative or not finite has no corner to start at (and would make `clamp` panic). - let size = document.filter(|size| size.width.is_finite() && size.height.is_finite() && size.width >= 0.0 && size.height >= 0.0); + let size = cx.space().and_then(|space| space.document()); + // A size that is negative or not finite has no bounds to start on (and would make `clamp` panic): no snap at all. + if size.is_some_and(|size| !(size.width.is_finite() && size.height.is_finite() && size.width >= 0.0 && size.height >= 0.0)) { + return press; + } if let Some(size) = size && cx.snaps_to_document_bounds() && !(0.0..=size.width).contains(&press.x)