diff --git a/lib/xmet/geo.py b/lib/xmet/geo.py index 3d55e03..e9bb732 100644 --- a/lib/xmet/geo.py +++ b/lib/xmet/geo.py @@ -3,17 +3,7 @@ import enum import math import shapely -from typing import Self, Union - -def each_intermediate_point(p1: shapely.Point, - p2: shapely.Point, - intersection: Union[shapely.LineString, shapely.MultiLineString]): - typeof = type(intersection) - - if typeof is shapely.LineString: - pass - elif typeof is shapely.MultiLineString: - pass +from typing import Self class PointDirection(enum.Enum): EQUAL = 0 @@ -125,10 +115,12 @@ class PolygonBuilder(): def each_intermediate_point(self, p1: shapely.Point, p2: shapely.Point): count = len(self.bounds) - i1 = self.bounds.nearest_index(p1) + count - i2 = self.bounds.nearest_index(p2) + count + i1 = self.bounds.nearest_index(p1) + i2 = self.bounds.nearest_index(p2) - if i1 > i2: + dist, direction = self.bounds.index_distance(i1, i2) + + if direction is not PointDirection.LEFT: return for i in range(i1, i2+1): @@ -194,10 +186,7 @@ class PolygonBuilder(): # Yield all intermediate points if the first point is to the right # of the last point. # - dist, direction = self.bounds.index_distance(self.point_first, - self.point_last) - - if direction is PointDirection.RIGHT: + 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)