Skip to content

Commit e34b7e8

Browse files
committed
add basis for aabb and obb calculation of all data structures
1 parent 40b658b commit e34b7e8

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

src/compas/datastructures/datastructure.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,40 @@ class Datastructure(Data):
1818
def __init__(self, attributes=None, name=None):
1919
super(Datastructure, self).__init__(name=name)
2020
self.attributes = attributes or {}
21+
self._aabb = None
22+
self._obb = None
23+
24+
@property
25+
def aabb(self):
26+
if self._aabb is None:
27+
self._aabb = self.compute_aabb()
28+
return self._aabb
29+
30+
@property
31+
def obb(self):
32+
if self._obb is None:
33+
self._obb = self.compute_obb()
34+
return self._obb
35+
36+
def compute_aabb(self):
37+
"""Compute the axis-aligned bounding box of the datastructure.
38+
39+
Returns
40+
-------
41+
:class:`compas.geometry.Box`
42+
43+
"""
44+
raise NotImplementedError
45+
46+
def compute_obb(self):
47+
"""Compute the oriented bounding box of the datastructure.
48+
49+
Returns
50+
-------
51+
:class:`compas.geometry.Box`
52+
53+
"""
54+
raise NotImplementedError
2155

2256
def transform(self, transformation):
2357
"""Transforms the data structure.

src/compas/geometry/geometry.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ def obb(self):
3939
self._obb = self.compute_obb()
4040
return self._obb
4141

42+
def compute_aabb(self):
43+
"""Compute the axis-aligned bounding box of the geometry.
44+
45+
Returns
46+
-------
47+
:class:`compas.geometry.Box`
48+
49+
"""
50+
raise NotImplementedError
51+
52+
def compute_obb(self):
53+
"""Compute the oriented bounding box of the geometry.
54+
55+
Returns
56+
-------
57+
:class:`compas.geometry.Box`
58+
59+
"""
60+
raise NotImplementedError
61+
4262
def transform(self, transformation):
4363
"""Transform the geometry.
4464
@@ -274,23 +294,3 @@ def rotated(self, angle, axis=None, point=None): # type: (...) -> G
274294
axis = [0.0, 0.0, 1.0]
275295

276296
return self.transformed(Rotation.from_axis_and_angle(axis, angle, point))
277-
278-
def compute_aabb(self):
279-
"""Compute the axis-aligned bounding box of the geometry.
280-
281-
Returns
282-
-------
283-
:class:`compas.geometry.Box`
284-
285-
"""
286-
raise NotImplementedError
287-
288-
def compute_obb(self):
289-
"""Compute the oriented bounding box of the geometry.
290-
291-
Returns
292-
-------
293-
:class:`compas.geometry.Box`
294-
295-
"""
296-
raise NotImplementedError

0 commit comments

Comments
 (0)