bugfix convex hull: the hull can contains straight tangents
This commit is contained in:
parent
cfa38b6216
commit
4504f89d30
1 changed files with 11 additions and 6 deletions
17
hull.py
17
hull.py
|
|
@ -98,21 +98,26 @@ def right_tangent(hull, p):
|
||||||
return icenter
|
return icenter
|
||||||
|
|
||||||
# If the tangent touches the left point in the window.
|
# If the tangent touches the left point in the window.
|
||||||
elif ( c_side == TURN_LEFT and ( l_next == TURN_RIGHT or l_prev == l_next) ) \
|
elif c_side == TURN_LEFT and ( l_next == TURN_RIGHT or l_prev == l_next ) \
|
||||||
or ( c_side == TURN_RIGHT and c_prev == TURN_RIGHT ):
|
or c_side == TURN_RIGHT and c_prev == TURN_RIGHT:
|
||||||
# Do not consider points at the RIGHT of the center.
|
# Do not consider points at the RIGHT of the center.
|
||||||
iright = icenter
|
iright = icenter
|
||||||
|
|
||||||
# If the tangent touches the right point in the window.
|
# If the tangent touches the right point in the window,
|
||||||
else:
|
# but this is not the last possible tangent.
|
||||||
|
elif icenter+1 < iright:
|
||||||
# Do not consider points at the LEFT of the center.
|
# Do not consider points at the LEFT of the center.
|
||||||
ileft = icenter + 1
|
ileft = icenter+1
|
||||||
# Switch sides: if the turn toward the point before the center
|
# Switch sides: if the turn toward the point before the center
|
||||||
# was to the right, search to the left and conversely.
|
# was to the right, search to the left and conversely.
|
||||||
l_prev = -1 * c_next
|
l_prev = -1 * c_next
|
||||||
# Update the turn to the next left point.
|
# Update the turn to the next left point.
|
||||||
l_next = turn( p, hull[ileft], hull[ at(ileft+1) ] )
|
l_next = turn( p, hull[ileft], hull[ at(ileft+1) ] )
|
||||||
|
|
||||||
|
# There is no more possible tangent, the hull contains a straight segment.
|
||||||
|
else:
|
||||||
|
return ileft
|
||||||
|
|
||||||
return ileft
|
return ileft
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -177,7 +182,7 @@ def convex_hull(points):
|
||||||
LOG( "Guess",guess)
|
LOG( "Guess",guess)
|
||||||
hulls = []
|
hulls = []
|
||||||
for i in range(0, len(points), guess):
|
for i in range(0, len(points), guess):
|
||||||
LOG(".")
|
# LOG(".")
|
||||||
# Split the points into chunks of (roughly) the guess.
|
# Split the points into chunks of (roughly) the guess.
|
||||||
chunk = points[i:i + guess]
|
chunk = points[i:i + guess]
|
||||||
# Find the corresponding convex hull of these chunks.
|
# Find the corresponding convex hull of these chunks.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue