def polygon_clip_unnest()

in utils/box_intersection.pyx [0:0]


def polygon_clip_unnest(float [:, :] subjectPolygon, float [:, :] clipPolygon):
    """ Clip a polygon with another polygon.

   Ref: https://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping#Python

   Args:
     subjectPolygon: a list of (x,y) 2d points, any polygon.
     clipPolygon: a list of (x,y) 2d points, has to be *convex*
   Note:
     **points have to be counter-clockwise ordered**

   Return:
     a list of (x,y) vertex point for the intersection polygon.
   """
    outputList = [subjectPolygon[x] for x in range(subjectPolygon.shape[0])]
    cp1 = clipPolygon[-1]
    cdef int lenc = len(clipPolygon)
    cdef int iidx = 0

    # for clipVertex in clipPolygon:
    for cidx in range(lenc):
        clipVertex = clipPolygon[cidx]
        cp2 = clipVertex
        inputList = outputList.copy()
        outputList.clear()
        s = inputList[-1]

        inc = len(inputList)
 
        # for subjectVertex in inputList:
        for iidx in range(inc):
            subjectVertex = inputList[iidx]
            e = subjectVertex
            if inside(cp1, cp2, e):
                if not inside(cp1, cp2, s):
                    outputList.append(computeIntersection(cp1, cp2, s, e))
                outputList.append(e)
            elif inside(cp1, cp2, s):
                outputList.append(computeIntersection(cp1, cp2, s, e))
            s = e
        cp1 = cp2
        if len(outputList) == 0:
            break
    return outputList