Skip to content

Commit

Permalink
use shallow copy instead of deepcopy (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
maomaozi committed Jul 7, 2021
1 parent d222bb8 commit 88cad39
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/python_package.yaml
@@ -1,6 +1,11 @@
name: CI

on: [push]
on:
push:
branches: [master, ]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]

jobs:
pytest:
Expand Down
5 changes: 2 additions & 3 deletions aabbtree.py
@@ -1,6 +1,5 @@
"""Class definitions and methods for the AABB and AABBTree."""

import copy
from collections import deque

__all__ = ['AABB', 'AABBTree']
Expand Down Expand Up @@ -404,7 +403,7 @@ def add(self, aabb, value=None, method='volume'):
self.value = value

elif self.is_leaf:
self.left = copy.deepcopy(self)
self.left = AABBTree(self.aabb, value=self.value, left=self.left, right=self.right)
self.right = AABBTree(aabb, value)

self.aabb = AABB.merge(self.aabb, aabb)
Expand Down Expand Up @@ -438,7 +437,7 @@ def add(self, aabb, value=None, method='volume'):
raise ValueError('Unrecognized method: ' + str(method))

if branch_cost < left_cost and branch_cost < right_cost:
self.left = copy.deepcopy(self)
self.left = AABBTree(self.aabb, value=self.value, left=self.left, right=self.right)
self.right = AABBTree(aabb, value)
self.value = None
elif left_cost < right_cost:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -15,7 +15,7 @@ def read(fname):

setup(
name='aabbtree',
version='2.8.0',
version='2.8.1',
license='MIT',
description='Pure Python implementation of d-dimensional AABB tree.',
long_description=read('README.rst'),
Expand Down
14 changes: 14 additions & 0 deletions tests/test_aabbtree.py
Expand Up @@ -257,6 +257,20 @@ def test_overlap_values_error():
tree.overlap_values(aabbs[0], method=method)


def test_return_the_origin_pass_in_value():
class Foo:
pass

tree = AABBTree()
value_set = {Foo() for _ in range(10)}

for value in value_set:
tree.add(AABB([(0, 1), (0, 1)]), value=value)

retrieved_value_set = set(tree.overlap_values(AABB([(0, 2), (0, 2)]), unique=False))
assert retrieved_value_set == value_set


def test_depth():
assert AABBTree().depth == 0
assert standard_tree().depth == 2
Expand Down

0 comments on commit 88cad39

Please sign in to comment.