cache LevelRenderData for each level completely (+ cropping)

This commit is contained in:
Laura Klünder 2017-10-20 22:02:51 +02:00
parent b9c3a961af
commit 9f59b841b0
5 changed files with 223 additions and 125 deletions

View file

@ -29,12 +29,8 @@ class SVGRenderer:
@cached_property
def affected_access_restrictions(self):
access_restrictions = set()
for geoms, default_height in self.level_render_data:
for access_restriction, area in geoms.access_restriction_affected.items():
if access_restriction not in access_restrictions and area.intersects(self.bbox):
access_restrictions.add(access_restriction)
return access_restrictions
return set(ar for ar, area in self.level_render_data.access_restriction_affected.items()
if area.intersects(self.bbox))
@cached_property
def unlocked_access_restrictions(self):
@ -52,28 +48,8 @@ class SVGRenderer:
# 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:
if crop_to is None:
crop_to = geoms.holes
else:
crop_to = crop_to.intersection(geoms.holes)
for geoms, default_height in self.level_render_data:
for geoms, default_height in self.level_render_data.levels:
crop_to = self.bbox
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()
@ -97,10 +73,12 @@ class SVGRenderer:
svg.add_geometry(crop_to.intersection(unary_union(areas)), fill_color=color)
# 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)
if not add_walls.is_empty or not geoms.walls.is_empty:
svg.add_geometry(crop_to.intersection(geoms.walls.union(add_walls)),
fill_color='#aaaaaa', stroke_px=0.5, stroke_color='#aaaaaa', elevation=default_height)
svg.add_geometry(crop_to.intersection(geoms.doors.difference(add_walls)),
fill_color='#ffffff', stroke_px=0.5, stroke_color='#ffffff')
if not geoms.doors.is_empty:
svg.add_geometry(crop_to.intersection(geoms.doors.difference(add_walls)),
fill_color='#ffffff', stroke_px=0.5, stroke_color='#ffffff')
return svg