From 654a88c140188302332bd21af08605bbd6654ce6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 16 Dec 2017 01:19:59 +0900 Subject: [PATCH] graphics: Add TestImageOutsideUpperLeft --- image_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/image_test.go b/image_test.go index 619537b5f..e6c13ddfb 100644 --- a/image_test.go +++ b/image_test.go @@ -664,3 +664,31 @@ func TestImageOutside(t *testing.T) { } } } + +func TestImageOutsideUpperLeft(t *testing.T) { + src, _ := NewImage(4, 4, FilterNearest) + dst1, _ := NewImage(16, 16, FilterNearest) + dst2, _ := NewImage(16, 16, FilterNearest) + src.Fill(color.RGBA{0xff, 0, 0, 0xff}) + + op := &DrawImageOptions{} + op.GeoM.Rotate(math.Pi / 4) + r := image.Rect(-4, -4, 8, 8) + op.SourceRect = &r + dst1.DrawImage(src, op) + + op = &DrawImageOptions{} + op.GeoM.Translate(4, 4) + op.GeoM.Rotate(math.Pi / 4) + dst2.DrawImage(src, op) + + for j := 0; j < 16; j++ { + for i := 0; i < 16; i++ { + got := color.RGBAModel.Convert(dst1.At(i, j)).(color.RGBA) + want := color.RGBAModel.Convert(dst2.At(i, j)).(color.RGBA) + if got != want { + t.Errorf("got: dst1.At(%d, %d): %#v, want: dst2.At(%d, %d): %#v", i, j, got, i, j, want) + } + } + } +}