BoundingSphere computes the bounding sphere of this geometry if necessary and returns its value.
()
| 334 | // BoundingSphere computes the bounding sphere of this geometry |
| 335 | // if necessary and returns its value. |
| 336 | func (g *Geometry) BoundingSphere() math32.Sphere { |
| 337 | |
| 338 | // If valid, return its value |
| 339 | if g.boundingSphereValid { |
| 340 | return g.boundingSphere |
| 341 | } |
| 342 | |
| 343 | // Reset radius, calculate bounding box and copy center |
| 344 | g.boundingSphere.Radius = float32(0) |
| 345 | box := g.BoundingBox() |
| 346 | box.Center(&g.boundingSphere.Center) |
| 347 | |
| 348 | // Find the radius of the bounding sphere |
| 349 | maxRadiusSq := float32(0) |
| 350 | g.ReadVertices(func(vertex math32.Vector3) bool { |
| 351 | maxRadiusSq = math32.Max(maxRadiusSq, g.boundingSphere.Center.DistanceToSquared(&vertex)) |
| 352 | return false |
| 353 | }) |
| 354 | g.boundingSphere.Radius = float32(math32.Sqrt(maxRadiusSq)) |
| 355 | g.boundingSphereValid = true |
| 356 | return g.boundingSphere |
| 357 | } |
| 358 | |
| 359 | // Area returns the surface area. |
| 360 | // NOTE: This only works for triangle-based meshes. |
nothing calls this directly
no test coverage detected