55
66
77class AABB (object ):
8- """Axis aligned bounding box (AABB)
8+ """Axis- aligned bounding box (AABB)
99
1010 The AABB is a d-dimensional box.
1111
@@ -23,8 +23,10 @@ class AABB(object):
2323 def __init__ (self , limits = None ):
2424 if limits is not None :
2525 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 )
2830
2931 self .limits = limits
3032 self ._i = 0
@@ -96,10 +98,16 @@ def merge(cls, aabb1, aabb2):
9698 if aabb2 .limits is None :
9799 return cls (aabb1 .limits )
98100
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+
99106 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 ])
103111 merged_limits .append ((lower , upper ))
104112 return cls (merged_limits )
105113
@@ -195,20 +203,16 @@ def overlap_volume(self, aabb):
195203
196204
197205class AABBTree (object ):
198- """Python Implementation of the AABB Tree
206+ """Static AABB Tree
199207
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.
204209
205210 Args:
206211 aabb (AABB): An AABB
207212 value: The value associated with the AABB
208213 left (AABBTree, optional): The left branch of the tree
209214 right (AABBTree, optional): The right branch of the tree
210215
211- .. _`Introductory Guide to AABB Tree Collision Detection` : https://www.azurefromthetrenches.com/introductory-guide-to-aabb-tree-collision-detection/
212216 """ # NOQA: E501
213217 def __init__ (self , aabb = AABB (), value = None , left = None , right = None ):
214218
0 commit comments