Merge pull request #188 from Tskken/master

Added ZR for zero rect
This commit is contained in:
Michal Štrba 2019-05-24 20:33:23 +02:00 committed by GitHub
commit daa8205b8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -479,6 +479,9 @@ type Rect struct {
Min, Max Vec
}
// ZR is a zero rectangle.
var ZR = Rect{Min: ZV, Max: ZV}
// R returns a new Rect with given the Min and Max coordinates.
//
// Note that the returned rectangle is not automatically normalized.
@ -605,7 +608,7 @@ func (r Rect) Union(s Rect) Rect {
// Intersect returns the maximal Rect which is covered by both r and s. Rects r and s must be normalized.
//
// If r and s don't overlap, this function returns R(0, 0, 0, 0).
// If r and s don't overlap, this function returns a zero-rectangle.
func (r Rect) Intersect(s Rect) Rect {
t := R(
math.Max(r.Min.X, s.Min.X),
@ -614,7 +617,7 @@ func (r Rect) Intersect(s Rect) Rect {
math.Min(r.Max.Y, s.Max.Y),
)
if t.Min.X >= t.Max.X || t.Min.Y >= t.Max.Y {
return Rect{}
return ZR
}
return t
}