Builds a bounding box around `geometry` or a collection of points. Args: geometry: `Geometry` object or `Tensor` of points. reduce: Which objects to includes in each bounding box. Non-reduced dims will be part of the returned box. Returns: Bounding `Box` contai
(geometry: Union[Geometry, Tensor], reduce=non_batch)
| 448 | |
| 449 | |
| 450 | def bounding_box(geometry: Union[Geometry, Tensor], reduce=non_batch) -> Box: |
| 451 | """ |
| 452 | Builds a bounding box around `geometry` or a collection of points. |
| 453 | |
| 454 | Args: |
| 455 | geometry: `Geometry` object or `Tensor` of points. |
| 456 | reduce: Which objects to includes in each bounding box. Non-reduced dims will be part of the returned box. |
| 457 | |
| 458 | Returns: |
| 459 | Bounding `Box` containing only batch dims and `vector`. |
| 460 | """ |
| 461 | if isinstance(geometry, Tensor): |
| 462 | assert 'vector' in geometry.shape, f"When passing a Tensor to bounding_box, it needs to have a vector dimension but got {geometry.shape}" |
| 463 | reduce = geometry.shape.only(reduce) - 'vector' |
| 464 | return Box(math.min(geometry, reduce), math.max(geometry, reduce)) |
| 465 | center = geometry.center |
| 466 | extent = geometry.bounding_half_extent() |
| 467 | boxes = Box(center - extent, center + extent) |
| 468 | return boxes.largest(boxes.shape.only(reduce)-'vector') |
no test coverage detected