Debian Codegraph @

src/bonsai/test/bim/module/drawing/test_segment_clipping.py

raw
1 # Bonsai - OpenBIM Blender Add-on
2 # Copyright (C) 2020, 2021 Maxim Vasilyev <[email protected]>
3 #
4 # This file is part of Bonsai.
5 #
6 # Bonsai is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Bonsai is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
18
19 import pytest
20 from mathutils import Vector
21 from bonsai.bim.module.drawing.helper import clip_segment
22
23
24 BOUNDS = (10, 30, 10, 30, None, None)
25
26 SEGMENTS_INSIDE = (
27 (Vector((15, 20)), Vector((25, 20))),
28 (Vector((20, 15)), Vector((20, 25))),
29 (Vector((15, 15)), Vector((25, 25))),
30 (Vector((15, 25)), Vector((25, 15))),
31 )
32
33 SEGMENTS_OUTSIDE = (
34 (Vector((15, 35)), Vector((25, 35))),
35 (Vector((25, 35)), Vector((35, 25))),
36 (Vector((35, 25)), Vector((35, 15))),
37 (Vector((35, 15)), Vector((25, 5))),
38 (Vector((25, 5)), Vector((15, 5))),
39 (Vector((15, 5)), Vector((5, 15))),
40 (Vector((5, 15)), Vector((5, 25))),
41 (Vector((5, 25)), Vector((15, 35))),
42 )
43
44 SEGMENTS_CLIPPED = (
45 ((Vector((5, 20)), Vector((15, 20))), (Vector((10, 20)), Vector((15, 20)))),
46 ((Vector((25, 20)), Vector((35, 20))), (Vector((25, 20)), Vector((30, 20)))),
47 ((Vector((20, 5)), Vector((20, 15))), (Vector((20, 10)), Vector((20, 15)))),
48 ((Vector((20, 15)), Vector((20, 35))), (Vector((20, 15)), Vector((20, 30)))),
49 ((Vector((5, 20)), Vector((20, 35))), (Vector((10, 25)), Vector((15, 30)))),
50 ((Vector((5, 20)), Vector((20, 5))), (Vector((10, 15)), Vector((15, 10)))),
51 ((Vector((35, 20)), Vector((20, 35))), (Vector((30, 25)), Vector((25, 30)))),
52 ((Vector((35, 20)), Vector((20, 5))), (Vector((30, 15)), Vector((25, 10)))),
53 )
54
55
56 @pytest.mark.parametrize("segment", SEGMENTS_INSIDE)
57 def test_clip_inside(segment):
58 clipped = clip_segment(BOUNDS, segment)
59 assert clipped == segment
60
61
62 @pytest.mark.parametrize("segment", SEGMENTS_OUTSIDE)
63 def test_clip_outside(segment):
64 clipped = clip_segment(BOUNDS, segment)
65 assert clipped is None
66
67
68 @pytest.mark.parametrize("segment,expected", SEGMENTS_CLIPPED)
69 def test_clip_crossing(segment, expected):
70 clipped = clip_segment(BOUNDS, segment)
71 assert clipped == expected