5
5
6
6
7
7
class AABB (object ):
8
- """Axis aligned bounding box (AABB)
8
+ """Axis- aligned bounding box (AABB)
9
9
10
10
The AABB is a d-dimensional box.
11
11
@@ -23,8 +23,10 @@ class AABB(object):
23
23
def __init__ (self , limits = None ):
24
24
if limits is not None :
25
25
for lims in limits :
26
- assert len (lims ) == 2
27
- assert lims [0 ] <= lims [1 ]
26
+ if len (lims ) != 2 or lims [0 ] > lims [1 ]:
27
+ e_str = 'Limits not in (lower, upper) format: '
28
+ e_str += str (lims )
29
+ raise ValueError (e_str )
28
30
29
31
self .limits = limits
30
32
self ._i = 0
@@ -96,10 +98,16 @@ def merge(cls, aabb1, aabb2):
96
98
if aabb2 .limits is None :
97
99
return cls (aabb1 .limits )
98
100
101
+ if len (aabb1 ) != len (aabb2 ):
102
+ e_str = 'AABBs of different dimensions: ' + str (len (aabb1 ))
103
+ e_str += ' and ' + str (len (aabb2 ))
104
+ raise ValueError (e_str )
105
+
99
106
merged_limits = []
100
- for lims1 , lims2 in zip (aabb1 , aabb2 ):
101
- lower = min (lims1 [0 ], lims2 [0 ])
102
- upper = max (lims1 [1 ], lims2 [1 ])
107
+ n = len (aabb1 )
108
+ for i in range (n ):
109
+ lower = min (aabb1 [i ][0 ], aabb2 [i ][0 ])
110
+ upper = max (aabb1 [i ][1 ], aabb2 [i ][1 ])
103
111
merged_limits .append ((lower , upper ))
104
112
return cls (merged_limits )
105
113
@@ -195,20 +203,16 @@ def overlap_volume(self, aabb):
195
203
196
204
197
205
class AABBTree (object ):
198
- """Python Implementation of the AABB Tree
206
+ """Static AABB Tree
199
207
200
- This is a pure Python implementation of the static d-dimensional AABB tree.
201
- It is heavily based on
202
- `Introductory Guide to AABB Tree Collision Detection`_
203
- from *Azure From The Trenches*.
208
+ An AABB tree where the bounds of each AABB do not change.
204
209
205
210
Args:
206
211
aabb (AABB): An AABB
207
212
value: The value associated with the AABB
208
213
left (AABBTree, optional): The left branch of the tree
209
214
right (AABBTree, optional): The right branch of the tree
210
215
211
- .. _`Introductory Guide to AABB Tree Collision Detection` : https://www.azurefromthetrenches.com/introductory-guide-to-aabb-tree-collision-detection/
212
216
""" # NOQA: E501
213
217
def __init__ (self , aabb = AABB (), value = None , left = None , right = None ):
214
218
0 commit comments