more render() optimization: filter out empty sublevels directly

This commit is contained in:
Laura Klünder 2017-10-20 22:13:46 +02:00
parent 9f59b841b0
commit 6592c344b2
2 changed files with 19 additions and 5 deletions

View file

@ -95,6 +95,14 @@ class LevelRenderData:
new_altitudearea.colors = new_colors
new_geoms.altitudeareas.append(new_altitudearea)
if new_geoms.walls.is_empty and not new_geoms.altitudeareas:
continue
new_geoms.affected_area = unary_union((
*(altitudearea.geometry for altitudearea in new_geoms.altitudeareas),
crop_to.intersection(new_geoms.walls.buffer(1))
))
for access_restriction, area in old_geoms.restricted_spaces_indoors.items():
new_area = crop_to.intersection(area)
if not new_area.is_empty:
@ -135,6 +143,7 @@ class LevelGeometries:
self.access_restriction_affected = None
self.restricted_spaces_indoors = None
self.restricted_spaces_outdoors = None
self.affected_area = None
@staticmethod
def build_for_level(level):

View file

@ -1,4 +1,5 @@
from django.utils.functional import cached_property
from shapely import prepared
from shapely.geometry import box
from shapely.ops import unary_union
@ -48,8 +49,12 @@ class SVGRenderer:
# add no access restriction to “unlocked“ access restrictions so lookup gets easier
unlocked_access_restrictions = self.unlocked_access_restrictions | set([None])
bbox = self.bbox
bbox_prep = prepared.prep(bbox)
for geoms, default_height in self.level_render_data.levels:
crop_to = self.bbox
if not bbox_prep.intersects(geoms.affected_area):
continue
# 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()
@ -62,7 +67,7 @@ class SVGRenderer:
# 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)),
svg.add_geometry(bbox.intersection(altitudearea.geometry.difference(crop_areas)),
fill_color='#eeeeee', altitude=altitudearea.altitude)
for color, areas in altitudearea.colors.items():
@ -70,15 +75,15 @@ class SVGRenderer:
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)
svg.add_geometry(bbox.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,
if not add_walls.is_empty or not geoms.walls.is_empty:
svg.add_geometry(crop_to.intersection(geoms.walls.union(add_walls)),
svg.add_geometry(bbox.intersection(geoms.walls.union(add_walls)),
fill_color='#aaaaaa', stroke_px=0.5, stroke_color='#aaaaaa', elevation=default_height)
if not geoms.doors.is_empty:
svg.add_geometry(crop_to.intersection(geoms.doors.difference(add_walls)),
svg.add_geometry(bbox.intersection(geoms.doors.difference(add_walls)),
fill_color='#ffffff', stroke_px=0.5, stroke_color='#ffffff')
return svg