From 5a934e2f37c0a4df7ae5bc128d111876a7d2bc28 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Wed, 27 Apr 2022 00:11:10 +0300 Subject: [PATCH] Issues #126: refactor figures sorting. --- map_machine/constructor.py | 4 ++++ map_machine/mapper.py | 10 +++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/map_machine/constructor.py b/map_machine/constructor.py index 34ad72f..bf1c50c 100644 --- a/map_machine/constructor.py +++ b/map_machine/constructor.py @@ -529,6 +529,10 @@ class Constructor: ) self.points.append(point) + def get_sorted_figures(self) -> list[StyledFigure]: + """Get all figures sorted by priority.""" + return sorted(self.figures, key=lambda x: x.line_style.priority) + def check_level_number(tags: Tags, level: float) -> bool: """Check if element described by tags is no the specified level.""" diff --git a/map_machine/mapper.py b/map_machine/mapper.py index 353ac03..f142002 100644 --- a/map_machine/mapper.py +++ b/map_machine/mapper.py @@ -18,7 +18,6 @@ from map_machine.constructor import Constructor from map_machine.drawing import draw_text from map_machine.feature.building import Building, draw_walls, BUILDING_SCALE from map_machine.feature.road import Intersection, Road, RoadPart -from map_machine.figure import StyledFigure from map_machine.geometry.boundary_box import BoundaryBox from map_machine.geometry.flinger import Flinger from map_machine.geometry.vector import Segment @@ -59,16 +58,13 @@ class Map: self.svg.add( Rect((0.0, 0.0), self.flinger.size, fill=self.background_color) ) - ways: list[StyledFigure] = sorted( - constructor.figures, key=lambda x: x.line_style.priority - ) logging.info("Drawing ways...") - for way in ways: - path_commands: str = way.get_path(self.flinger) + for figure in constructor.get_sorted_figures(): + path_commands: str = figure.get_path(self.flinger) if path_commands: path: SVGPath = SVGPath(d=path_commands) - path.update(way.line_style.style) + path.update(figure.line_style.style) self.svg.add(path) constructor.roads.draw(self.svg, self.flinger)