Fix code style.

Fix some pylint warnings.
This commit is contained in:
Sergey Vartanov 2021-05-07 00:57:05 +03:00
parent fa8e5551e7
commit cbbd7bcf05
4 changed files with 64 additions and 50 deletions

View file

@ -22,7 +22,7 @@ def is_bright(color: Color) -> bool:
def get_gradient_color( def get_gradient_color(
value: Any, bounds: MinMax, colors: List[Color] value: Any, bounds: MinMax, colors: List[Color]
) -> Color: ) -> Color:
""" """
Get color from the color scale for the value. Get color from the color scale for the value.

View file

@ -25,7 +25,8 @@ from roentgen.util import MinMax
DEBUG: bool = False DEBUG: bool = False
TIME_COLOR_SCALE: List[Color] = [ TIME_COLOR_SCALE: List[Color] = [
Color("#581845"), Color("#900C3F"), Color("#C70039"), Color("#FF5733"), Color("#581845"), Color("#900C3F"), Color("#C70039"), Color("#FF5733"),
Color("#FFC300"), Color("#DAF7A6")] Color("#FFC300"), Color("#DAF7A6")
]
def is_clockwise(polygon: List[OSMNode]) -> bool: def is_clockwise(polygon: List[OSMNode]) -> bool:
@ -39,7 +40,8 @@ def is_clockwise(polygon: List[OSMNode]) -> bool:
next_index: int = 0 if index == len(polygon) - 1 else index + 1 next_index: int = 0 if index == len(polygon) - 1 else index + 1
count += ( count += (
(polygon[next_index].coordinates[0] - node.coordinates[0]) * (polygon[next_index].coordinates[0] - node.coordinates[0]) *
(polygon[next_index].coordinates[1] + node.coordinates[1])) (polygon[next_index].coordinates[1] + node.coordinates[1])
)
return count >= 0 return count >= 0
@ -67,8 +69,8 @@ class Figure(Tagged):
""" """
def __init__( def __init__(
self, tags: Dict[str, str], inners: List[List[OSMNode]], self, tags: Dict[str, str], inners: List[List[OSMNode]],
outers: List[List[OSMNode]], line_style: LineStyle): outers: List[List[OSMNode]], line_style: LineStyle
):
super().__init__() super().__init__()
self.tags: Dict[str, str] = tags self.tags: Dict[str, str] = tags
@ -82,20 +84,21 @@ class Figure(Tagged):
self.outers.append(make_counter_clockwise(outer_nodes)) self.outers.append(make_counter_clockwise(outer_nodes))
def get_path( def get_path(
self, flinger: Flinger, shift: np.array = np.array((0, 0))) -> str: self, flinger: Flinger, shift: np.array = np.array((0, 0))
) -> str:
""" """
Get SVG path commands. Get SVG path commands.
:param flinger: convertor for geo coordinates :param flinger: converter for geo coordinates
:param shift: shift vector :param shift: shift vector
""" """
path: str = "" path: str = ""
for outer_nodes in self.outers: for outer_nodes in self.outers:
path += get_path(outer_nodes, shift, flinger) + " " path += f"{get_path(outer_nodes, shift, flinger)} "
for inner_nodes in self.inners: for inner_nodes in self.inners:
path += get_path(inner_nodes, shift, flinger) + " " path += f"{get_path(inner_nodes, shift, flinger)} "
return path return path
@ -111,11 +114,14 @@ class Segment:
difference: np.array = point_2 - point_1 difference: np.array = point_2 - point_1
vector: np.array = difference / np.linalg.norm(difference) vector: np.array = difference / np.linalg.norm(difference)
self.angle: float = ( self.angle: float = (
np.arccos(np.dot(vector, np.array((0, 1)))) / np.pi) np.arccos(np.dot(vector, np.array((0, 1)))) / np.pi
)
def __lt__(self, other: "Segment"): def __lt__(self, other: "Segment") -> bool:
return (((self.point_1 + self.point_2) / 2)[1] < return (
((other.point_1 + other.point_2) / 2)[1]) ((self.point_1 + self.point_2) / 2)[1] <
((other.point_1 + other.point_2) / 2)[1]
)
class Building(Figure): class Building(Figure):
@ -124,8 +130,8 @@ class Building(Figure):
""" """
def __init__( def __init__(
self, tags: Dict[str, str], inners, outers, flinger: Flinger, self, tags: Dict[str, str], inners, outers, flinger: Flinger,
line_style: LineStyle): line_style: LineStyle
):
super().__init__(tags, inners, outers, line_style) super().__init__(tags, inners, outers, line_style)
self.parts = [] self.parts = []
@ -155,7 +161,7 @@ def line_center(nodes: List[OSMNode], flinger: Flinger) -> np.array:
:param nodes: node list :param nodes: node list
:param flinger: flinger that remap geo positions :param flinger: flinger that remap geo positions
""" """
boundary = [MinMax(), MinMax()] boundary: List[MinMax] = [MinMax(), MinMax()]
for node in nodes: # type: OSMNode for node in nodes: # type: OSMNode
boundary[0].update(node.coordinates[0]) boundary[0].update(node.coordinates[0])
@ -252,8 +258,8 @@ class Constructor:
def __init__( def __init__(
self, map_: Map, flinger: Flinger, scheme: Scheme, self, map_: Map, flinger: Flinger, scheme: Scheme,
icon_extractor: IconExtractor, check_level=lambda x: True, icon_extractor: IconExtractor, check_level=lambda x: True,
mode: str = "normal", seed: str = ""): mode: str = "normal", seed: str = ""
):
self.check_level = check_level self.check_level = check_level
self.mode: str = mode self.mode: str = mode
self.seed: str = seed self.seed: str = seed
@ -302,7 +308,8 @@ class Constructor:
def construct_line( def construct_line(
self, line: Optional[Tagged], self, line: Optional[Tagged],
inners: List[List[OSMNode]], outers: List[List[OSMNode]]) -> None: inners: List[List[OSMNode]], outers: List[List[OSMNode]]
) -> None:
""" """
Way or relation construction. Way or relation construction.
@ -394,7 +401,8 @@ class Constructor:
tags = relation.tags tags = relation.tags
if not self.check_level(tags): if not self.check_level(tags):
continue continue
if "type" in tags and tags["type"] == "multipolygon": if "type" not in tags or tags["type"] != "multipolygon":
continue
inner_ways: List[OSMWay] = [] inner_ways: List[OSMWay] = []
outer_ways: List[OSMWay] = [] outer_ways: List[OSMWay] = []
for member in relation.members: # type: OSMMember for member in relation.members: # type: OSMMember

View file

@ -61,7 +61,7 @@ class Sector:
def __init__(self, text: str, angle: Optional[float] = None): def __init__(self, text: str, angle: Optional[float] = None):
""" """
:param text: sector text representation. E.g. "70-210", "N-NW" :param text: sector text representation (e.g. "70-210", "N-NW")
:param angle: angle in degrees :param angle: angle in degrees
""" """
self.start: Optional[np.array] = None self.start: Optional[np.array] = None
@ -72,17 +72,17 @@ class Sector:
self.start = parse_vector(parts[0]) self.start = parse_vector(parts[0])
self.end = parse_vector(parts[1]) self.end = parse_vector(parts[1])
else: else:
result_angle: float
if angle is None: if angle is None:
angle = DEFAULT_ANGLE result_angle = DEFAULT_ANGLE
else: else:
angle = degree_to_radian(angle) / 2 result_angle = max(SMALLEST_ANGLE, degree_to_radian(angle) / 2)
angle = max(SMALLEST_ANGLE, angle)
vector: Optional[np.array] = parse_vector(text) vector: Optional[np.array] = parse_vector(text)
if vector is not None: if vector is not None:
self.start = np.dot(rotation_matrix(angle), vector) self.start = np.dot(rotation_matrix(result_angle), vector)
self.end = np.dot(rotation_matrix(-angle), vector) self.end = np.dot(rotation_matrix(-result_angle), vector)
def draw(self, center: np.array, radius: float) -> Optional[List[Path]]: def draw(self, center: np.array, radius: float) -> Optional[List[Path]]:
""" """

View file

@ -150,8 +150,14 @@ def draw_grid(
def draw_icon( def draw_icon(
file_name: str, icon_ids: Set[str], extractor: IconExtractor file_name: str, icon_ids: Set[str], extractor: IconExtractor
) -> None: ) -> None:
"""
Draw icon to the SVG file.
:param file_name: output SVG file name
:param icon_ids: input shape string identifiers
:param extractor: icon extractor
"""
icon_set: List[Shape] = [] icon_set: List[Shape] = []
for icon_id in icon_ids: # type: str for icon_id in icon_ids: # type: str
icon, extracted = extractor.get_path(icon_id) # type: Shape, bool icon, extracted = extractor.get_path(icon_id) # type: Shape, bool