Merge branch 'master' into comments-errors
This commit is contained in:
commit
18972c2818
13
geometry.go
13
geometry.go
|
@ -622,7 +622,18 @@ func (r Rect) Intersect(s Rect) Rect {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// IntersectCircle returns a minimal required Vector, such that moving the rect by that vector would stop the Circle
|
// Intersects returns whether or not the given Rect intersects at any point with this Rect.
|
||||||
|
//
|
||||||
|
// This function is overall about 5x faster than Intersect, so it is better
|
||||||
|
// to use if you have no need for the returned Rect from Intersect.
|
||||||
|
func (r Rect) Intersects(s Rect) bool {
|
||||||
|
return !(s.Max.X < r.Min.X ||
|
||||||
|
s.Min.X > r.Max.X ||
|
||||||
|
s.Max.Y < r.Min.Y ||
|
||||||
|
s.Min.Y > r.Max.Y)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntersectCircle returns a minimal required Vector, such that moving the circle by that vector would stop the Circle
|
||||||
// and the Rect intersecting. This function returns a zero-vector if the Circle and Rect do not overlap, and if only
|
// and the Rect intersecting. This function returns a zero-vector if the Circle and Rect do not overlap, and if only
|
||||||
// the perimeters touch.
|
// the perimeters touch.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1555,3 +1555,29 @@ func TestLine_String(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkRect_Intersect(b *testing.B) {
|
||||||
|
root := pixel.R(10, 10, 50, 50)
|
||||||
|
inter := pixel.R(11, 11, 15, 15)
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if root.Intersect(inter) != pixel.ZR {
|
||||||
|
// do a thing
|
||||||
|
}
|
||||||
|
|
||||||
|
// do a thing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkRect_IsIntersect(b *testing.B) {
|
||||||
|
root := pixel.R(10, 10, 50, 50)
|
||||||
|
inter := pixel.R(11, 11, 15, 15)
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if root.Intersects(inter) {
|
||||||
|
// do a thing
|
||||||
|
}
|
||||||
|
|
||||||
|
// do a thing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue