Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image: Rectangle.{Overlaps,Intersect} doesn't check for 1 pixel overlaps #8695

Closed
OneOfOne opened this issue Sep 10, 2014 · 2 comments
Closed

image: Rectangle.{Overlaps,Intersect} doesn't check for 1 pixel overlaps #8695

OneOfOne opened this issue Sep 10, 2014 · 2 comments

Comments

@OneOfOne
Copy link
Contributor

@OneOfOne OneOfOne commented Sep 10, 2014

Overlaps and Intersect should use >= / <= for their checks.

func (r Rectangle) Overlaps(s Rectangle) bool {
    return r.Min.X <= s.Max.X && s.Min.X <= r.Max.X &&
        r.Min.Y <= s.Max.Y && s.Min.Y <= r.Max.Y
}

instead of 

func (r Rectangle) Overlaps(s Rectangle) bool {
    return r.Min.X < s.Max.X && s.Min.X < r.Max.X &&
        r.Min.Y < s.Max.Y && s.Min.Y < r.Max.Y
}
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 10, 2014

Comment 1:

Labels changed: added repo-main, release-none.

Loading

@nigeltao
Copy link
Contributor

@nigeltao nigeltao commented Sep 10, 2014

Comment 2:

As the documentation at http://golang.org/pkg/image/#Rectangle says, a Rectangle is
inclusive (<=) on the Min end but exclusive (<) on the Max end. Overlaps should
use < and not <=.

Status changed to WorkingAsIntended.

Loading

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants