Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ def simplified(
polygon: list[tuple[float, float]], method: ReductionMethod
) -> list[tuple[float, float]]:
return reduce_polygon(polygon, ReductionMode.EPSILON, 1e-6, method)


@fixture(scope="class")
@parametrize_with_cases("method", cases=".method_cases", scope="class")
def simplified_len(
polygon: list[tuple[float, float]], method: ReductionMethod
) -> list[tuple[float, float]]:
return reduce_polygon(polygon, ReductionMode.LENGTH, 100, method)
33 changes: 33 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,36 @@ def test_containment(
# The null polygon cannot contain itself
if length:
assert simplified_shapely.contains(original_shapely)

def test_len(
self,
polygon: list[tuple[float, float]],
simplified_len: list[tuple[float, float]],
):
"""Ensure reduced polygon vertices are a subset of the originals."""
# if isinstance(polygon, ShapelyPolygon):
# original_set = set(map(lambda v: tuple(v), list(polygon.exterior.coords)))
# else:
# original_set = set(map(lambda v: tuple(v), polygon))
# simplified_set = set(map(lambda v: tuple(v), simplified_len))

# assert simplified_set <= original_set
assert len(simplified_len) <= 100

def test_containment_len(
self,
polygon: list[tuple[float, float]],
simplified_len: list[tuple[float, float]],
):
"""Ensure reduced polygons contain the original in their interior."""
original_shapely = ShapelyPolygon(polygon)
simplified_shapely = ShapelyPolygon(simplified_len)

if isinstance(polygon, ShapelyPolygon):
length = polygon.length
else:
length = len(polygon)

# The null polygon cannot contain itself
if length:
assert simplified_shapely.contains(original_shapely)
Loading