Skip to content

Commit

Permalink
fix(geometry): is_clockwise() now works as expected for a disv problem (
Browse files Browse the repository at this point in the history
#1374)

* fix(geometry): is_clockwise() now works as expected for a disv problem
* new test asserts a failure for a counter-clockwise set of vertices.  Ran black on new test script
  • Loading branch information
emorway-usgs committed Mar 16, 2022
1 parent 8ae9b4d commit 3a1d94a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 31 additions & 0 deletions autotest/t081_test_is_clockwise.py
@@ -0,0 +1,31 @@
import flopy
import numpy as np


def test_does_isclockwise_work():
# Create some points
verts = []
verts.append([0, 20.0000, 30.0000])
verts.append([1, 18.9394, 25.9806])
verts.append([2, 21.9192, 25.3013])
verts.append([3, 22.2834, 27.5068])

# List the points above in counter-clockwise order
iv = [0, 0, 1, 2, 3]

# Organize the previous info into lists of x an y data
xv, yv = [], []
xyverts = []
for v in iv[1:]:
tiv, txv, tyv = verts[v]
xv.append(txv)
yv.append(tyv)

# is_clockwise() should fail and return false
rslt = flopy.utils.geometry.is_clockwise(xv, yv)

assert bool(rslt) is False, "is_clockwise() failed"


if __name__ == "__main__":
test_does_isclockwise_work()
6 changes: 3 additions & 3 deletions flopy/utils/geometry.py
Expand Up @@ -827,10 +827,10 @@ def is_clockwise(*geom):
geom = GeoSpatialUtil(geom, shapetype="Polygon")
x, y = np.array(geom.points[0]).T

if not (x[0] == x[-1]) and (y[0] == y[-1]):
if not ((x[0] == x[-1]) and (y[0] == y[-1])):
# close the ring if needed
x = np.append(x, x[-1])
y = np.append(y, y[-1])
x = np.append(x, x[0])
y = np.append(y, y[0])
return np.sum((np.diff(x)) * (y[1:] + y[:-1])) > 0


Expand Down

0 comments on commit 3a1d94a

Please sign in to comment.