-
Notifications
You must be signed in to change notification settings - Fork 18k
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.Union() doesn't handle empty rectangles correctly #9895
Comments
I think it's correct as is. An empty rectangle is still a rectangle, and the function documentation says the resulting rectangle will contain both. With your addition, that's not necessarily true. |
Yeah, I was thinking about it, I'm not sure either. But, for an empty rectangle the position does not matter, it contains no pixels ( as explained here http://blog.golang.org/go-image-package ). If we define the union of two rectangles as the minimum rectangle that contains all the pixels of both, then the union of two empty rectangles should be empty, mathematically speaking it makes more sense. Also practically speaking maybe, if you imagine that you want to calculate the union of a slice of rectangles, you should be able to initialize an empty rectangle as accumulator and then simply iterate over the slice. |
I think it is indeed a bug. Please see https://go-review.googlesource.com/#/c/4990/ for a fix (and test). |
Looks good to me. |
Do you think that Rectangle.Eq() should be true for two empty but "different" rectangles or am I pushing it too far? :) |
Changing Rectangle.Eq is https://go-review.googlesource.com/5006 |
Great. |
The function for calculating the union of two rectangles returns wrong values when one or both input rectangles are empty. The code in image/geom.go is currently:
To be correct a couple of lines should be added at the beginning of the function:
Is this a bug, or is the case ignored for performance reasons? If it's the latter, I think a warning should be added in the function documentation.
The text was updated successfully, but these errors were encountered: