File: test_663_is_axes_aligned_rectange.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 (40 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download
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
# Copyright (c) 2024, Manfred Moitzi
# License: MIT License
import pytest

from ezdxf.math import is_axes_aligned_rectangle_2d, Vec2

@pytest.mark.parametrize(
    "points",
    [
        [(0, 0), (1, 0), (1, 1), (0, 1)],  # ccw start horizontal
        [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],  # ccw start horizontal closed
        [(1, 0), (1, 1), (0, 1), (0, 0)],  # ccw start vertical
        [(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)],  # ccw start vertical closed
        [(0, 1), (1, 1), (1, 0), (0, 0)],  # cw start horizontal
        [(0, 0), (0, 1), (1, 1), (1, 0)],  # cw start vertical
    ],
)
def test_is_aligned_rectangle(points):
    assert is_axes_aligned_rectangle_2d(Vec2.list(points)) is True


@pytest.mark.parametrize(
    "points",
    [
        [(0, 0), (1, 0), (1, 1)],  # less than 4 vertices
        [(0, 0), (1, 0), (1, 1), (0.1, 1)],  # nearly aligned quadliteral
        [
            (0, 0),
            (1, 0),
            (1.1, 1),
            (0.1, 1),
        ],  # parallelogram, opposed sides have the same length
    ],
)
def test_is_not_aligned_rectangle(points):
    assert is_axes_aligned_rectangle_2d(Vec2.list(points)) is False


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