From 9785a3962ddd4528ee1d31838a645087d0cc82f9 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 5 Jan 2015 16:08:40 +1100 Subject: [PATCH] image/draw: fold TestClipWithNilMP into TestClip. https://go-review.googlesource.com/#/c/1876/ introduced a new TestClipWithNilMP test, along with a code change that fixed a panic, but the existing TestClip test already contained almost enough machinery to cover that bug. There is a small code change in this CL, but it is a no-op: (*x).y is equivalent to x.y for a pointer-typed x, but the latter is cleaner. Change-Id: I79cf6952a4999bc4b91f0a8ec500acb108106e56 Reviewed-on: https://go-review.googlesource.com/2304 Reviewed-by: Dave Cheney --- src/image/draw/clip_test.go | 34 ++++++++++++++++++---------------- src/image/draw/draw.go | 8 ++++---- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/image/draw/clip_test.go b/src/image/draw/clip_test.go index 20de4e3332..5903338a07 100644 --- a/src/image/draw/clip_test.go +++ b/src/image/draw/clip_test.go @@ -139,7 +139,19 @@ var clipTests = []clipTest{ image.Pt(20, 0), image.Pt(20, 0), }, - // TODO(nigeltao): write more tests. + { + "clip sr and mr", + image.Rect(0, 0, 100, 100), + image.Rect(0, 0, 100, 100), + image.Rect(23, 23, 55, 86), + image.Rect(44, 44, 87, 58), + image.Pt(10, 10), + image.Pt(11, 11), + false, + image.Rect(33, 33, 45, 47), + image.Pt(43, 43), + image.Pt(44, 44), + }, } func TestClip(t *testing.T) { @@ -149,12 +161,12 @@ func TestClip(t *testing.T) { for _, c := range clipTests { dst := dst0.SubImage(c.dr).(*image.RGBA) src := src0.SubImage(c.sr).(*image.RGBA) - var mask image.Image - if !c.nilMask { - mask = mask0.SubImage(c.mr) - } r, sp, mp := c.r, c.sp, c.mp - clip(dst, &r, src, &sp, mask, &mp) + if c.nilMask { + clip(dst, &r, src, &sp, nil, nil) + } else { + clip(dst, &r, src, &sp, mask0.SubImage(c.mr), &mp) + } // Check that the actual results equal the expected results. if !c.r0.Eq(r) { @@ -191,13 +203,3 @@ func TestClip(t *testing.T) { } } } - -func TestClipWithNilMP(t *testing.T) { - src := image.NewRGBA(image.Rect(0, 0, 100, 100)) - // dst must be smaller than src for clipping to occur - dst := image.NewRGBA(image.Rect(50, 50, 100, 100)) - r := image.Rect(0, 0, 100, 100) - sp := image.ZP - // issue 9177: floydSteinberg.Draw passes nil for mp, which used to cause clip to panic - clip(dst, &r, src, &sp, nil, nil) -} diff --git a/src/image/draw/draw.go b/src/image/draw/draw.go index a060fa5e74..cffdcbc0d7 100644 --- a/src/image/draw/draw.go +++ b/src/image/draw/draw.go @@ -81,11 +81,11 @@ func clip(dst Image, r *image.Rectangle, src image.Image, sp *image.Point, mask if dx == 0 && dy == 0 { return } - (*sp).X += dx - (*sp).Y += dy + sp.X += dx + sp.Y += dy if mp != nil { - (*mp).X += dx - (*mp).Y += dy + mp.X += dx + mp.Y += dy } } -- 2.50.0