speedup cut_polygon_with_line calls by using list of polygons
This commit is contained in:
parent
f672ee107a
commit
7f5b614620
2 changed files with 7 additions and 7 deletions
|
@ -192,8 +192,8 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
|||
ramp.space = space.pk
|
||||
ramps.append(ramp)
|
||||
|
||||
areas = MultiPolygon(tuple(orient(polygon) for polygon in assert_multipolygon(
|
||||
unary_union(areas+list(door.geometry for door in level.doors.all())))
|
||||
areas = tuple(orient(polygon) for polygon in assert_multipolygon(
|
||||
unary_union(areas+list(door.geometry for door in level.doors.all()))
|
||||
))
|
||||
|
||||
# collect all stairs on this level
|
||||
|
@ -205,11 +205,11 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
|||
|
||||
# divide areas using stairs
|
||||
for stair in stairs:
|
||||
areas = MultiPolygon(cut_polygon_with_line(areas, stair))
|
||||
areas = cut_polygon_with_line(areas, stair)
|
||||
|
||||
# create altitudearea objects
|
||||
areas = [AltitudeArea(geometry=clean_cut_polygon(area), level=level)
|
||||
for area in assert_multipolygon(areas)]
|
||||
for area in areas]
|
||||
|
||||
# prepare area geometries
|
||||
for area in areas:
|
||||
|
|
|
@ -133,9 +133,9 @@ def cut_line_with_point(line: LineString, point: Point):
|
|||
|
||||
|
||||
def cut_polygon_with_line(polygon: Union[Polygon, MultiPolygon], line: LineString, debug=False) -> Sequence[Polygon]:
|
||||
orig_polygon = polygon
|
||||
orig_polygon = assert_multipolygon(polygon) if isinstance(polygon, (MultiPolygon, Polygon)) else polygon
|
||||
polygons: List[List[LinearRing]] = []
|
||||
for polygon in assert_multipolygon(polygon):
|
||||
for polygon in orig_polygon:
|
||||
rings = getattr(polygon, 'c3nav_cache', None)
|
||||
if not rings:
|
||||
rings = [polygon.exterior, *polygon.interiors]
|
||||
|
@ -160,7 +160,7 @@ def cut_polygon_with_line(polygon: Union[Polygon, MultiPolygon], line: LineStrin
|
|||
points = deque(sorted(points, key=lambda p: line.project(p.point)))
|
||||
|
||||
if not points:
|
||||
return tuple(assert_multipolygon(orig_polygon))
|
||||
return orig_polygon
|
||||
|
||||
# go through all points and cut pair-wise
|
||||
last = points.popleft()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue