mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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 <[email protected]> Claude-Session: https://claude.ai/code/session_01UHgFEHEsefoQoBParH47JA
This commit is contained in:
3 files changed
+5
-22
No files matched your search
@@ -165,9 +165,7 @@ fn new_artboard(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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).
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -65,8 +65,7 @@ pub fn fit_artboard(app: &mut PhotocraftApp) -> Result<Value, String> {
|
||||
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]),
|
||||
] {
|
||||
|
||||
Reference in new issue
Block a user