Reformat with Black.

This commit is contained in:
Sergey Vartanov 2021-07-30 02:55:35 +03:00
parent c69f1fdae8
commit 0c95f608f8
2 changed files with 70 additions and 40 deletions

View file

@ -187,11 +187,22 @@ class Painter:
for i in range(len(nodes) - 1): # type: int for i in range(len(nodes) - 1): # type: int
flung_1 = self.flinger.fling(nodes[i].coordinates) flung_1 = self.flinger.fling(nodes[i].coordinates)
flung_2 = self.flinger.fling(nodes[i + 1].coordinates) flung_2 = self.flinger.fling(nodes[i + 1].coordinates)
building_shade.add(Path( command = (
("M", np.add(flung_1, shift_1), "L", "M",
np.add(flung_2, shift_1), np.add(flung_2, shift_2), np.add(flung_1, shift_1),
np.add(flung_1, shift_2), "Z"), "L",
fill="#000000", stroke="#000000", stroke_width=1)) 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) self.svg.add(building_shade)
# Draw buildings. # Draw buildings.
@ -215,14 +226,24 @@ class Painter:
color_part: float = 0.8 + segment.angle * 0.2 color_part: float = 0.8 + segment.angle * 0.2
fill = Color(rgb=(color_part, color_part, color_part)) fill = Color(rgb=(color_part, color_part, color_part))
self.svg.add(self.svg.path( command = (
d=("M", segment.point_1 + shift_1, "L", "M",
segment.point_2 + shift_1, segment.point_1 + shift_1,
segment.point_2 + shift_2, "L",
segment.point_1 + shift_2, segment.point_2 + shift_1,
segment.point_1 + shift_1, "Z"), segment.point_2 + shift_2,
fill=fill.hex, stroke=fill.hex, stroke_width=1, segment.point_1 + shift_2,
stroke_linejoin="round")) 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. # Draw building roofs.
@ -280,24 +301,29 @@ class Painter:
paths = DirectionSet(direction).draw(point, direction_radius) paths = DirectionSet(direction).draw(point, direction_radius)
for path in paths: for path in paths:
gradient = self.svg.defs.add(self.svg.radialGradient( radial_gradient = self.svg.radialGradient(
center=point, r=direction_radius, center=point,
gradientUnits="userSpaceOnUse")) r=direction_radius,
gradientUnits="userSpaceOnUse",
)
gradient = self.svg.defs.add(radial_gradient)
if is_revert_gradient: if is_revert_gradient:
( (
gradient gradient
.add_stop_color(0, direction_color.hex, opacity=0) .add_stop_color(0, direction_color.hex, opacity=0)
.add_stop_color(1, direction_color.hex, opacity=0.7) .add_stop_color(1, direction_color.hex, opacity=0.7)
) ) # fmt: skip
else: else:
( (
gradient gradient
.add_stop_color(0, direction_color.hex, opacity=0.4) .add_stop_color(0, direction_color.hex, opacity=0.4)
.add_stop_color(1, direction_color.hex, opacity=0) .add_stop_color(1, direction_color.hex, opacity=0)
) ) # fmt: skip
self.svg.add(self.svg.path( path = self.svg.path(
d=["M", point] + path + ["L", point, "Z"], d=["M", point] + path + ["L", point, "Z"],
fill=gradient.get_paint_server())) fill=gradient.get_paint_server(),
)
self.svg.add(path)
def draw_road( def draw_road(
self, road: Road, color: Color, extra_width: float = 0 self, road: Road, color: Color, extra_width: float = 0

View file

@ -11,8 +11,12 @@ from colour import Color
from roentgen.direction import DirectionSet from roentgen.direction import DirectionSet
from roentgen.icon import ( from roentgen.icon import (
DEFAULT_COLOR, DEFAULT_SHAPE_ID, Icon, IconSet, ShapeExtractor, DEFAULT_COLOR,
ShapeSpecification DEFAULT_SHAPE_ID,
Icon,
IconSet,
ShapeExtractor,
ShapeSpecification,
) )
from roentgen.text import Label, get_address, get_text from roentgen.text import Label, get_address, get_text
@ -322,7 +326,7 @@ class Scheme:
def get_icon( def get_icon(
self, self,
icon_extractor: ShapeExtractor, extractor: ShapeExtractor,
tags: Dict[str, Any], tags: Dict[str, Any],
processed: Set[str], processed: Set[str],
for_: str = "node", for_: str = "node",
@ -330,7 +334,7 @@ class Scheme:
""" """
Construct icon set. Construct icon set.
:param icon_extractor: extractor with icon specifications :param extractor: extractor with icon specifications
:param tags: OpenStreetMap element tags dictionary :param tags: OpenStreetMap element tags dictionary
:param for_: target (node, way, area or relation) :param for_: target (node, way, area or relation)
:param processed: set of already processed tag keys :param processed: set of already processed tag keys
@ -359,27 +363,27 @@ class Scheme:
if not matcher.draw: if not matcher.draw:
processed |= matcher_tags processed |= matcher_tags
if matcher.shapes: if matcher.shapes:
main_icon = Icon([ specifications = [
ShapeSpecification.from_structure(x, icon_extractor, self) ShapeSpecification.from_structure(x, extractor, self)
for x in matcher.shapes 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 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: if matcher.add_shapes:
extra_icons += [Icon([ specifications = [
ShapeSpecification.from_structure( ShapeSpecification.from_structure(
x, icon_extractor, self, Color("#888888") x, extractor, self, Color("#888888")
) )
for x in matcher.add_shapes for x in matcher.add_shapes
])] ]
extra_icons += [Icon(specifications)]
processed |= matcher_tags processed |= matcher_tags
if matcher.set_main_color and main_icon: if matcher.set_main_color and main_icon:
main_icon.recolor(self.get_color(matcher.set_main_color)) 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) # 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: if not main_icon:
main_icon = Icon([ShapeSpecification(default_shape)]) main_icon = Icon([ShapeSpecification(default_shape)])