kip-hart / AABBTree

Pure Python implementation of d-dimensional AABB tree.
https://aabbtree.readthedocs.io
MIT License
62 stars 11 forks source link

add option to specify open/closed overlap testing #14

Closed kip-hart closed 3 years ago

kip-hart commented 3 years ago

Added the option to specify open vs closed overlap testing, per request in (#13). Default behavior remains unchanged if the closed flag is not set.

If closed is set to false, there must be a non-zero amount of overlap between boxes for there to be an intersection. This is the default behavior.

If closed is set to true, two boxes can be touching for there to be an intersection.

For example:

from aabbtree import AABB
from aabbtree import AABBTree
tree = AABBTree()
aabb1 = AABB([(0, 0)])
aabb2 = AABB([(-1, 0)])
tree.add(aabb1, 'box 1')
tree.add(aabb2, 'box 2')
# Open Boxes
v = tree.overlap_values(aabb2)
print(v)
>>> ['box 2']
# Closed Boxes
v = tree.overlap_values(aabb2, closed=True)
print(v)
>>> ['box 1', 'box 2']