Skip to content

Commit

Permalink
Merge pull request #3 from kip-hart/dev
Browse files Browse the repository at this point in the history
Update to 2.3
  • Loading branch information
kip-hart committed Feb 9, 2019
2 parents d91f2e9 + 63df551 commit 7826fff
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 607 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
docs/source/_static/diagram.png

###############################################################################
# #
# SNIPPET FROM .GITIGNORE GIST #
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AABBTree
|s-pver| |s-travis| |s-cov| |s-docs| |s-license|

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

Expand Down
28 changes: 16 additions & 12 deletions aabbtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class AABB(object):
"""Axis aligned bounding box (AABB)
"""Axis-aligned bounding box (AABB)
The AABB is a d-dimensional box.
Expand All @@ -23,8 +23,10 @@ class AABB(object):
def __init__(self, limits=None):
if limits is not None:
for lims in limits:
assert len(lims) == 2
assert lims[0] <= lims[1]
if len(lims) != 2 or lims[0] > lims[1]:
e_str = 'Limits not in (lower, upper) format: '
e_str += str(lims)
raise ValueError(e_str)

self.limits = limits
self._i = 0
Expand Down Expand Up @@ -96,10 +98,16 @@ def merge(cls, aabb1, aabb2):
if aabb2.limits is None:
return cls(aabb1.limits)

if len(aabb1) != len(aabb2):
e_str = 'AABBs of different dimensions: ' + str(len(aabb1))
e_str += ' and ' + str(len(aabb2))
raise ValueError(e_str)

merged_limits = []
for lims1, lims2 in zip(aabb1, aabb2):
lower = min(lims1[0], lims2[0])
upper = max(lims1[1], lims2[1])
n = len(aabb1)
for i in range(n):
lower = min(aabb1[i][0], aabb2[i][0])
upper = max(aabb1[i][1], aabb2[i][1])
merged_limits.append((lower, upper))
return cls(merged_limits)

Expand Down Expand Up @@ -195,20 +203,16 @@ def overlap_volume(self, aabb):


class AABBTree(object):
"""Python Implementation of the AABB Tree
"""Static AABB Tree
This is a pure Python implementation of the static d-dimensional AABB tree.
It is heavily based on
`Introductory Guide to AABB Tree Collision Detection`_
from *Azure From The Trenches*.
An AABB tree where the bounds of each AABB do not change.
Args:
aabb (AABB): An AABB
value: The value associated with the AABB
left (AABBTree, optional): The left branch of the tree
right (AABBTree, optional): The right branch of the tree
.. _`Introductory Guide to AABB Tree Collision Detection` : https://www.azurefromthetrenches.com/introductory-guide-to-aabb-tree-collision-detection/
""" # NOQA: E501
def __init__(self, aabb=AABB(), value=None, left=None, right=None):

Expand Down
Binary file removed docs/source/_static/AABB_tree_BVT.png
Binary file not shown.
Loading

0 comments on commit 7826fff

Please sign in to comment.