How to use the pyclipper.PFT_NONZERO function in pyclipper

To help you get started, we’ve selected a few pyclipper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUDelft-CNS-ATM / bluesky / bluesky / traffic / asas / SSD.py View on Github external
pc2.AddPath(part, pyclipper.PT_SUBJECT, True)
                        elif priocode == "RS3":
                            # Small ring
                            xyp = (tuple(map(tuple, np.flipud(xyc * min(vmax,gs_ap[i] + 0.1)))), tuple(map(tuple , xyc * max(vmin,gs_ap[i] - 0.1))))
                            part = pyclipper.scale_to_clipper(xyp)
                            pc2.AddPaths(part, pyclipper.PT_SUBJECT, True)
                        elif priocode == "RS4":
                            hdg_sel = hdg[i] * np.pi / 180
                            xyp = np.array([[np.sin(hdg_sel-0.0087),np.cos(hdg_sel-0.0087)],
                                            [0,0],
                                            [np.sin(hdg_sel+0.0087),np.cos(hdg_sel+0.0087)]],
                                            dtype=np.float64)
                            part = pyclipper.scale_to_clipper(tuple(map(tuple, 1.1 * vmax * xyp)))
                            pc2.AddPath(part, pyclipper.PT_SUBJECT, True)
                        # Execute clipper command
                        ARV_calc = pyclipper.scale_from_clipper(pc2.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO))
                        N += 1
                        # If no smaller ARV is found, take the full ARV
                        if len(ARV_calc) == 0:
                            ARV_calc = ARV
                        # Check multi exteriors, if this layer is not a list, it means it has no exteriors
                        # In that case, make it a list, such that its format is consistent with further code
                        if not type(ARV_calc[0][0]) == list:
                            ARV_calc = [ARV_calc]
                    # Shortest way out prio, so use full SSD (ARV_calc = ARV)
                    else:
                        ARV_calc = ARV
                    # Update calculatable ARV for resolutions
                    ARV_calc_loc[i] = ARV_calc

    # If sequential approach, the local should go elsewhere
    if not priocode == "RS7" and not priocode == "RS8":
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / asas / SSD.py View on Github external
if brg_own[j] >= -20. and brg_own[j] <= 110.:
                            # Head-on or converging from right
                            pc_rota.AddPath(VO, pyclipper.PT_CLIP, True)
                        elif brg_other[j] <= -110. or brg_other[j] >= 110.:
                            # In overtaking position
                            pc_rota.AddPath(VO, pyclipper.PT_CLIP, True)
                    # Detect conflicts for smaller layer in RS7 and RS8
                    if priocode == "RS7" or priocode == "RS8":
                        if pyclipper.PointInPolygon(pyclipper.scale_to_clipper((gseast[i],gsnorth[i])),VO):
                            asas.inconf2[i] = True
                    if priocode == "RS5":
                        if pyclipper.PointInPolygon(pyclipper.scale_to_clipper((apeast[i],apnorth[i])),VO):
                            asas.ap_free[i] = False

                # Execute clipper command
                FRV = pyclipper.scale_from_clipper(pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO))

                ARV = pc.Execute(pyclipper.CT_DIFFERENCE, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)

                if not priocode == "RS1" and not priocode == "RS5" and not priocode == "RS7" and not priocode == "RS8":
                    # Make another clipper object for extra intersections
                    pc2 = pyclipper.Pyclipper()
                    # When using RotA clip with pc_rota
                    if priocode == "RS6":
                        # Calculate ARV for RotA
                        ARV_rota = pc_rota.Execute(pyclipper.CT_DIFFERENCE, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)
                        if len(ARV_rota) > 0:
                            pc2.AddPaths(ARV_rota, pyclipper.PT_CLIP, True)
                    else:
                        # Put the ARV in there, make sure it's not empty
                        if len(ARV) > 0:
                            pc2.AddPaths(ARV, pyclipper.PT_CLIP, True)
github cwig / start_follow_read / utils / PAGE_xml.py View on Github external
region_poly = r['bounding_poly']
        scores_i = []
        scores.append(scores_i)
        for p in polys:
            pc = pyclipper.Pyclipper()

            try:
                pc.AddPath(p, pyclipper.PT_CLIP, True)
            except:
                scores_i.append(0)
                # print p
                print "Failed to assign text line, probably not an issue"
                continue
            pc.AddPath(region_poly, pyclipper.PT_SUBJECT, True)

            solution = pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)

            # pts = np.array(region_poly, np.int32)
            # pts = pts.reshape((-1,1,2))
            # cv2.polylines(img,[pts],True,(0,0,255), thickness=3)

            area = 0
            for path in solution:
                area += pyclipper.Area(path)

            scores_i.append(area)

    background_scores = []
    total_areas = []
    for p in polys:
        pc = pyclipper.Pyclipper()
        try:
github jamiebull1 / geomeppy / geomeppy / geom / clippers.py View on Github external
def intersect(self, poly):
        # type: (Polygon) -> List[Polygon]
        """Intersect with another polygon.

        :param poly: The clip polygon.
        :returns: False if no intersection, otherwise a list of Polygons representing each intersection.

        """
        clipper = self._prepare_clipper(poly)
        if not clipper:
            return []
        intersections = clipper.Execute(
            pc.CT_INTERSECTION, pc.PFT_NONZERO, pc.PFT_NONZERO)

        return self._process(intersections)
github deeplycloudy / glmtools / glmtools / grid / clipping.py View on Github external
def join_polys(polys, scale=True):
    """ Given a list of polygons, merge them (union) and return a list
        of merged polygons
    """
    pc = pyclipper.Pyclipper()

    if scale:
        polys = scale_to_clipper(polys)

    results=[]
    pc.AddPaths(polys, pyclipper.PT_SUBJECT, True)
    clip_polys = pc.Execute(pyclipper.CT_UNION, pyclipper.PFT_NONZERO, 
        pyclipper.PFT_NONZERO)
    if scale:
        clip_polys = scale_from_clipper(clip_polys)
    results.extend([cp for cp in clip_polys]) 
    pc.Clear()
    return results
github typemytype / booleanOperations / Lib / booleanOperations / booleanOperationManager.py View on Github external
- some kind of a log
"""


_operationMap = {
    "union": pyclipper.CT_UNION,
    "intersection": pyclipper.CT_INTERSECTION,
    "difference": pyclipper.CT_DIFFERENCE,
    "xor": pyclipper.CT_XOR,
}

_fillTypeMap = {
    "evenOdd": pyclipper.PFT_EVENODD,
    "nonZero": pyclipper.PFT_NONZERO,
    # we keep the misspelling for compatibility with earlier versions
    "noneZero": pyclipper.PFT_NONZERO,
}


def clipExecute(subjectContours, clipContours, operation, subjectFillType="nonZero",
                clipFillType="nonZero"):
    pc = pyclipper.Pyclipper()

    for i, subjectContour in enumerate(subjectContours):
        try:
            pc.AddPath(subjectContour, pyclipper.PT_SUBJECT)
        except pyclipper.ClipperException:
            # skip invalid paths with no area
            if pyclipper.Area(subjectContour) != 0:
                raise InvalidSubjectContourError("contour %d is invalid for clipping" % i)

    for j, clipContour in enumerate(clipContours):