[Path] preserve cap extensions in normalized form, and scale them with scale()
This commit is contained in:
parent
1bcf5901d6
commit
3beadd2bf0
3 changed files with 52 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from numpy.testing import assert_equal
|
||||
from numpy.testing import assert_equal, assert_allclose
|
||||
|
||||
from ..shapes import Path
|
||||
|
||||
|
|
@ -79,3 +79,33 @@ def test_path_scale() -> None:
|
|||
p.scale_by(2)
|
||||
assert_equal(p.vertices, [[0, 0], [20, 0]])
|
||||
assert p.width == 4
|
||||
|
||||
|
||||
def test_path_scale_custom_cap_extensions() -> None:
|
||||
p = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.SquareCustom, cap_extensions=(1, 2))
|
||||
p.scale_by(3)
|
||||
|
||||
assert_equal(p.vertices, [[0, 0], [30, 0]])
|
||||
assert p.width == 6
|
||||
assert p.cap_extensions is not None
|
||||
assert_allclose(p.cap_extensions, [3, 6])
|
||||
assert_equal(p.to_polygons()[0].get_bounds_single(), [[-3, -3], [36, 3]])
|
||||
|
||||
|
||||
def test_path_normalized_form_preserves_width_and_custom_cap_extensions() -> None:
|
||||
p = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.SquareCustom, cap_extensions=(1, 2))
|
||||
|
||||
intrinsic, _extrinsic, ctor = p.normalized_form(5)
|
||||
q = ctor()
|
||||
|
||||
assert intrinsic[-1] == (0.2, 0.4)
|
||||
assert q.width == 2
|
||||
assert q.cap_extensions is not None
|
||||
assert_allclose(q.cap_extensions, [1, 2])
|
||||
|
||||
|
||||
def test_path_normalized_form_distinguishes_custom_caps() -> None:
|
||||
p1 = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.SquareCustom, cap_extensions=(1, 2))
|
||||
p2 = Path(vertices=[[0, 0], [10, 0]], width=2, cap=Path.Cap.SquareCustom, cap_extensions=(3, 4))
|
||||
|
||||
assert p1.normalized_form(1)[0] != p2.normalized_form(1)[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue