]> Cypherpunks repositories - gostls13.git/commit
image: fix the overlap check in Rectangle.Intersect.
authorNigel Tao <nigeltao@golang.org>
Fri, 10 Feb 2017 03:40:38 +0000 (14:40 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 10 Feb 2017 05:05:59 +0000 (05:05 +0000)
commit3a20928157356f98db74db859b36d744400fc462
treeb0bebd2095c841a51c8afa9c3a4473030cc3b909
parent5faba3057dacdf365572b89b4c9ec9e27f3a6133
image: fix the overlap check in Rectangle.Intersect.

This is a re-roll of a previous commit,
a855da29dbd7a80c4d87a421c1f88a8603c020fa, which was rolled back in
14347ee480968c712ea885a4ea62779fd8a0dc44.

It was rolled back because it broke a unit test in image/gif. The
image/gif code was fixed by 9ef65dbe0683634a2e8a557d12267d0309ae1570
"image/gif: fix frame-inside-image bounds checking".

The original commit message:

image: fix the overlap check in Rectangle.Intersect.

The doc comment for Rectangle.Intersect clearly states, "If the two
rectangles do not overlap then the zero rectangle will be returned."
Prior to this fix, calling Intersect on adjacent but non-overlapping
rectangles would return an empty but non-zero rectangle.

The fix essentially changes
if r.Min.X > r.Max.X || r.Min.Y > r.Max.Y { etc }
to
if r.Min.X >= r.Max.X || r.Min.Y >= r.Max.Y { etc }
(note that the > signs have become >= signs), but changing that line to:
if r.Empty() { etc }
seems clearer (and equivalent).

Change-Id: I2e3af1f1686064a573b2e513b39246fe60c03631
Reviewed-on: https://go-review.googlesource.com/36734
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/image/geom.go
src/image/geom_test.go