mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
graphics: Refactoring: Use a value type of bounds instead of a pointer
This commit is contained in:
parent
5ed6565d1d
commit
9595f7ae26
14
image.go
14
image.go
@ -129,7 +129,7 @@ type Image struct {
|
|||||||
// The level 0 image is a regular image and higher-level images are used for mipmap.
|
// The level 0 image is a regular image and higher-level images are used for mipmap.
|
||||||
mipmap *mipmap
|
mipmap *mipmap
|
||||||
|
|
||||||
bounds *image.Rectangle
|
bounds image.Rectangle
|
||||||
original *Image
|
original *Image
|
||||||
|
|
||||||
pixelsToSet []byte
|
pixelsToSet []byte
|
||||||
@ -510,20 +510,20 @@ func (i *Image) SubImage(r image.Rectangle) image.Image {
|
|||||||
r = r.Intersect(i.Bounds())
|
r = r.Intersect(i.Bounds())
|
||||||
// Need to check Empty explicitly. See the standard image package implementations.
|
// Need to check Empty explicitly. See the standard image package implementations.
|
||||||
if r.Empty() {
|
if r.Empty() {
|
||||||
img.bounds = &image.ZR
|
img.bounds = image.ZR
|
||||||
} else {
|
} else {
|
||||||
img.bounds = &r
|
img.bounds = r
|
||||||
}
|
}
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bounds returns the bounds of the image.
|
// Bounds returns the bounds of the image.
|
||||||
func (i *Image) Bounds() image.Rectangle {
|
func (i *Image) Bounds() image.Rectangle {
|
||||||
if i.bounds == nil {
|
if !i.isSubImage() {
|
||||||
w, h := i.mipmap.original().Size()
|
w, h := i.mipmap.original().Size()
|
||||||
return image.Rect(0, 0, w, h)
|
return image.Rect(0, 0, w, h)
|
||||||
}
|
}
|
||||||
return *i.bounds
|
return i.bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
// ColorModel returns the color model of the image.
|
// ColorModel returns the color model of the image.
|
||||||
@ -549,7 +549,7 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
if i.isDisposed() {
|
if i.isDisposed() {
|
||||||
return color.RGBA{}
|
return color.RGBA{}
|
||||||
}
|
}
|
||||||
if i.bounds != nil && !image.Pt(x, y).In(*i.bounds) {
|
if i.isSubImage() && !image.Pt(x, y).In(i.bounds) {
|
||||||
return color.RGBA{}
|
return color.RGBA{}
|
||||||
}
|
}
|
||||||
i.resolvePixelsToSet(true)
|
i.resolvePixelsToSet(true)
|
||||||
@ -573,7 +573,7 @@ func (img *Image) Set(x, y int, clr color.Color) {
|
|||||||
if img.isDisposed() {
|
if img.isDisposed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if img.bounds != nil && !image.Pt(x, y).In(*img.bounds) {
|
if img.isSubImage() && !image.Pt(x, y).In(img.bounds) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if img.isSubImage() {
|
if img.isSubImage() {
|
||||||
|
Loading…
Reference in New Issue
Block a user