add a test for WCS mirror-transformations of clockwise oriented arc edge
# Copyright (c) 2015-2020, Manfred Moitzi
# License: MIT License
+from typing import TYPE_CHECKING
import pytest
import math
@@ -10,6 +11,9 @@ from ezdxf.lldxf import const
from ezdxf.render.forms import box
from ezdxf.math import Vec3, Matrix44, arc_angle_span_deg
+if TYPE_CHECKING:
+ from ezdxf.path import Path
+
@pytest.fixture
def hatch():
@@ -589,6 +593,12 @@ def test_can_not_associate_destroyed_entity(msp):
hatch.associate(path, [pline])
+def transformed_copy(entity, matrix):
+ _copy = entity.copy()
+ _copy.transform(matrix)
+ return _copy
+
+
@pytest.mark.parametrize(
"sx, sy, extrusion",
[
@@ -598,24 +608,41 @@ def test_can_not_associate_destroyed_entity(msp):
],
ids=["mirror-x", "mirror-y", "mirror-xy"],
)
-def test_mirror_transformations_of_clockwise_oriented_arcs(sx, sy, extrusion):
- def copy(entity, matrix):
- _copy = entity.copy()
- _copy.transform(matrix)
- return _copy
-
+def test_ocs_mirror_transformations_of_clockwise_oriented_arcs(
+ sx, sy, extrusion
+):
hatch = Hatch()
edge_path = hatch.paths.add_edge_path()
edge_path.add_arc((0, 0), 5, start_angle=0, end_angle=180, ccw=False)
+ transformed_hatch = transformed_copy(hatch, Matrix44.scale(sx, sy, 1))
- transformed = copy(hatch, Matrix44.scale(sx, sy, 1))
# This tests the current implementation of OCS transformations!
- assert transformed.dxf.extrusion.isclose(extrusion)
+ assert transformed_hatch.dxf.extrusion.isclose(extrusion)
assert (
- transformed.paths[0].edges[0].ccw is False
+ transformed_hatch.paths[0].edges[0].ccw is False
), "ccw flag should not change"
+@pytest.mark.parametrize(
+ "sx, sy",
+ [(-1, 1), (1, -1), (-1, -1)],
+ ids=["mirror-x", "mirror-y", "mirror-xy"],
+)
+def test_wcs_mirror_transformations_of_clockwise_oriented_arcs(sx, sy):
+ from ezdxf.path import make_path, equal_paths
+
+ hatch = Hatch()
+ edge_path = hatch.paths.add_edge_path()
+ edge_path.add_arc((0, 0), 5, start_angle=0, end_angle=180, ccw=False)
+ src_path = make_path(hatch)
+ m = Matrix44.scale(sx, sy, 1)
+ transformed_hatch = transformed_copy(hatch, m)
+
+ expected_path = src_path.transform(m)
+ transformed_path = make_path(transformed_hatch)
+ assert equal_paths(transformed_path, expected_path) is True
+
+
PATH_HATCH = """ 0
HATCH
5
