Implement index_distance()
This commit is contained in:
parent
a4cf0cddc5
commit
5e6b774595
1 changed files with 23 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import enum
|
||||
import math
|
||||
import shapely
|
||||
|
||||
|
@ -14,6 +15,11 @@ def each_intermediate_point(p1: shapely.Point,
|
|||
elif typeof is shapely.MultiLineString:
|
||||
pass
|
||||
|
||||
class PointDirection(enum.Enum):
|
||||
EQUAL = 0
|
||||
LEFT = enum.auto()
|
||||
RIGHT = enum.auto()
|
||||
|
||||
class PointSequence(list):
|
||||
linestring: shapely.LineString
|
||||
polygon: shapely.Polygon
|
||||
|
@ -73,6 +79,23 @@ class PointSequence(list):
|
|||
|
||||
return indices[0][0]
|
||||
|
||||
def index_distance(self, i1: int, i2: int) -> int:
|
||||
"""
|
||||
Returns the index distance of i1 relative to i2, and whether i1 is
|
||||
considered left of, equal to, or right of i2.
|
||||
"""
|
||||
count = len(self)
|
||||
value = count - ((i1 - i2) % count)
|
||||
|
||||
if value == 0:
|
||||
direction = PointDirection.EQUAL
|
||||
elif value > count / 2:
|
||||
direction = PointDirection.RIGHT
|
||||
else:
|
||||
direction = PointDirection.LEFT
|
||||
|
||||
return value, direction
|
||||
|
||||
class PolygonBuilder():
|
||||
point_first: shapely.Point
|
||||
point_last: shapely.Point
|
||||
|
|
Loading…
Add table
Reference in a new issue