gg/mx/circle.go

33 lines
468 B
Go
Raw Normal View History

2024-05-28 11:24:12 +03:00
package mx
// The type describes a simple
// math circle.
type Circle struct {
Center Vector
Radius Float
}
func (c Circle) ContainsPoint(
pt Vector,
) bool {
d := c.Center.Sub(pt)
dx, dy := d.XY()
d2 := dx*dx + dy*dy
r2 := c.Radius*c.Radius
return r2 > d2
}
func (c Circle) GetContainedPoints(
pts Vectors,
) Vectors {
ret := make(Vectors, 0, len(pts))
for _, pt := range pts {
if c.ContainsPoint(pt) {
ret = append(ret, pt)
}
}
return ret
}