From 00247d024d0d56495f2a401a91ff327d68d99cd8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 18:27:46 +0000 Subject: [PATCH] Fit Artboard on Screen: keep the view fix; leave new_artboard to #1032 #1032 rejects an artboard whose far edge would pass i32::MAX, so this PR keeps only the f64 midpoint in fit_artboard, and its test uses a board near i32::MAX that #1032 accepts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UHgFEHEsefoQoBParH47JA --- crates/engine/src/artboard_cmds.rs | 4 +--- crates/engine/src/artboard_cmds/tests.rs | 14 -------------- crates/ui-egui/src/artboard_ui.rs | 9 ++++----- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/crates/engine/src/artboard_cmds.rs b/crates/engine/src/artboard_cmds.rs index 92853d9593..93a1ad5bf9 100644 --- a/crates/engine/src/artboard_cmds.rs +++ b/crates/engine/src/artboard_cmds.rs @@ -165,9 +165,7 @@ fn new_artboard(s: &mut Session, p: &Value) -> Result { let right = d.doc.artboards().iter().map(|b| b.2.rect.x1).max(); let top = d.doc.artboards().iter().map(|b| b.2.rect.y0).min().unwrap_or(0); let base = match right { - // The rightmost edge may already sit at i32::MAX (a saturated far edge), so the gap - // must not overflow (#981); `from_xywh` saturates the rest. - Some(x) => Rect::from_xywh(x.saturating_add(GAP), top, pw, ph), + Some(x) => Rect::from_xywh(x + GAP, top, pw, ph), None => Rect::from_xywh(0, 0, pw, ph), }; // A preset decides the size (dialogs send the canvas size alongside it). diff --git a/crates/engine/src/artboard_cmds/tests.rs b/crates/engine/src/artboard_cmds/tests.rs index 1d883800c1..93ac762b52 100644 --- a/crates/engine/src/artboard_cmds/tests.rs +++ b/crates/engine/src/artboard_cmds/tests.rs @@ -155,20 +155,6 @@ fn raster_pdf_xref_offsets_point_at_objects() { assert!(text.contains("/MediaBox [0 0 2.000 3.000]")); } -#[test] -fn new_artboard_next_to_a_board_at_the_i32_edge() { - // #981: the default placement added `GAP` to the rightmost board's far edge, which - // `Rect::from_xywh` had already saturated at i32::MAX, and overflowed. - let mut s = session(8); - let r = s.execute("layer.new.artboard", json!({"x": 2147483600, "y": 0, "width": 1000, "height": 1000})).unwrap(); - assert_eq!(r["rect"], json!([2147483600, 0, 47, 1000])); - // Default placement right of that board saturates to a zero-width base: an error, not a panic. - let err = s.execute("layer.new.artboard", json!({})).unwrap_err(); - assert!(err.to_string().contains("positive"), "{err}"); - let r = s.execute("layer.new.artboard", json!({"y": -1073741840, "width": 50, "height": 20})).unwrap(); - assert_eq!(r["rect"], json!([i32::MAX, -1073741840, 0, 20])); -} - #[test] fn disabled_without_artboards() { let mut s = session(8); diff --git a/crates/ui-egui/src/artboard_ui.rs b/crates/ui-egui/src/artboard_ui.rs index 33febd6ed2..d30a6c9b0a 100644 --- a/crates/ui-egui/src/artboard_ui.rs +++ b/crates/ui-egui/src/artboard_ui.rs @@ -65,8 +65,7 @@ pub fn fit_artboard(app: &mut PhotocraftApp) -> Result { let v = &mut app.ui.views[i]; // Leave room for the name above the board. v.zoom = ((area.x - 60.0) / b.width().max(1) as f32).min((area.y - 80.0) / b.height().max(1) as f32).clamp(0.01, 64.0); - // Widen before adding: a board near ±2^30, or one whose far edge saturated at i32::MAX, - // overflows an i32 sum (#981). + // Widen before adding: the edges of a board near ±2^30 or i32::MAX overflow an i32 sum (#981). v.center = [((f64::from(b.x0) + f64::from(b.x1)) / 2.0) as f32, ((f64::from(b.y0) + f64::from(b.y1)) / 2.0) as f32]; v.fit_pending = false; Ok(json!({"zoom": v.zoom, "artboard": id.0, "bounds": [b.x0, b.y0, b.x1, b.y1]})) @@ -196,10 +195,10 @@ mod tests { #[test] fn fit_artboard_centres_a_board_with_large_coordinates() { - // #981: `(b.x0 + b.x1) as f32` overflowed i32 for boards near ±2^30 and for a board - // whose far edge saturated at i32::MAX, panicking outside any dispatch guard. + // #981: `(b.x0 + b.x1) as f32` overflowed i32 for boards near ±2^30 and near i32::MAX, + // panicking outside any dispatch guard. (Boards past i32::MAX are refused, #1032.) for (params, want) in [ - (json!({"x": 2147483600, "y": 0, "width": 1000, "height": 1000}), [(2147483600.0 + 2147483647.0) / 2.0, 500.0]), + (json!({"x": 2147482000, "y": 0, "width": 1000, "height": 1000}), [(2147482000.0 + 2147483000.0) / 2.0, 500.0]), (json!({"x": 1073741824, "width": 50, "height": 20}), [1073741849.0, 10.0]), (json!({"y": -1073741840, "width": 50, "height": 20}), [25.0, -1073741830.0]), ] {