internal/restorable: refactoring

Updates #805
This commit is contained in:
Hajime Hoshi 2024-01-13 18:15:24 +09:00
parent e804f9e58c
commit 81e1104613

View File

@ -96,7 +96,10 @@ 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) {
i.WritePixels(nil, region) if region.Dx() <= 0 || region.Dy() <= 0 {
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.
@ -111,11 +114,7 @@ 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.