-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ff6735
commit 485f084
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |