Skip to content

Commit

Permalink
fix: adding test to bb
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed Dec 3, 2023
1 parent 0ff6735 commit 485f084
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/unit/utils/test_bounding_box.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from LoopStructural.utils import BoundingBox
import numpy as np


def test_create_bounding_box():
bbox = BoundingBox(origin=[0, 0, 0], maximum=[1, 1, 1])
assert bbox.origin[0] == 0
assert bbox.origin[1] == 0
assert bbox.origin[2] == 0
assert bbox.maximum[0] == 1
assert bbox.maximum[1] == 1
assert bbox.maximum[2] == 1
assert np.all(bbox.bb == np.array([[0, 0, 0], [1, 1, 1]]))
assert bbox.valid == True


def test_create_bounding_box_from_points():
bbox = BoundingBox()
bbox.fit(np.array([[0, 0, 0], [1, 1, 1]]))
assert bbox.origin[0] == 0
assert bbox.origin[1] == 0
assert bbox.origin[2] == 0
assert bbox.maximum[0] == 1
assert bbox.maximum[1] == 1
assert bbox.maximum[2] == 1
assert np.all(bbox.bb == np.array([[0, 0, 0], [1, 1, 1]]))
assert bbox.valid == True


def test_create_with_buffer():
bbox = BoundingBox(origin=[0, 0, 0], maximum=[1, 1, 1])
bbox = bbox.with_buffer(0.2)
assert bbox.origin[0] == -0.2
assert bbox.origin[1] == -0.2
assert bbox.origin[2] == -0.2
assert bbox.maximum[0] == 1.2
assert bbox.maximum[1] == 1.2
assert bbox.maximum[2] == 1.2
assert np.all(bbox.bb == np.array([[-0.2, -0.2, -0.2], [1.2, 1.2, 1.2]]))
assert bbox.valid == True


def test_is_inside():
bbox = BoundingBox(origin=[0, 0, 0], maximum=[1, 1, 1])
assert bbox.is_inside(np.array([0.5, 0.5, 0.5])) == True
assert bbox.is_inside(np.array([0.5, 0.5, 1.5])) == False
assert bbox.is_inside(np.array([0.5, 0.5, -0.5])) == False
assert bbox.is_inside(np.array([0.5, 1.5, 0.5])) == False
assert bbox.is_inside(np.array([0.5, -0.5, 0.5])) == False
assert bbox.is_inside(np.array([1.5, 0.5, 0.5])) == False
assert bbox.is_inside(np.array([-0.5, 0.5, 0.5])) == False


if __name__ == "__main__":
test_create_bounding_box()
test_create_bounding_box_from_points()
test_create_with_buffer()
test_is_inside()

0 comments on commit 485f084

Please sign in to comment.