Skip to content

Commit

Permalink
add tests for simplify() with/without clockwise option
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Sep 27, 2020
1 parent 41a136e commit cbc63dd
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/pathops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
float2bits,
ArcSize,
Direction,
simplify,
)

import pytest
Expand Down Expand Up @@ -790,3 +791,62 @@ def test_path_operation(message, operations, expected):
round_pts.append(tuple(round(c, 2) for c in pt))
rounded.append((verb, tuple(round_pts)))
assert tuple(rounded) == expected, message



@pytest.fixture
def overlapping_path():
path = Path()
path.moveTo(0, 0)
path.lineTo(10, 0)
path.lineTo(10, 10)
path.lineTo(0, 10)
path.close()
path.moveTo(5, 5)
path.lineTo(15, 5)
path.lineTo(15, 15)
path.lineTo(5, 15)
path.close()
return path


def test_simplify(overlapping_path):
result = simplify(overlapping_path)

assert overlapping_path != result
assert list(result) == [
(PathVerb.MOVE, ((0, 0),)),
(PathVerb.LINE, ((10, 0),)),
(PathVerb.LINE, ((10, 5),)),
(PathVerb.LINE, ((15, 5),)),
(PathVerb.LINE, ((15, 15),)),
(PathVerb.LINE, ((5, 15),)),
(PathVerb.LINE, ((5, 10),)),
(PathVerb.LINE, ((0, 10),)),
(PathVerb.CLOSE, ()),
]

overlapping_path.simplify()

assert overlapping_path == result


def test_simplify_clockwise(overlapping_path):
result = simplify(overlapping_path, clockwise=True)

assert overlapping_path != result
assert list(result) == [
(PathVerb.MOVE, ((0, 0),)),
(PathVerb.LINE, ((0, 10),)),
(PathVerb.LINE, ((5, 10),)),
(PathVerb.LINE, ((5, 15),)),
(PathVerb.LINE, ((15, 15),)),
(PathVerb.LINE, ((15, 5),)),
(PathVerb.LINE, ((10, 5),)),
(PathVerb.LINE, ((10, 0),)),
(PathVerb.CLOSE, ()),
]

overlapping_path.simplify(clockwise=True)

assert overlapping_path == result

0 comments on commit cbc63dd

Please sign in to comment.