Files
IfcOpenShell/src/bonsai/test/bim/module/drawing/test_segment_clipping.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.5 KiB
Python
Raw Normal View History

2024-08-13 15:47:27 +10:00
# Bonsai - OpenBIM Blender Add-on
# Copyright (C) 2020, 2021 Maxim Vasilyev <qwiglydee@gmail.com>
2021-08-17 08:55:29 +10:00
#
2024-08-13 15:47:27 +10:00
# This file is part of Bonsai.
2021-08-17 08:55:29 +10:00
#
2024-08-13 15:47:27 +10:00
# Bonsai is free software: you can redistribute it and/or modify
2021-08-17 08:55:29 +10:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2024-08-13 15:47:27 +10:00
# Bonsai is distributed in the hope that it will be useful,
2021-08-17 08:55:29 +10:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2024-08-13 15:47:27 +10:00
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
2021-08-17 08:55:29 +10:00
2021-01-06 02:32:55 +07:00
import pytest
from mathutils import Vector
2026-01-26 17:11:12 +05:00
from bonsai.bim.module.drawing.helper import clip_segment
2021-01-06 02:32:55 +07:00
BOUNDS = (10, 30, 10, 30, None, None)
2021-01-06 02:32:55 +07:00
SEGMENTS_INSIDE = (
(Vector((15, 20)), Vector((25, 20))),
(Vector((20, 15)), Vector((20, 25))),
(Vector((15, 15)), Vector((25, 25))),
(Vector((15, 25)), Vector((25, 15))),
)
SEGMENTS_OUTSIDE = (
(Vector((15, 35)), Vector((25, 35))),
(Vector((25, 35)), Vector((35, 25))),
(Vector((35, 25)), Vector((35, 15))),
(Vector((35, 15)), Vector((25, 5))),
(Vector((25, 5)), Vector((15, 5))),
(Vector((15, 5)), Vector((5, 15))),
(Vector((5, 15)), Vector((5, 25))),
(Vector((5, 25)), Vector((15, 35))),
2021-01-06 02:32:55 +07:00
)
SEGMENTS_CLIPPED = (
((Vector((5, 20)), Vector((15, 20))), (Vector((10, 20)), Vector((15, 20)))),
((Vector((25, 20)), Vector((35, 20))), (Vector((25, 20)), Vector((30, 20)))),
((Vector((20, 5)), Vector((20, 15))), (Vector((20, 10)), Vector((20, 15)))),
((Vector((20, 15)), Vector((20, 35))), (Vector((20, 15)), Vector((20, 30)))),
((Vector((5, 20)), Vector((20, 35))), (Vector((10, 25)), Vector((15, 30)))),
((Vector((5, 20)), Vector((20, 5))), (Vector((10, 15)), Vector((15, 10)))),
((Vector((35, 20)), Vector((20, 35))), (Vector((30, 25)), Vector((25, 30)))),
((Vector((35, 20)), Vector((20, 5))), (Vector((30, 15)), Vector((25, 10)))),
)
@pytest.mark.parametrize("segment", SEGMENTS_INSIDE)
2021-01-06 02:32:55 +07:00
def test_clip_inside(segment):
clipped = clip_segment(BOUNDS, segment)
assert clipped == segment
@pytest.mark.parametrize("segment", SEGMENTS_OUTSIDE)
2021-01-06 02:32:55 +07:00
def test_clip_outside(segment):
clipped = clip_segment(BOUNDS, segment)
assert clipped is None
@pytest.mark.parametrize("segment,expected", SEGMENTS_CLIPPED)
2021-01-06 02:32:55 +07:00
def test_clip_crossing(segment, expected):
clipped = clip_segment(BOUNDS, segment)
assert clipped == expected