@@ -10,12 +10,24 @@ def test_create_bounding_box():
1010 assert bbox .maximum [0 ] == 1
1111 assert bbox .maximum [1 ] == 1
1212 assert bbox .maximum [2 ] == 1
13+ assert bbox .dimensions == 3
1314 assert np .all (bbox .bb == np .array ([[0 , 0 , 0 ], [1 , 1 , 1 ]]))
1415 assert bbox .valid is True
1516
1617
18+ def test_create_bounding_box_2d ():
19+ bbox = BoundingBox (origin = [0 , 0 ], maximum = [1 , 1 ], dimensions = 2 )
20+ assert bbox .origin [0 ] == 0
21+ assert bbox .origin [1 ] == 0
22+ assert bbox .maximum [0 ] == 1
23+ assert bbox .maximum [1 ] == 1
24+ assert bbox .dimensions == 2
25+ assert np .all (bbox .bb == np .array ([[0 , 0 ], [1 , 1 ]]))
26+ assert bbox .valid is True
27+
28+
1729def test_create_bounding_box_from_points ():
18- bbox = BoundingBox ()
30+ bbox = BoundingBox (dimensions = 3 )
1931 bbox .fit (np .array ([[0 , 0 , 0 ], [1 , 1 , 1 ]]))
2032 assert bbox .origin [0 ] == 0
2133 assert bbox .origin [1 ] == 0
@@ -27,6 +39,27 @@ def test_create_bounding_box_from_points():
2739 assert bbox .valid is True
2840
2941
42+ def test_create_bounding_box_from_points_2d ():
43+ bbox = BoundingBox (dimensions = 2 )
44+ bbox .fit (np .array ([[0 , 0 ], [1 , 1 ]]))
45+ assert bbox .origin [0 ] == 0
46+ assert bbox .origin [1 ] == 0
47+ assert bbox .maximum [0 ] == 1
48+ assert bbox .maximum [1 ] == 1
49+ assert np .all (bbox .bb == np .array ([[0 , 0 ], [1 , 1 ]]))
50+ assert bbox .valid is True
51+
52+
53+ def test_create_3d_bounding_box_from_2d_points ():
54+ bbox = BoundingBox (dimensions = 3 )
55+ try :
56+ bbox .fit (np .array ([[0 , 0 ], [1 , 1 ]]))
57+ except Exception as e :
58+ assert str (e ) == "locations array is 2D but bounding box is 3"
59+ else :
60+ assert False
61+
62+
3063def test_create_with_buffer ():
3164 bbox = BoundingBox (origin = [0 , 0 , 0 ], maximum = [1 , 1 , 1 ])
3265 bbox = bbox .with_buffer (0.2 )
@@ -51,8 +84,24 @@ def test_is_inside():
5184 assert not np .all (bbox .is_inside (np .array ([- 0.5 , 0.5 , 0.5 ])))
5285
5386
87+ def test_regular_grid_3d ():
88+ bbox = BoundingBox (origin = [0 , 0 , 0 ], maximum = [1 , 1 , 1 ])
89+ print (bbox .dimensions )
90+ grid = bbox .regular_grid ((10 , 10 , 10 ))
91+ assert grid .shape == (10 * 10 * 10 , 3 )
92+
93+
94+ def test_regular_grid_2d ():
95+ bbox = BoundingBox (origin = [0 , 0 ], maximum = [1 , 1 ], dimensions = 2 )
96+ print (bbox .dimensions )
97+ grid = bbox .regular_grid ((10 , 10 ))
98+ assert grid .shape == (10 * 10 , 2 )
99+
100+
54101if __name__ == "__main__" :
55102 test_create_bounding_box ()
56103 test_create_bounding_box_from_points ()
57104 test_create_with_buffer ()
58105 test_is_inside ()
106+ test_regular_grid_3d ()
107+ test_regular_grid_2d ()
0 commit comments