Fixing 0,0 being legit closest point

This commit is contained in:
Ben Cragg 2020-05-10 14:25:05 +01:00
parent 76534cb8d0
commit 5254b4eb62
1 changed files with 3 additions and 3 deletions

View File

@ -406,12 +406,12 @@ func (l Line) IntersectRect(r Rect) Vec {
// - the point is contained by the rectangle // - the point is contained by the rectangle
// - the point is not the corner itself // - the point is not the corner itself
corners := r.Vertices() corners := r.Vertices()
closest := ZV var closest *Vec
closestCorner := corners[0] closestCorner := corners[0]
for _, c := range corners { for _, c := range corners {
cc := l.Closest(c) cc := l.Closest(c)
if closest == ZV || (closest.Len() > cc.Len() && r.Contains(cc)) { if closest == nil || (closest.Len() > cc.Len() && r.Contains(cc)) {
closest = cc closest = &cc
closestCorner = c closestCorner = c
} }
} }