Skip to content

Commit

Permalink
Mypy and tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasteuwen committed Aug 17, 2024
1 parent d4e417b commit 170df62
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dlup/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ def __getstate__(self) -> dict[str, dict[str, Any]]:
return state

def __setstate__(self, state: dict[str, dict[str, Any]]) -> None:
self.__init__(state["_object"]["exterior"], state["_object"]["interiors"])
exterior = state["_object"]["exterior"]
interiors = state["_object"]["interiors"]

# Use the class method directly instead of calling on self
DlupPolygon.__init__(self, exterior, interiors)

for key, value in state["_fields"].items():
self.set_field(key, value)

Expand Down Expand Up @@ -307,12 +312,13 @@ def __getstate__(self) -> dict[str, dict[str, Any]]:
}
return state

def __setstate__(self, state) -> None:
self.__init__(state["_object"]["coordinates"][0], state["_object"]["coordinates"][1])
def __setstate__(self, state: dict[str, dict[str, Any]]) -> None:
coordinates = state["_object"]["coordinates"]
DlupPoint.__init__(self, coordinates[0], coordinates[1])
for key, value in state["_fields"].items():
self.set_field(key, value)

def scale(self, scaling, origin: Optional["DlupPoint"] = None) -> None:
def scale(self, scaling: float, origin: Optional["DlupPoint"] = None) -> None:
if origin is None:
origin = DlupPoint(0, 0)
super().scale(scaling, origin)
Expand Down Expand Up @@ -356,17 +362,16 @@ def __getstate__(self) -> dict[str, Any]:
}
return state

def __setstate__(self, state) -> None:
def __setstate__(self, state: dict[str, list[dict[str, Any]]]) -> None:
polygons = [DlupPolygon.__new__(DlupPolygon) for _ in state["_polygons"]]
for polygon, polygon_state in zip(polygons, state["_polygons"]):
polygon.__setstate__(polygon_state)

# Reconstruct points from their saved state
points = [DlupPoint.__new__(DlupPoint) for _ in state["_points"]]
for point, point_state in zip(points, state["_points"]):
point.__setstate__(point_state)

self.__init__()
GeometryCollection.__init__(self)
for polygon in polygons:
self.add_polygon(polygon)

Expand Down

0 comments on commit 170df62

Please sign in to comment.