MCPcopy
hub / github.com/tum-pbs/PhiFlow / bounding_box

Function bounding_box

phi/geom/_box.py:450–468  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

448
449
450def 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')

Callers 3

enclosing_gridFunction · 0.85
_cell_deltasMethod · 0.85
build_facesFunction · 0.85

Calls 3

largestMethod · 0.95
BoxClass · 0.85
bounding_half_extentMethod · 0.45

Tested by

no test coverage detected