spatial/{barneshut,vptree}: refuse points at infinity

This commit is contained in:
Dan Kortschak
2019-06-20 09:38:02 +09:30
parent 90b7154515
commit e34e6b933b
3 changed files with 38 additions and 2 deletions

View File

@@ -47,12 +47,23 @@ type Plane struct {
}
// NewPlane returns a new Plane.
//
// Points in p must not be infinitely distant, otherwise NewPlane will panic.
func NewPlane(p []Particle2) *Plane {
for _, l := range p {
if isInfR2(l.Coord2()) {
panic("barneshut: point at infinity")
}
}
q := Plane{Particles: p}
q.Reset()
return &q
}
func isInfR2(v r2.Vec) bool {
return math.IsInf(v.X, 0) || math.IsInf(v.Y, 0)
}
// Reset reconstructs the Barnes-Hut tree. Reset must be called if the
// Particles field or elements of Particles have been altered, unless
// ForceOn is called with theta=0 or no data structures have been