Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions yt/data_objects/construction_data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ def _setup_data_source(self):
# their cell centers.
self._data_source.loose_selection = True

def get_bbox(self):
return (self.left_edge, self.right_edge)

def get_data(self, fields=None):
if fields is None:
return
Expand Down
11 changes: 11 additions & 0 deletions yt/data_objects/selection_objects/boolean_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ def __init__(self, data_objects, ds=None, field_parameters=None, data_source=Non
YTSelectionContainer3D.__init__(self, None, ds, field_parameters, data_source)
self.data_objects = list(always_iterable(data_objects))

def get_bbox(self):
# Get the bounding box of the intersection
bbox = self.data_objects[0].get_bbox()
for obj in self.data_objects[1:]:
cur_bbox = obj._get_bbox()
bbox = (
np.maximum(bbox[0], cur_bbox[0]),
np.minimum(bbox[1], cur_bbox[1]),
)
return bbox


class YTDataObjectUnion(YTSelectionContainer3D):
"""
Expand Down
32 changes: 31 additions & 1 deletion yt/data_objects/tests/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from numpy.testing import assert_equal

from yt.testing import assert_allclose_units, fake_amr_ds
from yt.testing import assert_allclose_units, fake_amr_ds, fake_octree_ds


def test_object_bbox():
Expand Down Expand Up @@ -55,3 +55,33 @@ def test_object_bbox():
assert_allclose_units(re3, re0)
assert_equal(le4, regb.left_edge)
assert_equal(re4, regb.right_edge)


def test_covering_grid_bbox():
ds = fake_octree_ds(num_zones=32)

cg = ds.covering_grid(level=0, left_edge=[0.3, 0.3, 0.3], dims=[8, 8, 8])

# Make a covering grid with a data source
sp = ds.sphere(
[0.5, 0.5, 0.5],
0.15,
)
cgds = ds.covering_grid(
level=0,
left_edge=[0.3, 0.3, 0.3],
dims=[8, 8, 8],
data_source=sp,
)

# The bounding boxes of the two covering grids should be the same
cg_bbox = cg.get_bbox()
cgds_bbox = cgds.get_bbox()
assert_equal(cg_bbox, cgds_bbox)

# The bounding box of the cg's data source should be the left edge of sp and right edge of cgds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the comment quite cryptic. Do you mean that the covering grid's datasource (sp) should have the same bbox as sp?

Copy link
Author

@AnatoleStorck AnatoleStorck Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So they way I've set up this test is I've made a covering grid in the lower left of the box, and placed a sphere in the center. Parts of the sphere is in the bounding box but some of it is not.

The covering grid which includes the sphere should have a data source which is the intersection of these two objects, and whose bounding box should be the lower left of the sphere, and the upper right of the covering grid.

cgds_ds_bbox = cgds._data_source.get_bbox()
le_sp, re_sp = sp.get_bbox()

assert_equal(le_sp, cgds_ds_bbox[0])
assert_equal(cgds_bbox[1], cgds_ds_bbox[1])
Loading