Skip to content

Commit

Permalink
Use dataclass instead
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Dec 23, 2023
1 parent a7de74f commit 8ed2155
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions deebot_client/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import itertools
import lzma
import struct
from typing import Any, Final, NamedTuple
from typing import Any, Final
import zlib

from PIL import Image, ImageColor, ImageOps, ImagePalette
Expand Down Expand Up @@ -91,18 +91,22 @@ def _as_str(cls, val: Any) -> str:
)


class Point(NamedTuple):
@dataclasses.dataclass(frozen=True)
class Point:
"""Point."""

x: float
y: float

def flatten(self) -> tuple[float, float]:
"""Flatten point."""
return (self.x, self.y)

Check warning on line 103 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L103

Added line #L103 was not covered by tests


class TracePoint(NamedTuple):
@dataclasses.dataclass(frozen=True)
class TracePoint(Point):
"""Trace point."""

x: int
y: int
connected: bool


Expand Down Expand Up @@ -262,7 +266,7 @@ def _get_svg_positions(
for position in sorted(positions, key=lambda x: _POSITIONS_SVG_ORDER[x.type]):
pos = _calc_point(position.x, position.y, map_manipulation)

Check warning on line 267 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L267

Added line #L267 was not covered by tests
svg_positions.append(
svg.Use(href=f"#position_{position.type}", x=pos[0], y=pos[1])
svg.Use(href=f"#position_{position.type}", x=pos.x, y=pos.y)
)

return svg_positions
Expand Down Expand Up @@ -300,7 +304,7 @@ def _get_svg_subset(
stroke_width=1.5,
stroke_dasharray=[4],
vector_effect="non-scaling-stroke",
points=list(sum(points, [])), # Re-flatten the list of coordinates
points=[num for p in points for num in p.flatten()],
)


Expand Down

0 comments on commit 8ed2155

Please sign in to comment.