def getLoopConvex(polygonComplex):
 if (len(polygonComplex) < 4):
  return polygonComplex
 leftPointIndex = getLeftPointIndex(polygonComplex)
 around = (polygonComplex[(leftPointIndex + 1):] + polygonComplex[:(leftPointIndex + 1)])
 lastAddedIndex = (-1)
 lastPoint = around[(-1)]
 aroundLengthMinusOne = (len(around) - 1)
 polygonConvex = []
 segment = complex(0.0, (-1.0))
 while (lastAddedIndex < aroundLengthMinusOne):
  lastAddedIndex = getLoopConvexAddedIndex(around, lastAddedIndex, lastPoint, segment)
  segment = getNormalized((around[lastAddedIndex] - lastPoint))
  lastPoint = around[lastAddedIndex]
  polygonConvex.append(lastPoint)
 return polygonConvex

def getLoopConvex ( polygonComplex ) : if ( len ( polygonComplex ) < 4 ) : return polygonComplex leftPointIndex = getLeftPointIndex ( polygonComplex ) around = ( polygonComplex [ ( leftPointIndex + 1 ) : ] + polygonComplex [ : ( leftPointIndex + 1 ) ] ) lastAddedIndex = ( - 1 ) lastPoint = around [ ( - 1 ) ] aroundLengthMinusOne = ( len ( around ) - 1 ) polygonConvex = [ ] segment = complex ( 0.0 , ( - 1.0 ) ) while ( lastAddedIndex < aroundLengthMinusOne ) : lastAddedIndex = getLoopConvexAddedIndex ( around , lastAddedIndex , lastPoint , segment ) segment = getNormalized ( ( around [ lastAddedIndex ] - lastPoint ) ) lastPoint = around [ lastAddedIndex ] polygonConvex . append ( lastPoint ) return polygonConvex
get convex hull of a complex polygon using gift wrap algorithm .