From 5b441d389c4ca9a37f097556acd378bc563bf876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Thu, 10 Sep 2026 19:02:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=BD=E7=95=A5=E5=AE=8C=E5=85=A8=E4=BD=8D?= =?UTF-8?q?=E4=BA=8E=E5=9B=BE=E7=89=87=E5=A4=96=E7=9A=84=E5=88=87=E5=88=86?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E7=9F=A9=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 矩形起点超出图片边界时直接返回 None,避免在边缘绘制伪影。 新增越界矩形回归测试。 --- .../src/ui_editor/commands/separation/marker.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/marker.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/marker.rs index 771d1f352..117c266b7 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/marker.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/marker.rs @@ -119,8 +119,11 @@ fn clipped_rect( if width == 0 || height == 0 || w == 0 || h == 0 { return None; } - let x0 = x.min(width - 1); - let y0 = y.min(height - 1); + if x >= width || y >= height { + return None; + } + let x0 = x; + let y0 = y; let x1 = x.saturating_add(w).min(width).saturating_sub(1); let y1 = y.saturating_add(h).min(height).saturating_sub(1); (x0 <= x1 && y0 <= y1).then_some((x0, y0, x1, y1)) @@ -301,6 +304,12 @@ mod tests { assert_eq!(*image.get_pixel(1, 1), image::Rgba([1, 2, 3, 255])); } + #[test] + fn clipped_rect_ignores_rectangles_starting_outside_image() { + assert_eq!(clipped_rect(4, 0, 1, 1, 4, 4), None); + assert_eq!(clipped_rect(0, 4, 1, 1, 4, 4), None); + } + #[test] fn text_mask_is_purple_before_green_frame() { let mut image = image::RgbaImage::from_pixel(8, 8, image::Rgba([1, 2, 3, 255]));