mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Bug fix: SubImage's SubImage's bounds was wrong
This commit is contained in:
parent
8f133c443e
commit
5ed6565d1d
2
image.go
2
image.go
@ -507,7 +507,7 @@ func (i *Image) SubImage(r image.Rectangle) image.Image {
|
||||
}
|
||||
img.addr = img
|
||||
|
||||
r = r.Intersect(img.Bounds())
|
||||
r = r.Intersect(i.Bounds())
|
||||
// Need to check Empty explicitly. See the standard image package implementations.
|
||||
if r.Empty() {
|
||||
img.bounds = &image.ZR
|
||||
|
@ -1617,3 +1617,38 @@ func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageSubImageSubImage(t *testing.T) {
|
||||
img, _ := NewImage(16, 16, FilterDefault)
|
||||
img.Fill(color.White)
|
||||
sub0 := img.SubImage(image.Rect(0, 0, 12, 12)).(*Image)
|
||||
sub1 := sub0.SubImage(image.Rect(4, 4, 16, 16)).(*Image)
|
||||
cases := []struct {
|
||||
X int
|
||||
Y int
|
||||
Color color.RGBA
|
||||
}{
|
||||
{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Color: color.RGBA{},
|
||||
},
|
||||
{
|
||||
X: 4,
|
||||
Y: 4,
|
||||
Color: color.RGBA{0xff, 0xff, 0xff, 0xff},
|
||||
},
|
||||
{
|
||||
X: 15,
|
||||
Y: 15,
|
||||
Color: color.RGBA{},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := sub1.At(c.X, c.Y)
|
||||
want := c.Color
|
||||
if got != want {
|
||||
t.Errorf("At(%d, %d): got: %v, want: %v", c.X, c.Y, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user