File: test_650_elliptic_arc_span.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 (153 lines) | stat: -rw-r--r-- 4,090 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#  Copyright (c) 2021, Manfred Moitzi
#  License: MIT License

import pytest
import math

from ezdxf.math import ellipse_param_span, arc_angle_span_deg, arc_angle_span_rad


class TestArcParamSpan:
    def span(self, s, e):
        return arc_angle_span_deg(s, e)

    @pytest.mark.parametrize(
        "start, end",
        [
            (0, 0),
            (90, 90),
            (-90, -90),
            (180, 180),
            (-180, -180),
            (270, 270),
            (-270, -270),
            (360, 360),
            (-360, -360),
            (720, 720),
            (-720, -720),
        ],
    )
    def test_no_curve(self, start, end):
        assert self.span(start, end) == pytest.approx(0)

    @pytest.mark.parametrize(
        "start, end",
        [
            # full circles:
            # Normalized start- and end angles are equal, but input values are
            # different:
            (0, 360),
            (360, 0),
            (-360, 0),
            (0, -360),
            (90, 450),
            (180, 540),
            (180, -180),
            (-180, 180),
            (90, -270),
            (-90, 270),
        ],
    )
    def test_closed_curve(self, start, end):
        assert self.span(start, end) == pytest.approx(360.0)

    @pytest.mark.parametrize(
        "start, end, expected",
        [
            (0, 90, 90),
            (0, -90, 270),
            (0, 180, 180),
            (0, -180, 180),
            (180, 360, 180),
            (-180, -360, 180),
            (-90, 360, 90),
            (90, -360, 270),
            (-90, -360, 90),
            (90, 360, 270),
            (360, 90, 90),  # start angle 360 is 0
            (360, -90, 270),  # start angle 360 is 0
            (-360, 90, 90),  # start angle -360 is 0
            (-360, -90, 270),  # start angle -360 is 0
            (30, -30, 300),  # crossing 0 deg
            (-30, 30, 60),  # crossing 0 deg
            (90, -90, 180),
            (-90, 90, 180),
            (360, 400, 40),
            (400, 360, 320),
        ],
    )
    def test_partial_arc(self, start, end, expected):
        assert self.span(start, end) == pytest.approx(expected)


class TestEllipseParamSpan(TestArcParamSpan):
    def span(self, s, e):
        return math.degrees(
            ellipse_param_span(math.radians(s), math.radians(e))
        )


class TestArcParamSpanRadians(TestArcParamSpan):
    def span(self, s, e):
        return math.degrees(
            arc_angle_span_rad(math.radians(s), math.radians(e))
        )


PI2 = math.pi / 2.0


class TestParamSpan:
    # Preserved old param span test.
    # This tests work without degrees-radians-degrees conversion
    @pytest.mark.parametrize(
        "start, end",
        [
            (0, 0),
            (math.pi, math.pi),
            (math.tau, math.tau),
            (0, 0),
            (-math.pi, -math.pi),
            (-math.tau, -math.tau),
        ],
    )
    def test_no_ellipse(self, start, end):
        assert ellipse_param_span(start, end) == 0.0

    @pytest.mark.parametrize(
        "start, end",
        [
            (0, math.tau),
            (math.tau, 0),
            (math.pi, -math.pi),
            (0, -math.tau),
            (-math.tau, 0),
            (-math.pi, math.pi),
        ],
    )
    def test_full_ellipse(self, start, end):
        assert ellipse_param_span(start, end) == pytest.approx(math.tau)

    @pytest.mark.parametrize(
        "start, end, expected",
        [
            (0, PI2, PI2),
            (PI2, 0, math.pi * 1.5),
            (PI2, math.pi, PI2),
            (PI2, -PI2, math.pi),
            (math.pi, 0, math.pi),
            (0, math.pi, math.pi),
            (0, -PI2, math.pi * 1.5),
            (-PI2, 0, PI2),
            (-PI2, -math.pi, math.pi * 1.5),
            (-PI2, PI2, math.pi),
            (-math.pi, 0, math.pi),
            (0, -math.pi, math.pi),
        ],
    )
    def test_elliptic_arc(self, start, end, expected):
        assert ellipse_param_span(start, end) == pytest.approx(expected)


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