File: test_642_construction_line.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 (78 lines) | stat: -rw-r--r-- 3,595 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright (c) 2019-2020, Manfred Moitzi
# License: MIT License
from ezdxf.math import ConstructionLine, Vec2


class TestConstructionLine:
    def test_is_vertical(self):
        assert ConstructionLine((0, 0), (10, 0)).is_vertical is False
        assert ConstructionLine((5, -5), (5, 5)).is_vertical is True

    def test_left_of_line(self):
        line = ConstructionLine((0, 0), (0.1, 1))
        assert line.is_point_left_of_line(Vec2(-1, 0)) is True
        assert line.is_point_left_of_line(Vec2(1, 0)) is False
        assert line.is_point_left_of_line(Vec2(-1, -1)) is True

        line = ConstructionLine((0, 0), (0, -1))
        assert line.is_point_left_of_line(Vec2(1, 0)) is True

        line = ConstructionLine((0, 0), (-1, 0.1))
        assert line.is_point_left_of_line(Vec2(-1, 0)) is True

        line = ConstructionLine((0, 0), (10, 0))
        assert line.is_point_left_of_line(Vec2(0, 0)) is False
        assert line.is_point_left_of_line(Vec2(10, 0)) is False
        assert line.is_point_left_of_line(Vec2(10, 1)) is True
        assert line.is_point_left_of_line(Vec2(10, -1)) is False

        line = ConstructionLine((10, 0), (0, 0))
        assert line.is_point_left_of_line(Vec2(0, 0)) is False
        assert line.is_point_left_of_line(Vec2(10, 0)) is False
        assert line.is_point_left_of_line(Vec2(10, 1)) is False
        assert line.is_point_left_of_line(Vec2(10, -1)) is True

        line = ConstructionLine((0, 0), (0, 10))
        assert line.is_point_left_of_line(Vec2(0, 0)) is False
        assert line.is_point_left_of_line(Vec2(0, 10)) is False
        assert line.is_point_left_of_line(Vec2(1, 10)) is False
        assert line.is_point_left_of_line(Vec2(-1, 10)) is True

        line = ConstructionLine((0, 10), (0, 0))
        assert line.is_point_left_of_line(Vec2(0, 0)) is False
        assert line.is_point_left_of_line(Vec2(0, 10)) is False
        assert line.is_point_left_of_line(Vec2(1, 10)) is True
        assert line.is_point_left_of_line(Vec2(-1, 10)) is False

    def test_intersect_horizontal_line(self):
        line = ConstructionLine((0, 0), (10, 0))
        assert line.intersect(ConstructionLine((0, 0), (10, 0))) is None
        assert line.intersect(ConstructionLine((0, 1), (10, 1))) is None
        assert line.intersect(ConstructionLine((0, -1), (10, 1))) == (5, 0)
        assert line.intersect(ConstructionLine((5, 5), (5, -5))) == (5, 0)
        assert line.intersect(ConstructionLine((5, 5), (5, 1))) is None
        assert line.intersect(ConstructionLine((0, 0), (5, 5))) == (0, 0)

    def test_intersect_vertical_line(self):
        line = ConstructionLine((0, 0), (0, 10))
        assert line.intersect(ConstructionLine((0, 0), (0, 10))) is None
        assert line.intersect(ConstructionLine((1, 0), (1, 10))) is None
        assert line.intersect(ConstructionLine((-1, 0), (1, 10))) == (0, 5)
        assert line.intersect(ConstructionLine((-1, 0), (1, 0))) == (0, 0)
        assert line.intersect(ConstructionLine((-1, 10), (1, 10))) == (0, 10)
        assert line.intersect(ConstructionLine((-1, 11), (1, 11))) is None

    def test_bounding_box(self):
        line = ConstructionLine((0, 0), (7, 10))
        bbox = line.bounding_box
        assert bbox.extmin == (0, 0)
        assert bbox.extmax == (7, 10)

    def test_translate(self):
        line = ConstructionLine((0, 0), (0, 10))
        line.translate(3, 7)
        assert line.start == (3, 7)
        assert line.end == (3, 17)
        bbox = line.bounding_box
        assert bbox.extmin == (3, 7)
        assert bbox.extmax == (3, 17)