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

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

View file

@ -61,7 +61,7 @@ class Sector:
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
"""
self.start: Optional[np.array] = None
@ -72,17 +72,17 @@ class Sector:
self.start = parse_vector(parts[0])
self.end = parse_vector(parts[1])
else:
result_angle: float
if angle is None:
angle = DEFAULT_ANGLE
result_angle = DEFAULT_ANGLE
else:
angle = degree_to_radian(angle) / 2
angle = max(SMALLEST_ANGLE, angle)
result_angle = max(SMALLEST_ANGLE, degree_to_radian(angle) / 2)
vector: Optional[np.array] = parse_vector(text)
if vector is not None:
self.start = np.dot(rotation_matrix(angle), vector)
self.end = np.dot(rotation_matrix(-angle), vector)
self.start = np.dot(rotation_matrix(result_angle), vector)
self.end = np.dot(rotation_matrix(-result_angle), vector)
def draw(self, center: np.array, radius: float) -> Optional[List[Path]]:
"""

View file

@ -151,7 +151,13 @@ def draw_grid(
def draw_icon(
file_name: str, icon_ids: Set[str], extractor: IconExtractor
) -> 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] = []
for icon_id in icon_ids: # type: str
icon, extracted = extractor.get_path(icon_id) # type: Shape, bool