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]));