BoundingBox computes the bounding box of the geometry if necessary and returns is value.
()
| 312 | // BoundingBox computes the bounding box of the geometry if necessary |
| 313 | // and returns is value. |
| 314 | func (g *Geometry) BoundingBox() math32.Box3 { |
| 315 | |
| 316 | // If valid, return its value |
| 317 | if g.boundingBoxValid { |
| 318 | return g.boundingBox |
| 319 | } |
| 320 | |
| 321 | // Reset bounding box |
| 322 | g.boundingBox.Min.Set(math.MaxFloat32, math.MaxFloat32, math.MaxFloat32) |
| 323 | g.boundingBox.Max.Set(-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32) |
| 324 | |
| 325 | // Expand bounding box by each vertex |
| 326 | g.ReadVertices(func(vertex math32.Vector3) bool { |
| 327 | g.boundingBox.ExpandByPoint(&vertex) |
| 328 | return false |
| 329 | }) |
| 330 | g.boundingBoxValid = true |
| 331 | return g.boundingBox |
| 332 | } |
| 333 | |
| 334 | // BoundingSphere computes the bounding sphere of this geometry |
| 335 | // if necessary and returns its value. |
no test coverage detected