|
1 | 1 | """Cases for end-to-end testing of reduce_polygon."""
|
2 | 2 |
|
3 | 3 | import pickle
|
| 4 | +from collections.abc import Sequence |
| 5 | + |
| 6 | +import numpy as np |
| 7 | +from numpy.typing import NDArray |
| 8 | +from shapely import Polygon as ShapelyPolygon |
| 9 | +from shapely.coords import CoordinateSequence |
4 | 10 |
|
5 | 11 |
|
6 | 12 | class CaseLarge:
|
@@ -60,3 +66,100 @@ def case_interlocking_teeth(self) -> list[tuple[float, float]]:
|
60 | 66 | (1.0, 0.0),
|
61 | 67 | (0.0, 0.0),
|
62 | 68 | ]
|
| 69 | + |
| 70 | + class CaseTypes: |
| 71 | + """Minimal polygons of various types.""" |
| 72 | + |
| 73 | + def case_tuple_tuple(self) -> tuple[tuple[float, float], ...]: |
| 74 | + """A polygon as a tuple of tuples.""" |
| 75 | + return ( |
| 76 | + (0.0, 0.0), |
| 77 | + (0.0, 1.0), |
| 78 | + (0.5, 0.5), |
| 79 | + (1.0, 1.0), |
| 80 | + (1.0, 0.0), |
| 81 | + (0.0, 0.0), |
| 82 | + ) |
| 83 | + |
| 84 | + def case_tuple_list(self) -> tuple[list[float], ...]: |
| 85 | + """A polygon as a tuple of lists.""" |
| 86 | + return ( |
| 87 | + [0.0, 0.0], |
| 88 | + [0.0, 1.0], |
| 89 | + [0.5, 0.5], |
| 90 | + [1.0, 1.0], |
| 91 | + [1.0, 0.0], |
| 92 | + [0.0, 0.0], |
| 93 | + ) |
| 94 | + |
| 95 | + def case_list_tuple(self) -> list[tuple[float, float]]: |
| 96 | + """A polygon as a list of tuples.""" |
| 97 | + return [ |
| 98 | + (0.0, 0.0), |
| 99 | + (0.0, 1.0), |
| 100 | + (0.5, 0.5), |
| 101 | + (1.0, 1.0), |
| 102 | + (1.0, 0.0), |
| 103 | + (0.0, 0.0), |
| 104 | + ] |
| 105 | + |
| 106 | + def case_list_list(self) -> list[list[float]]: |
| 107 | + """A polygon as a list of lists.""" |
| 108 | + return [ |
| 109 | + [0.0, 0.0], |
| 110 | + [0.0, 1.0], |
| 111 | + [0.5, 0.5], |
| 112 | + [1.0, 1.0], |
| 113 | + [1.0, 0.0], |
| 114 | + [0.0, 0.0], |
| 115 | + ] |
| 116 | + |
| 117 | + def case_array(self) -> NDArray[np.floating]: |
| 118 | + """A polygon as a numpy array.""" |
| 119 | + return np.array( |
| 120 | + [ |
| 121 | + [0.0, 0.0], |
| 122 | + [0.0, 1.0], |
| 123 | + [0.5, 0.5], |
| 124 | + [1.0, 1.0], |
| 125 | + [1.0, 0.0], |
| 126 | + [0.0, 0.0], |
| 127 | + ] |
| 128 | + ) |
| 129 | + |
| 130 | + def case_shapely_coord_sequence(self) -> CoordinateSequence: |
| 131 | + """A polygon as a shapely CoordinateSequence.""" |
| 132 | + return ShapelyPolygon( |
| 133 | + [ |
| 134 | + [0.0, 0.0], |
| 135 | + [0.0, 1.0], |
| 136 | + [0.5, 0.5], |
| 137 | + [1.0, 1.0], |
| 138 | + [1.0, 0.0], |
| 139 | + [0.0, 0.0], |
| 140 | + ] |
| 141 | + ).exterior.coords |
| 142 | + |
| 143 | + def case_sequence(self) -> Sequence[tuple[float, float]]: |
| 144 | + """A polygon as a custom type.""" |
| 145 | + |
| 146 | + class CoordSequence(Sequence): |
| 147 | + def __init__(self, coords: list[tuple[float, float]]): |
| 148 | + self.coords = coords |
| 149 | + |
| 150 | + def __len__(self) -> int: |
| 151 | + return len(self.coords) |
| 152 | + |
| 153 | + def __getitem__(self, index: int) -> tuple[float, float]: |
| 154 | + return self.coords[index] |
| 155 | + |
| 156 | + return CoordSequence( |
| 157 | + [ |
| 158 | + (0.0, 0.0), |
| 159 | + (0.0, 1.0), |
| 160 | + (0.5, 0.5), |
| 161 | + (1.0, 1.0), |
| 162 | + (1.0, 0.0), |
| 163 | + (0.0, 0.0), |
| 164 | + ] |
| 165 | + ) |
0 commit comments