fixed intersect function
This commit is contained in:
parent
c70d7575ce
commit
2cce50832d
|
@ -483,7 +483,8 @@ func (c Circle) IntersectsRect(r Rect) bool {
|
|||
}.Contains(c.Center)
|
||||
}
|
||||
// The center is in the diagonal quadrants
|
||||
return c.Center.To(r.Min).Len() <= c.Radius || c.Center.To(r.Max).Len() <= c.Radius
|
||||
return c.Center.To(r.Min).Len() <= c.Radius || c.Center.To(r.Max).Len() <= c.Radius ||
|
||||
c.Center.To(V(r.Min.X, r.Max.Y)).Len() <= c.Radius || c.Center.To(V(r.Max.X, r.Min.Y)).Len() <= c.Radius
|
||||
}
|
||||
|
||||
// Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such
|
||||
|
|
|
@ -490,9 +490,15 @@ func TestRect_IntersectsCircle(t *testing.T) {
|
|||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Rect.IntersectsCircle(): circle overlaps one corner",
|
||||
name: "Rect.IntersectsCircle(): circle overlaps bottom-left corner",
|
||||
fields: fields{Min: pixel.ZV, Max: pixel.V(10, 10)},
|
||||
args: args{c: pixel.C(1, pixel.ZV)},
|
||||
args: args{c: pixel.C(1, pixel.V(-.5, -.5))},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Rect.IntersectsCircle(): circle overlaps top-left corner",
|
||||
fields: fields{Min: pixel.ZV, Max: pixel.V(10, 10)},
|
||||
args: args{c: pixel.C(1, pixel.V(-.5, 10.5))},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue