Skip to content
Merged
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
24 changes: 18 additions & 6 deletions map_machine/feature/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ def draw(
self, svg: Drawing, flinger: Flinger, use_building_colors: bool
) -> None:
"""Draw simple building shape."""

if (path_commands := self.get_path(flinger)) is None:
return

path: Path = Path(
d=self.get_path(flinger),
d=path_commands,
stroke=self.stroke.hex
if use_building_colors
else self.default_stroke.hex,
Expand All @@ -122,9 +126,12 @@ def draw_shade(self, building_shade: Group, flinger: Flinger) -> None:
scale: float = flinger.get_scale() * SHADE_SCALE
shift_1: np.ndarray = np.array((scale * self.min_height, 0.0))
shift_2: np.ndarray = np.array((scale * self.height, 0.0))
commands: str = self.get_path(flinger, shift_1)

if (path_commands := self.get_path(flinger, shift_1)) is None:
return

path: Path = Path(
commands, fill="#000000", stroke="#000000", stroke_width=1.0
path_commands, fill="#000000", stroke="#000000", stroke_width=1.0
)
building_shade.add(path)
for nodes in self.inners + self.outers:
Expand Down Expand Up @@ -182,15 +189,20 @@ def draw_roof(
) -> None:
"""Draw building roof."""

if (
path_commands := self.get_path(
flinger, np.array([0.0, -self.height * scale * BUILDING_SCALE])
)
) is None:
return

fill: Color = self.fill if use_building_colors else self.default_fill
stroke: Color = (
self.stroke if use_building_colors else self.default_stroke
)

path: Path = Path(
d=self.get_path(
flinger, np.array([0.0, -self.height * scale * BUILDING_SCALE])
),
d=path_commands,
stroke=stroke,
fill="none" if self.is_construction else fill.hex,
stroke_linejoin="round",
Expand Down
1 change: 1 addition & 0 deletions map_machine/feature/direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def __init__(self, tags: dict[str, str], point: np.ndarray) -> None:

def draw(self, svg: Drawing, scheme) -> None:
"""Draw gradient sector."""

angle: Optional[float] = None
is_revert_gradient: bool = False
direction: str
Expand Down
26 changes: 19 additions & 7 deletions map_machine/feature/road.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ def draw(self, svg: Drawing, is_border: bool) -> None:
filter_: Filter = self.get_filter(svg, is_border)

style: dict[str, Union[int, float, str]] = self.get_style(is_border)
path_commands: str = self.line.get_path(self.placement_offset)

if (path_commands := self.line.get_path(self.placement_offset)) is None:
return

path: Path
if filter_:
path = Path(d=path_commands, filter=filter_.get_funciri())
Expand Down Expand Up @@ -569,9 +572,15 @@ def draw_lanes(self, svg: Drawing, color: Color) -> None:
lane_offset: float = self.scale * (
-self.width / 2.0 + index * self.width / len(self.lanes)
)
path: Path = Path(
d=self.line.get_path(self.placement_offset + lane_offset)
)

if (
path_commands := self.line.get_path(
self.placement_offset + lane_offset
)
) is None:
return

path: Path = Path(d=path_commands)
style: dict[str, Any] = {
"fill": "none",
"stroke": color.hex,
Expand All @@ -588,9 +597,12 @@ def draw_caption(self, svg: Drawing) -> None:
if not name:
return

path: Path = svg.path(
d=self.line.get_path(self.placement_offset + 3.0), fill="none"
)
if (
path_commands := self.line.get_path(self.placement_offset + 3.0)
) is None:
return

path: Path = svg.path(d=path_commands, fill="none")
svg.add(path)

text = svg.add(svg.text.Text(""))
Expand Down
5 changes: 4 additions & 1 deletion map_machine/geometry/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Polyline:
def __init__(self, points: list[np.ndarray]) -> None:
self.points: list[np.ndarray] = points

def get_path(self, parallel_offset: float = 0.0) -> str:
def get_path(self, parallel_offset: float = 0.0) -> Optional[str]:
"""Construct SVG path commands."""
points: list[np.ndarray]

Expand All @@ -65,6 +65,9 @@ def get_path(self, parallel_offset: float = 0.0) -> str:
except (ValueError, NotImplementedError):
points = self.points

if len(points) < 2: # Deal with malformed paths.
return None

return (
"M "
+ " L ".join(f"{point[0]},{point[1]}" for point in points)
Expand Down
8 changes: 8 additions & 0 deletions map_machine/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def draw(self, constructor: Constructor) -> None:

for figure in bottom_figures:
path_commands: str = figure.get_path(self.flinger)

if "M" not in path_commands: # Deal with malformed paths.
continue

if path_commands:
path: SVGPath = SVGPath(d=path_commands)
path.update(figure.line_style.style)
Expand All @@ -84,6 +88,10 @@ def draw(self, constructor: Constructor) -> None:

for figure in top_figures:
path_commands: str = figure.get_path(self.flinger)

if "M" not in path_commands: # Deal with malformed paths.
continue

if path_commands:
path: SVGPath = SVGPath(d=path_commands)
path.update(figure.line_style.style)
Expand Down
2 changes: 1 addition & 1 deletion map_machine/osm/osm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def parse_levels(string: str) -> list[float]:
return list(map(float, string.replace(",", ".").split(";")))
except ValueError:
logging.warning(f"Cannot parse level description from `{string}`.")
return []
return [0.0]


@dataclass
Expand Down