diff --git a/map.py b/map.py index aa3067c..c76b82b 100644 --- a/map.py +++ b/map.py @@ -156,6 +156,7 @@ def main(): zoom_scale: float = 0. def get_map_raw_coords(lon: float, lat: float) -> tuple[int, int]: + nonlocal zoom_scale return ( int(zoom_scale * math.radians(lon)), int(zoom_scale * math.log(math.tan(math.pi / 4 + math.radians(lat) / 2))) @@ -167,7 +168,7 @@ def main(): # math.degrees(2 * math.atan(math.exp(y / zoom_scale)) - math.pi / 2.) # ) - zoom_level = 1 + int(-math.log2(((bounds.maxlon - bounds.minlon) * 2 * math.pi) / map_target_width)) + zoom_level = math.ceil(-math.log2(((bounds.maxlon - bounds.minlon) * 2 * math.pi) / map_target_width)) zoom_scale = (2**zoom_level * map_target_width) / (2 * math.pi) min_x, min_y = get_map_raw_coords(bounds.minlon, bounds.minlat) max_x, max_y = get_map_raw_coords(bounds.maxlon, bounds.maxlat) @@ -193,9 +194,10 @@ def main(): node = nodes[node_id] new_coord = get_map_coords(node.lon, node.lat) # print(f'{new_coord=}') - if len(coords) < 2 or new_coord != coords[-1]: + if not coords or new_coord != coords[-1]: coords.append(new_coord) - draw.polygon(coords, fill=color, outline=outline, width=width) + if len(coords) > 2: # noqa: PLR2004 + draw.polygon(coords, fill=color, outline=outline, width=width) def draw_way_line(way: Way, width: int, color: tuple[int, ...] | str, joint: str | None = None): nonlocal bounds, draw, map_height, map_width, nodes @@ -204,9 +206,10 @@ def main(): node = nodes[node_id] new_coord = get_map_coords(node.lon, node.lat) # print(f'{new_coord=}') - if len(coords) < 2 or new_coord != coords[-1]: + if not coords or new_coord != coords[-1]: coords.append(new_coord) - draw.line(coords, width=width, fill=color, joint=joint) + if len(coords) > 1: + draw.line(coords, width=width, fill=color, joint=joint) for relation in relations.values(): if 'natural' in relation.tags and relation.tags['natural'] == 'wood':