add more comments to renderer/svg.py

This commit is contained in:
Laura Klünder 2017-10-19 17:55:41 +02:00
parent 2a64262e90
commit c59b20a5bb

View file

@ -49,14 +49,19 @@ class SVGRenderer:
def render(self):
svg = SVGImage(bounds=((self.miny, self.minx), (self.maxy, self.maxx)), scale=self.scale, buffer=1)
# add no access restriction to “unlocked“ access restrictions so lookup gets easier
unlocked_access_restrictions = self.unlocked_access_restrictions | set([None])
# choose a crop area for each level. non-intermediate levels (not on_top_of) below the one that we are
# currently rendering will be cropped to only render content that is visible through holes indoors in the
# levels above them.
crop_to = None
primary_level_count = 0
for geoms, default_height in reversed(self.level_render_data):
if geoms.holes is not None:
primary_level_count += 1
# set crop area if we area on the second primary layer from top or below
geoms.crop_to = crop_to if primary_level_count > 1 else None
if geoms.holes is not None:
@ -70,6 +75,7 @@ class SVGRenderer:
if geoms.crop_to is not None:
crop_to = crop_to.intersection(geoms.crop_to)
# hide indoor and outdoor rooms if their access restriction was not unlocked
add_walls = unary_union(tuple(area for access_restriction, area in geoms.restricted_spaces_indoors.items()
if access_restriction not in unlocked_access_restrictions))
crop_areas = unary_union(
@ -77,16 +83,20 @@ class SVGRenderer:
if access_restriction not in unlocked_access_restrictions)
).union(add_walls)
# render altitude areas in default ground color and add ground colors to each one afterwards
# shadows are directly calculated and added by the SVGImage class
for altitudearea in geoms.altitudeareas:
svg.add_geometry(crop_to.intersection(altitudearea.geometry.difference(crop_areas)),
fill_color='#eeeeee', altitude=altitudearea.altitude)
for color, areas in altitudearea.colors.items():
# only select ground colors if their access restriction is unlocked
areas = tuple(area for access_restriction, area in areas.items()
if access_restriction in unlocked_access_restrictions)
if areas:
svg.add_geometry(crop_to.intersection(unary_union(areas)), fill_color=color, elevation=0)
# add walls, stroke_px makes sure that all walls are at least 1px thick on all zoom levels,
svg.add_geometry(crop_to.intersection(geoms.walls.union(add_walls)),
fill_color='#aaaaaa', stroke_px=0.5, stroke_color='#aaaaaa', elevation=default_height)