Commit 9785a396 authored by Nigel Tao's avatar Nigel Tao

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/2304Reviewed-by: 's avatarDave Cheney <dave@cheney.net>
parent f15c675f
......@@ -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)
}
......@@ -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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment