From 0c95f608f81db59dcba8c86f3278fc2ace21f61d Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Fri, 30 Jul 2021 02:55:35 +0300 Subject: [PATCH] Reformat with Black. --- roentgen/mapper.py | 66 ++++++++++++++++++++++++++++++++-------------- roentgen/scheme.py | 44 +++++++++++++++++-------------- 2 files changed, 70 insertions(+), 40 deletions(-) diff --git a/roentgen/mapper.py b/roentgen/mapper.py index 445588f..0ec638f 100644 --- a/roentgen/mapper.py +++ b/roentgen/mapper.py @@ -187,11 +187,22 @@ class Painter: for i in range(len(nodes) - 1): # type: int flung_1 = self.flinger.fling(nodes[i].coordinates) flung_2 = self.flinger.fling(nodes[i + 1].coordinates) - building_shade.add(Path( - ("M", np.add(flung_1, shift_1), "L", - np.add(flung_2, shift_1), np.add(flung_2, shift_2), - np.add(flung_1, shift_2), "Z"), - fill="#000000", stroke="#000000", stroke_width=1)) + command = ( + "M", + np.add(flung_1, shift_1), + "L", + np.add(flung_2, shift_1), + np.add(flung_2, shift_2), + np.add(flung_1, shift_2), + "Z", + ) + path = Path( + command, + fill="#000000", + stroke="#000000", + stroke_width=1, + ) + building_shade.add(path) self.svg.add(building_shade) # Draw buildings. @@ -215,14 +226,24 @@ class Painter: color_part: float = 0.8 + segment.angle * 0.2 fill = Color(rgb=(color_part, color_part, color_part)) - self.svg.add(self.svg.path( - d=("M", segment.point_1 + shift_1, "L", - segment.point_2 + shift_1, - segment.point_2 + shift_2, - segment.point_1 + shift_2, - segment.point_1 + shift_1, "Z"), - fill=fill.hex, stroke=fill.hex, stroke_width=1, - stroke_linejoin="round")) + command = ( + "M", + segment.point_1 + shift_1, + "L", + segment.point_2 + shift_1, + segment.point_2 + shift_2, + segment.point_1 + shift_2, + segment.point_1 + shift_1, + "Z", + ) + path = self.svg.path( + d=command, + fill=fill.hex, + stroke=fill.hex, + stroke_width=1, + stroke_linejoin="round", + ) + self.svg.add(path) # Draw building roofs. @@ -280,24 +301,29 @@ class Painter: paths = DirectionSet(direction).draw(point, direction_radius) for path in paths: - gradient = self.svg.defs.add(self.svg.radialGradient( - center=point, r=direction_radius, - gradientUnits="userSpaceOnUse")) + radial_gradient = self.svg.radialGradient( + center=point, + r=direction_radius, + gradientUnits="userSpaceOnUse", + ) + gradient = self.svg.defs.add(radial_gradient) if is_revert_gradient: ( gradient .add_stop_color(0, direction_color.hex, opacity=0) .add_stop_color(1, direction_color.hex, opacity=0.7) - ) + ) # fmt: skip else: ( gradient .add_stop_color(0, direction_color.hex, opacity=0.4) .add_stop_color(1, direction_color.hex, opacity=0) - ) - self.svg.add(self.svg.path( + ) # fmt: skip + path = self.svg.path( d=["M", point] + path + ["L", point, "Z"], - fill=gradient.get_paint_server())) + fill=gradient.get_paint_server(), + ) + self.svg.add(path) def draw_road( self, road: Road, color: Color, extra_width: float = 0 diff --git a/roentgen/scheme.py b/roentgen/scheme.py index d071fa3..31f835f 100644 --- a/roentgen/scheme.py +++ b/roentgen/scheme.py @@ -11,8 +11,12 @@ from colour import Color from roentgen.direction import DirectionSet from roentgen.icon import ( - DEFAULT_COLOR, DEFAULT_SHAPE_ID, Icon, IconSet, ShapeExtractor, - ShapeSpecification + DEFAULT_COLOR, + DEFAULT_SHAPE_ID, + Icon, + IconSet, + ShapeExtractor, + ShapeSpecification, ) from roentgen.text import Label, get_address, get_text @@ -322,7 +326,7 @@ class Scheme: def get_icon( self, - icon_extractor: ShapeExtractor, + extractor: ShapeExtractor, tags: Dict[str, Any], processed: Set[str], for_: str = "node", @@ -330,7 +334,7 @@ class Scheme: """ Construct icon set. - :param icon_extractor: extractor with icon specifications + :param extractor: extractor with icon specifications :param tags: OpenStreetMap element tags dictionary :param for_: target (node, way, area or relation) :param processed: set of already processed tag keys @@ -359,27 +363,27 @@ class Scheme: if not matcher.draw: processed |= matcher_tags if matcher.shapes: - main_icon = Icon([ - ShapeSpecification.from_structure(x, icon_extractor, self) + specifications = [ + ShapeSpecification.from_structure(x, extractor, self) for x in matcher.shapes - ]) + ] + main_icon = Icon(specifications) + processed |= matcher_tags + if matcher.over_icon and main_icon: + specifications = [ + ShapeSpecification.from_structure(x, extractor, self) + for x in matcher.over_icon + ] + main_icon.add_specifications(specifications) processed |= matcher_tags - if matcher.over_icon: - if main_icon: - main_icon.add_specifications([ - ShapeSpecification.from_structure( - x, icon_extractor, self - ) - for x in matcher.over_icon - ]) - processed |= matcher_tags if matcher.add_shapes: - extra_icons += [Icon([ + specifications = [ ShapeSpecification.from_structure( - x, icon_extractor, self, Color("#888888") + x, extractor, self, Color("#888888") ) for x in matcher.add_shapes - ])] + ] + extra_icons += [Icon(specifications)] processed |= matcher_tags if matcher.set_main_color and main_icon: main_icon.recolor(self.get_color(matcher.set_main_color)) @@ -413,7 +417,7 @@ class Scheme: # if x not in processed and not self.is_no_drawable(x) # ] - default_shape = icon_extractor.get_shape(DEFAULT_SHAPE_ID) + default_shape = extractor.get_shape(DEFAULT_SHAPE_ID) if not main_icon: main_icon = Icon([ShapeSpecification(default_shape)])