Revert "internal/restorable: refactoring"

This reverts commit 81e1104613.

Updates #3083
This commit is contained in:
Hajime Hoshi 2024-09-06 14:14:02 +09:00
parent 19d2009a5f
commit becada4afc

View File

@ -88,10 +88,7 @@ func clearImage(i *graphicscommand.Image, region image.Rectangle) {
// ClearPixels clears the specified region by WritePixels. // ClearPixels clears the specified region by WritePixels.
func (i *Image) ClearPixels(region image.Rectangle) { func (i *Image) ClearPixels(region image.Rectangle) {
if region.Dx() <= 0 || region.Dy() <= 0 { i.WritePixels(nil, region)
panic("restorable: width/height must be positive")
}
clearImage(i.Image, region.Intersect(image.Rect(0, 0, i.width, i.height)))
} }
// WritePixels replaces the image pixels with the given pixels slice. // WritePixels replaces the image pixels with the given pixels slice.
@ -106,7 +103,11 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
panic(fmt.Sprintf("restorable: out of range %v", region)) panic(fmt.Sprintf("restorable: out of range %v", region))
} }
if pixels != nil {
i.Image.WritePixels(pixels, region) i.Image.WritePixels(pixels, region)
} else {
clearImage(i.Image, region)
}
} }
// DrawTriangles draws triangles with the given image. // DrawTriangles draws triangles with the given image.