]> Cypherpunks repositories - gostls13.git/commitdiff
image/draw: fold TestClipWithNilMP into TestClip.
authorNigel Tao <nigeltao@golang.org>
Mon, 5 Jan 2015 05:08:40 +0000 (16:08 +1100)
committerNigel Tao <nigeltao@golang.org>
Wed, 14 Jan 2015 06:04:13 +0000 (06:04 +0000)
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 <dave@cheney.net>
src/image/draw/clip_test.go
src/image/draw/draw.go

index 20de4e3332b18b009bdbfd639e1fcc1d10ba65a6..5903338a077dda1a890ba43c20953aad388344e3 100644 (file)
@@ -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)
-}
index a060fa5e74c4c4dd91ed23501ec996205dee642f..cffdcbc0d7cf4814a4e8b2aec9cc566500b32f5e 100644 (file)
@@ -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
        }
 }