added ll and ur as suggested by @pshriwise

This commit is contained in:
Jonathan Shimwell 2023-04-14 17:11:44 +01:00
parent b3ff7f26e3
commit c4aafdd508
2 changed files with 40 additions and 2 deletions

View file

@ -13,10 +13,14 @@ class BoundingBox(tuple):
Attributes
----------
volume: float
The volume of the bounding box in cm3
center: numpy.array
x, y, z coordinates of the center of the bounding box in cm.
lower_left: numpy.array
The x, y, z coordinates of the lower left corner of the bounding box
upper_right
The x, y, z coordinates of the upper right corner of the bounding box
volume: float
The volume of the bounding box in cm3
"""
def __init__(self, corners):
@ -34,6 +38,16 @@ class BoundingBox(tuple):
"""The center x, y, z coordinates of the bounding box"""
return (self.corners[0] + self.corners[1]) / 2
@property
def lower_left(self):
"""The x, y, z coordinates of the lower left corner of the bounding box"""
return self.corners[0]
@property
def upper_right(self):
"""The x, y, z coordinates of the upper right corner of the bounding box"""
return self.corners[1]
@property
def volume(self):
"""The volume of the bounding box"""

View file

@ -26,6 +26,30 @@ def test_bounding_box_volume(bb, expected):
assert bb.volume == expected
@pytest.mark.parametrize(
"bb, expected",
[
(test_bb_1, np.array([-10.0, -20.0, -30.0])),
(test_bb_2, np.array([1.0, 2.0, 3.0])),
(test_bb_3, np.array([-10.0, -20.0, -30.0])),
],
)
def test_bounding_lower_left(bb, expected):
assert np.array_equiv(expected, bb.lower_left)
@pytest.mark.parametrize(
"bb, expected",
[
(test_bb_1, np.array([1.0, 2.0, 3.0])),
(test_bb_2, np.array([11.0, 22.0, 33.0])),
(test_bb_3, np.array([-1.0, -2.0, -3.0])),
],
)
def test_bounding_upper_right(bb, expected):
assert np.array_equiv(expected, bb.upper_right)
@pytest.mark.parametrize(
"bb, expected",
[