only look through holes to levels below

This commit is contained in:
Laura Klünder 2017-10-19 15:31:30 +02:00
parent ed2cedaa87
commit f167a72a49
2 changed files with 36 additions and 5 deletions

View file

@ -13,6 +13,13 @@ class LevelGeometries:
self.altitudeareas = []
self.walls = None
self.doors = None
self.holes = None
@staticmethod
def crop(self, geometry, crop_to):
if crop_to is None:
return geometry
return geometry.intersection(crop_to)
@staticmethod
def rebuild():
@ -32,6 +39,9 @@ class LevelGeometries:
spaces_geom = unary_union([s.geometry for s in level.spaces.all()])
geoms.doors = unary_union([d.geometry for d in level.doors.all()])
walkable_geom = unary_union([s.walkable_geom for s in level.spaces.all()]).union(geoms.doors)
if level.on_top_of_id is None:
geoms.holes = spaces_geom.difference(walkable_geom)
print(level.pk, geoms.holes.area)
for altitudearea in level.altitudeareas.all():
geoms.altitudeareas.append((altitudearea.geometry.intersection(walkable_geom), altitudearea.altitude))

View file

@ -10,13 +10,34 @@ def render_svg(level, miny, minx, maxy, maxx, scale=1):
within_coords = (minx-2, miny-2, maxx+2, maxy+2)
bbox = box(*within_coords)
for geoms, default_height in get_render_level_data(level):
for altitudearea_geom, altitude in geoms.altitudeareas:
svg.add_geometry(bbox.intersection(altitudearea_geom), fill_color='#eeeeee', altitude=altitude)
render_level_data = get_render_level_data(level)
svg.add_geometry(bbox.intersection(geoms.walls),
crop_to = None
primary_level_count = 0
for geoms, default_height in reversed(render_level_data):
if geoms.holes is not None:
print(geoms.holes.area)
primary_level_count += 1
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 render_level_data:
crop_to = bbox
if geoms.crop_to is not None:
crop_to = crop_to.intersection(geoms.crop_to)
for altitudearea_geom, altitude in geoms.altitudeareas:
svg.add_geometry(crop_to.intersection(altitudearea_geom), fill_color='#eeeeee', altitude=altitude)
svg.add_geometry(crop_to.intersection(geoms.walls),
fill_color='#aaaaaa', stroke_px=0.5, stroke_color='#aaaaaa', elevation=default_height)
svg.add_geometry(bbox.intersection(geoms.doors), fill_color='#ffffff', elevation=0)
svg.add_geometry(crop_to.intersection(geoms.doors), fill_color='#ffffff', elevation=0)
return svg