Coverage for test/unit/tasks/common/test_inner_loop_remover.py: 100%
41 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
1import unittest
3from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
5from bim2sim.tasks.common.inner_loop_remover import convex_decomposition_base
6from bim2sim.utilities.pyocc_tools import PyOCCTools
9class TestInnerLoopRemover(unittest.TestCase):
10 def test_simple_convex_polygon(self):
11 points = [(1.0, 1.0, 0.0), (5.0, 1.0, 0.0), (5.0, 5.0, 0.0), (1.0, 5.0, 0.0)]
12 shape = PyOCCTools.make_faces_from_pnts(points)
14 result = convex_decomposition_base(shape)
15 self.assertEqual(result, [points])
17 def test_polygon_with_single_reflex(self):
18 shape = PyOCCTools.make_faces_from_pnts([(1.0, 1.0, 0.0), (5.0, 1.0, 0.0), (2.0, 2.0, 0.0), (1.0, 5.0, 0.0)])
20 result = convex_decomposition_base(shape)
21 self.assertEqual(result, [
22 [(5.0, 1.0, 0.0), (2.0, 2.0, 0.0), (1.0, 1.0, 0.0)],
23 [(1.0, 5.0, 0.0), (1.0, 1.0, 0.0), (2.0, 2.0, 0.0)]
24 ])
26 def test_bigger_polygon_with_single_reflex(self):
27 points = [(1.0, 1.0, 0.0), (3.0, 0.0, 0.0), (5.0, 1.0, 0.0), (2.0, 2.0, 0.0), (1.0, 5.0, 0.0)]
28 shape = PyOCCTools.make_faces_from_pnts(points)
30 result = convex_decomposition_base(shape)
31 self.assertEqual(result, [
32 [(2.0, 2.0, 0.0), (1.0, 1.0, 0.0), (3.0, 0.0, 0.0), (5.0, 1.0, 0.0)],
33 [(1.0, 5.0, 0.0), (1.0, 1.0, 0.0), (2.0, 2.0, 0.0)]
34 ])
36 def test_convex_polygon_with_single_hole(self):
37 big_rect = PyOCCTools.make_faces_from_pnts([(1, 1, 0), (5, 1, 0), (5, 5, 0), (1, 5, 0)])
38 small_rect = PyOCCTools.make_faces_from_pnts([(2, 2, 0), (3, 2, 0), (3, 3, 0), (2, 3, 0)])
39 shape = BRepAlgoAPI_Cut(big_rect, small_rect).Shape()
41 result = convex_decomposition_base(shape)
42 self.assertEqual(result, [
43 [(3.0, 2.0, 0.0), (2.0, 2.0, 0.0), (1.0, 1.0, 0.0), (5.0, 1.0, 0.0)],
44 [(1.0, 1.0, 0.0), (2.0, 2.0, 0.0), (2.0, 3.0, 0.0), (1.0, 5.0, 0.0)],
45 [(3.0, 3.0, 0.0), (3.0, 2.0, 0.0), (5.0, 1.0, 0.0), (5.0, 5.0, 0.0)],
46 [(1.0, 5.0, 0.0), (2.0, 3.0, 0.0), (3.0, 3.0, 0.0), (5.0, 5.0, 0.0)]
47 ])
49 def test_polygon_with_reflex_and_single_hole(self):
50 big_shape = PyOCCTools.make_faces_from_pnts([(1, 1, 0), (5, 1, 0), (5, 5, 0), (3, 4, 0), (1, 5, 0)])
51 small_rect = PyOCCTools.make_faces_from_pnts([(2, 2, 0), (3, 2, 0), (3, 3, 0), (2, 3, 0)])
52 shape = BRepAlgoAPI_Cut(big_shape, small_rect).Shape()
54 result = convex_decomposition_base(shape)
55 self.assertEqual(result, [
56 [(1.0, 1.0, 0.0), (2.0, 2.0, 0.0), (2.0, 3.0, 0.0), (1.0, 5.0, 0.0)],
57 [(3.0, 2.0, 0.0), (2.0, 2.0, 0.0), (1.0, 1.0, 0.0), (5.0, 1.0, 0.0)],
58 [(3.0, 3.0, 0.0), (3.0, 2.0, 0.0), (5.0, 1.0, 0.0), (5.0, 5.0, 0.0), (3.0, 4.0, 0.0)],
59 [(2.0, 3.0, 0.0), (3.0, 3.0, 0.0), (3.0, 4.0, 0.0), (1.0, 5.0, 0.0)]
60 ])
62 def test_polygon_with_reflexes_and_multiple_holes(self):
63 big_shape = PyOCCTools.make_faces_from_pnts([(1, 1, 0), (2, 1.5, 0), (5, 1, 0), (5, 5, 0), (1, 5, 0), (1.5, 4, 0)])
64 small_rect = PyOCCTools.make_faces_from_pnts([(2, 2, 0), (3, 2, 0), (3, 3, 0), (2, 3, 0)])
65 extra_small_rect = PyOCCTools.make_faces_from_pnts([(2, 4, 0), (2, 3.5, 0), (2.5, 3.5, 0), (2.5, 4, 0)])
66 small_trig = PyOCCTools.make_faces_from_pnts([(4, 3, 0), (4, 4, 0), (3, 4, 0)])
67 shape = BRepAlgoAPI_Cut(big_shape, small_rect).Shape()
68 shape = BRepAlgoAPI_Cut(shape, extra_small_rect).Shape()
69 shape = BRepAlgoAPI_Cut(shape, small_trig).Shape()
71 result = convex_decomposition_base(shape)
72 self.assertEqual(result, [
73 [(1.5, 4.0, 0.0), (1.0, 1.0, 0.0), (2.0, 1.5, 0.0), (2.0, 2.0, 0.0), (2.0, 3.0, 0.0), (2.0, 3.5, 0.0), (2.0, 4.0, 0.0)],
74 [(3.0, 2.0, 0.0), (2.0, 2.0, 0.0), (2.0, 1.5, 0.0), (5.0, 1.0, 0.0)],
75 [(5.0, 5.0, 0.0), (1.0, 5.0, 0.0), (1.5, 4.0, 0.0), (2.0, 4.0, 0.0), (2.5, 4.0, 0.0), (3.0, 4.0, 0.0), (4.0, 4.0, 0.0)],
76 [(2.0, 3.0, 0.0), (3.0, 3.0, 0.0), (2.5, 3.5, 0.0), (2.0, 3.5, 0.0)],
77 [(3.0, 4.0, 0.0), (2.5, 4.0, 0.0), (2.5, 3.5, 0.0), (3.0, 3.0, 0.0), (4.0, 3.0, 0.0)],
78 [(4.0, 3.0, 0.0), (3.0, 3.0, 0.0), (3.0, 2.0, 0.0), (5.0, 1.0, 0.0)],
79 [(5.0, 5.0, 0.0), (4.0, 4.0, 0.0), (4.0, 3.0, 0.0), (5.0, 1.0, 0.0)]
80 ])