Skip to content

Commit 7826fff

Browse files
authored
Merge pull request #3 from kip-hart/dev
Update to 2.3
2 parents d91f2e9 + 63df551 commit 7826fff

File tree

11 files changed

+156
-607
lines changed

11 files changed

+156
-607
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
docs/source/_static/diagram.png
2+
13
###############################################################################
24
# #
35
# SNIPPET FROM .GITIGNORE GIST #

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AABBTree
66
|s-pver| |s-travis| |s-cov| |s-docs| |s-license|
77

88
AABBTree is a pure Python implementation of a static d-dimensional
9-
axis aligned bounding box (AABB) tree. It is heavily based on
9+
axis aligned bounding box (AABB) tree. It is inspired by
1010
`Introductory Guide to AABB Tree Collision Detection`_
1111
from *Azure From The Trenches*.
1212

aabbtree.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class 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

197205
class 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

docs/source/_static/AABB_tree_BVT.png

-94.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)