This is better for my current corner case

This commit is contained in:
XANTRONIX 2025-03-24 13:38:14 -04:00
parent 150ab35d04
commit 9b9a95b71a

View file

@ -100,12 +100,8 @@ class PolygonBuilder():
def yield_point(self, point: shapely.Point): def yield_point(self, point: shapely.Point):
""" """
Yield the single point to the caller, while maintaining state of Yield the single point to the caller, while maintaining state of
whether this point is the first or last point seen by the polygon number of points yielded to the caller.
builder.
""" """
if self.point_first is None:
self.point_first = point
self.point_last = point self.point_last = point
yield point yield point
@ -130,6 +126,11 @@ class PolygonBuilder():
last = None last = None
for point in self.sequence: for point in self.sequence:
if self.point_first is None:
self.point_first = point
self.point_last = point
if last is None: if last is None:
last = point last = point
continue continue
@ -170,7 +171,6 @@ class PolygonBuilder():
continue continue
yield from self.yield_point(last_geom) yield from self.yield_point(last_geom)
yield from self.each_intermediate_point(last_geom, geom)
yield from self.yield_point(geom) yield from self.yield_point(geom)
last_geom = geom last_geom = geom
@ -182,14 +182,6 @@ class PolygonBuilder():
if point_within: if point_within:
yield from self.yield_point(point) yield from self.yield_point(point)
#
# Yield all intermediate points if the first point is to the right
# of the last point.
#
if self.point_first is not None and self.point_last is not None:
yield from self.each_intermediate_point(self.point_last,
self.point_first)
last = point last = point
def process(self) -> shapely.Polygon: def process(self) -> shapely.Polygon: