File: test_705_shape.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 (61 lines) | stat: -rw-r--r-- 1,284 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
# Copyright (c) 2020, Manfred Moitzi
# License: MIT License
import pytest
from ezdxf.math.shape import Shape2d


@pytest.fixture()
def square():
    return Shape2d([(0, 0), (1, 0), (1, 1), (0, 1)])


def test_init(square):

    # shape is list like
    assert len(square) == 4

    # elements are Vec3s?
    assert square[0].x == 0
    assert square[0].y == 0
    assert square[2].x == 1
    assert square[2].y == 1

    e = list(square)
    assert len(e) == 4

    square.append((3, 3))
    assert square[-1] == (3, 3)


def test_translate(square):
    square.translate((1, 0))
    assert square[0] == (1, 0)
    assert square[2] == (2, 1)


def test_scale(square):
    square.scale(sx=2, sy=3)
    assert square[0] == (0, 0)
    assert square[2] == (2, 3)


def test_scale_uniform(square):
    square.scale_uniform(1.5)
    assert square[0] == (0, 0)
    assert square[2] == (1.5, 1.5)


def test_rotate(square):
    square.rotate(90)
    assert square[0].isclose((0, 0))
    assert square[2].isclose((-1, 1))
    square.rotate(90)
    assert square[0].isclose((0, 0))
    assert square[2].isclose((-1, -1))


def test_rotate_center(square):
    square.translate((2, 2))
    square.rotate(90, center=(2, 2))
    assert square[0].isclose((2, 2))
    assert square[2].isclose((1, 3))