mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Handle non-well-formatted rectangle at DrawImageOptions
This commit is contained in:
parent
7378192fc2
commit
4744b461df
@ -628,25 +628,29 @@ func TestImageOutside(t *testing.T) {
|
|||||||
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
src.Fill(color.RGBA{0xff, 0, 0, 0xff})
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
X, Y int
|
X, Y, Width, Height int
|
||||||
}{
|
}{
|
||||||
{-4, -4},
|
{-4, -4, 4, 4},
|
||||||
{5, 0},
|
{5, 0, 4, 4},
|
||||||
{0, 10},
|
{0, 10, 4, 4},
|
||||||
{5, 10},
|
{5, 10, 4, 4},
|
||||||
{8, 0},
|
{8, 0, 4, 4},
|
||||||
{0, 16},
|
{0, 16, 4, 4},
|
||||||
{8, 16},
|
{8, 16, 4, 4},
|
||||||
{8, -4},
|
{8, -4, 4, 4},
|
||||||
{-4, 16},
|
{-4, 16, 4, 4},
|
||||||
|
{5, 10, 0, 0},
|
||||||
|
{5, 10, -2, -2}, // non-well-formed rectangle
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
dst.Clear()
|
dst.Clear()
|
||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Translate(0, 0)
|
op.GeoM.Translate(0, 0)
|
||||||
r := image.Rect(c.X, c.Y, c.X+4, c.Y+4)
|
op.SourceRect = &image.Rectangle{
|
||||||
op.SourceRect = &r
|
Min: image.Pt(c.X, c.Y),
|
||||||
|
Max: image.Pt(c.X+c.Width, c.Y+c.Height),
|
||||||
|
}
|
||||||
dst.DrawImage(src, op)
|
dst.DrawImage(src, op)
|
||||||
|
|
||||||
for j := 0; j < 4; j++ {
|
for j := 0; j < 4; j++ {
|
||||||
@ -654,7 +658,7 @@ func TestImageOutside(t *testing.T) {
|
|||||||
got := color.RGBAModel.Convert(dst.At(i, j)).(color.RGBA)
|
got := color.RGBAModel.Convert(dst.At(i, j)).(color.RGBA)
|
||||||
want := color.RGBA{0, 0, 0, 0}
|
want := color.RGBA{0, 0, 0, 0}
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("src(%d, %d), dst At(%d, %d): got %#v, want: %#v", c.X, c.Y, i, j, got, want)
|
t.Errorf("src(x: %d, y: %d, w: %d, h: %d), dst At(%d, %d): got %#v, want: %#v", c.X, c.Y, c.Width, c.Height, i, j, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func (v *verticesBackend) get() []float32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func vertices(sx0, sy0, sx1, sy1 int, width, height int, geo *affine.GeoM) []float32 {
|
func vertices(sx0, sy0, sx1, sy1 int, width, height int, geo *affine.GeoM) []float32 {
|
||||||
if sx0 == sx1 || sy0 == sy1 {
|
if sx0 >= sx1 || sy0 >= sy1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: This function should be in graphics package?
|
// TODO: This function should be in graphics package?
|
||||||
|
Loading…
Reference in New Issue
Block a user