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:
func (r Rectangle) Union(s Rectangle) Rectangle {
if r.Min.X > s.Min.X {
r.Min.X = s.Min.X
}
if r.Min.Y > s.Min.Y {
r.Min.Y = s.Min.Y
}
if r.Max.X < s.Max.X {
r.Max.X = s.Max.X
}
if r.Max.Y < s.Max.Y {
r.Max.Y = s.Max.Y
}
return r
}
To be correct a couple of lines should be added at the beginning of the function:
if r.Empty() {
return s
}
if s.Empty() {
return r
}
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 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.