MCPcopy Index your code
hub / github.com/g3n/engine / BoundingSphere

Method BoundingSphere

geometry/geometry.go:336–357  ·  view source on GitHub ↗

BoundingSphere computes the bounding sphere of this geometry if necessary and returns its value.

()

Source from the content-addressed store, hash-verified

334// BoundingSphere computes the bounding sphere of this geometry
335// if necessary and returns its value.
336func (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.

Callers

nothing calls this directly

Calls 6

BoundingBoxMethod · 0.95
ReadVerticesMethod · 0.95
MaxFunction · 0.92
SqrtFunction · 0.92
CenterMethod · 0.45
DistanceToSquaredMethod · 0.45

Tested by

no test coverage detected