diff --git a/tests/conftest.py b/tests/conftest.py index 55aba02..58a85cf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/test_integration.py b/tests/test_integration.py index ebacacf..d250213 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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)