Beispiel #1
0
def test_merge():
    aabb1 = AABB([(0, 1)])
    aabb2 = AABB([(-1, 2)])
    assert aabb2 == AABB.merge(aabb1, aabb2)

    aabb3 = AABB([(0.5, 3)])
    assert AABB([(0, 3)]) == AABB.merge(aabb1, aabb3)

    assert aabb1 == AABB.merge(aabb1, AABB())
    assert aabb2 == AABB.merge(AABB(), aabb2)
    assert AABB() == AABB.merge(AABB(), AABB())

    aabb3 = AABB([(-1, 0), (2, 3), (1, 5)])
    with pytest.raises(ValueError):
        AABB.merge(aabb1, aabb3)
Beispiel #2
0
def aabb_merge(tree):
    if not tree.is_leaf:
        assert tree.aabb == AABB.merge(tree.left.aabb, tree.right.aabb)
        aabb_merge(tree.left)
        aabb_merge(tree.right)