File: test_659_intersection_line_polygon_3d.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (64 lines) | stat: -rw-r--r-- 1,811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#  Copyright (c) 2022, Manfred Moitzi
#  License: MIT License

import pytest
from ezdxf.math import intersection_line_polygon_3d, Vec3


@pytest.fixture(scope="module")
def polygon():
    return Vec3.list([(-1, -1, 1), (1, -1, 1), (1, 1, 1), (-1, 1, 1)])


def test_polygon_with_invalid_normal():
    polygon = Vec3.list([(0, 0, 0), (1, 0, 0), (2, 0, 0)])
    ip = intersection_line_polygon_3d(Vec3(0, 0, 0), Vec3(0, 0, 5), polygon)
    assert ip is None


def test_intersection_point_inside(polygon):
    ip = intersection_line_polygon_3d(Vec3(0, 0, 0), Vec3(0, 0, 5), polygon)
    assert ip.isclose((0, 0, 1))


def test_intersection_point_at_boundary_line(polygon):
    ip = intersection_line_polygon_3d(
        Vec3(1, 0, 0), Vec3(1, 0, 5), polygon, boundary=True
    )
    assert ip.isclose((1, 0, 1))


def test_ignore_intersection_point_at_boundary_line(polygon):
    ip = intersection_line_polygon_3d(
        Vec3(1, 0, 0), Vec3(1, 0, 5), polygon, boundary=False
    )
    assert ip is None


def test_ignore_coplanar_start_point_as_intersection_point(polygon):
    ip = intersection_line_polygon_3d(
        Vec3(0, 0, 1), Vec3(0, 0, 5), polygon, coplanar=False
    )
    assert ip is None


def test_ignore_coplanar_end_point_as_intersection_point(polygon):
    ip = intersection_line_polygon_3d(
        Vec3(0, 0, 0), Vec3(0, 0, 1), polygon, coplanar=False
    )
    assert ip is None


def test_intersection_point_outside():
    polygon = Vec3.list([(-1, -1, 1), (1, -1, 1), (1, 1, 1), (-1, 1, 1)])
    ip = intersection_line_polygon_3d(Vec3(2, 0, 0), Vec3(2, 0, 5), polygon)
    assert ip is None


def test_ignore_coplanar_line(polygon):
    ip = intersection_line_polygon_3d(Vec3(1, 0, 1), Vec3(2, 0, 1), polygon)
    assert ip is None


if __name__ == "__main__":
    pytest.main([__file__])