Skip to content

Commit cfd568a

Browse files
fjzzq2002lin-toto
authored andcommitted
add strict option
1 parent c7dc65e commit cfd568a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cyaron/polygon.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def convex_hull(n, **kwargs):
4444
# fx, fy are functions which map [0,1] to int or float
4545
fx = kwargs.get("fx", lambda x: x)
4646
fy = kwargs.get("fy", lambda x: x)
47+
strict = kwargs.get("strict", True)
4748
sz = n * 2
4849
result = []
4950
while len(result) < n:
@@ -74,8 +75,9 @@ def convex_hull(n, **kwargs):
7475
a = st[len(st) - 1]
7576
b = points[i]
7677
o = st[len(st) - 2]
77-
if (a[0] - o[0]) * (b[1] - o[1]) - \
78-
(a[1] - o[1]) * (b[0] - o[0]) >= 0:
78+
tmp = (a[0] - o[0]) * (b[1] - o[1]) - \
79+
(a[1] - o[1]) * (b[0] - o[0])
80+
if tmp > 0 or (tmp == 0 and not strict):
7981
break
8082
st.pop()
8183
st.append(points[i])
@@ -85,8 +87,9 @@ def convex_hull(n, **kwargs):
8587
a = st[len(st) - 1]
8688
b = points[i]
8789
o = st[len(st) - 2]
88-
if (a[0] - o[0]) * (b[1] - o[1]) - \
89-
(a[1] - o[1]) * (b[0] - o[0]) >= 0:
90+
tmp = (a[0] - o[0]) * (b[1] - o[1]) - \
91+
(a[1] - o[1]) * (b[0] - o[0])
92+
if tmp > 0 or (tmp == 0 and not strict):
9093
break
9194
st.pop()
9295
st.append(points[i])

0 commit comments

Comments
 (0)