Skip to content

Commit

Permalink
pass ccw through to get_oriented_ring
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Oct 31, 2023
1 parent 0f8cc7f commit 5b461c7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pygeoif/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
mpre: Pattern[str] = re.compile(r"\(\((.+?)\)\)")


def get_oriented_ring(ring: LineType, ccw: bool) -> LineType: # noqa: FBT001
s = 1.0 if ccw else -1.0
return ring if signed_area(ring) / s >= 0 else ring[::-1]


def orient(polygon: Polygon, ccw: bool = True) -> Polygon: # noqa: FBT001, FBT002
"""
Return a polygon with exteriors and interiors in the right orientation.
Expand All @@ -68,14 +73,9 @@ def orient(polygon: Polygon, ccw: bool = True) -> Polygon: # noqa: FBT001, FBT0
and the interiors will be in clockwise orientation, or
the other way round when ccw is False.
"""

def get_oriented_ring(ring: LineType) -> LineType:
return ring if signed_area(ring) / s >= 0 else ring[::-1]

s = 1.0 if ccw else -1.0
shell = get_oriented_ring(polygon.exterior.coords)
s = -s # flip orientation for holes
holes = [get_oriented_ring(ring.coords) for ring in polygon.interiors]
shell = get_oriented_ring(polygon.exterior.coords, ccw)
ccw = not ccw # flip orientation for holes
holes = [get_oriented_ring(ring.coords, ccw) for ring in polygon.interiors]
return Polygon(shell=shell, holes=holes)


Expand Down

0 comments on commit 5b461c7

Please sign in to comment.