How to use the pyclipper.PT_SUBJECT 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
# Efficient calculation of box, see notes
                        if priocode == "RS2" or priocode == "RS6":
                            # CW or right-turning
                            sin_table = np.array([[1,0],[-1,0],[-1,-1],[1,-1]], dtype=np.float64)
                            cos_table = np.array([[0,1],[0,-1],[1,-1],[1,1]], dtype=np.float64)
                        elif priocode == "RS9":
                            # CCW or left-turning
                            sin_table = np.array([[1,0],[1,1],[-1,1],[-1,0]], dtype=np.float64)
                            cos_table = np.array([[0,1],[-1,1],[-1,-1],[0,-1]], dtype=np.float64)
                        # Overlay a part of the full SSD
                        if priocode == "RS2" or priocode == "RS9" or priocode == "RS6":
                            # Normalized coordinates of box
                            xyp = np.sin(own_hdg) * sin_table + np.cos(own_hdg) * cos_table
                            # Scale with vmax (and some factor) and put in tuple
                            part = pyclipper.scale_to_clipper(tuple(map(tuple, 1.1 * vmax * xyp)))
                            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
github lquirosd / P2PaLA / evalTools / metrics.py View on Github external
def poly_intersect(subj, clip):
    """
    """
    pc = pyclipper.Pyclipper()
    pc.AddPath(clip, pyclipper.PT_CLIP, True)
    pc.AddPath(subj, pyclipper.PT_SUBJECT, True)
    solution = pc.Execute(
        pyclipper.CT_INTERSECTION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD
    )
    return np.array(solution)
github TUDelft-CNS-ATM / bluesky / bluesky / traffic / asas / SSD.py View on Github external
# Get vertices in an x- and y-array of size (ntraf-1)*3x1
                x = np.concatenate((gseast[i_other],
                                    x1[ind] * fix + gseast[i_other],
                                    x2[ind] * fix + gseast[i_other]))
                y = np.concatenate((gsnorth[i_other],
                                    y1[ind] * fix + gsnorth[i_other],
                                    y2[ind] * fix + gsnorth[i_other]))
                # Reshape [(ntraf-1)x3] and put arrays in one array [(ntraf-1)x3x2]
                x = np.transpose(x.reshape(3, np.shape(i_other)[0]))
                y = np.transpose(y.reshape(3, np.shape(i_other)[0]))
                xy = np.dstack((x,y))

                # Make a clipper object
                pc = pyclipper.Pyclipper()
                # Add circles (ring-shape) to clipper as subject
                pc.AddPaths(pyclipper.scale_to_clipper(circle_tup), pyclipper.PT_SUBJECT, True)

                # Extra stuff needed for RotA
                if priocode == "RS6":
                    # Make another clipper object for RotA
                    pc_rota = pyclipper.Pyclipper()
                    pc_rota.AddPaths(pyclipper.scale_to_clipper(circle_tup), pyclipper.PT_SUBJECT, True)
                    # Bearing calculations from own view and other view
                    brg_own = np.mod((np.rad2deg(qdr[ind]) + fix_ang - hdg[i]) + 540., 360.) - 180.
                    brg_other = np.mod((np.rad2deg(qdr[ind]) + 180. - fix_ang - hdg[i_other]) + 540., 360.) - 180.

                # Add each other other aircraft to clipper as clip
                for j in range(np.shape(i_other)[0]):
                    ## Debug prints
                    ## print(traf.id[i] + " - " + traf.id[i_other[j]])
                    ## print(dist[ind[j]])
                    # Scale VO when not in LOS
github typemytype / booleanOperations / Lib / booleanOperations / booleanOperationManager.py View on Github external
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):
        try:
            pc.AddPath(clipContour, pyclipper.PT_CLIP)
        except pyclipper.ClipperException:
            # skip invalid paths with no area
            if pyclipper.Area(clipContour) == 0:
                raise InvalidClippingContourError("contour %d is invalid for clipping" % j)

    bounds = pc.GetBounds()
    if (bounds.bottom, bounds.left, bounds.top, bounds.right) == (0, 0, 0, 0):
        # do nothing if there are no paths
github tilezen / mapbox-vector-tile / mapbox_vector_tile / polygon.py View on Github external
the polygon, and can reconstruct the orientation of the polygon from that.
    The pyclipper library is robust, and uses integer coordinates, so should
    not produce any additional degeneracies.

    Before cleaning the polygon, we remove all degenerate inners. This is
    useful to remove inners which have collapsed to points or lines, which can
    interfere with the cleaning process.
    """

    # drop all degenerate inners
    clean_shape = _drop_degenerate_inners(shape)

    pc = pyclipper.Pyclipper()

    try:
        pc.AddPaths(_coords(clean_shape), pyclipper.PT_SUBJECT, True)

        # note: Execute2 returns the polygon tree, not the list of paths
        result = pc.Execute2(pyclipper.CT_UNION, pyclipper.PFT_EVENODD)

    except pyclipper.ClipperException:
        return MultiPolygon([])

    return _polytree_to_shapely(result)
github stephane-caron / pymanoid / pymanoid / geometry.py View on Github external
Vertices of the first polygon in counterclockwise order.
    polygon1 : list of arrays
        Vertices of the second polygon in counterclockwise order.

    Returns
    -------
    intersection : list of arrays
        Vertices of the intersection in counterclockwise order.
    """
    from pyclipper import Pyclipper, PT_CLIP, PT_SUBJECT, CT_INTERSECTION
    from pyclipper import scale_to_clipper, scale_from_clipper
    # could be accelerated by removing the scale_to/from_clipper()
    subj, clip = (polygon1,), polygon2
    pc = Pyclipper()
    pc.AddPath(scale_to_clipper(clip), PT_CLIP)
    pc.AddPaths(scale_to_clipper(subj), PT_SUBJECT)
    solution = pc.Execute(CT_INTERSECTION)
    if not solution:
        return []
    return scale_from_clipper(solution)[0]
github jamiebull1 / geomeppy / geomeppy / geom / clippers.py View on Github external
def _prepare_clipper(self, poly):
        """Prepare 2D polygons for clipping operations.

        :param poly: The clip polygon.
        :returns: A Pyclipper object.

        """
        s1 = pc.scale_to_clipper(self.vertices_list)
        s2 = pc.scale_to_clipper(poly.vertices_list)
        clipper = pc.Pyclipper()
        clipper.AddPath(s1, poly_type=pc.PT_SUBJECT, closed=True)
        clipper.AddPath(s2, poly_type=pc.PT_CLIP, closed=True)
        return clipper
github revarbat / mandoline-py / mandoline / geometry2d.py View on Github external
def diff(subj, clip_paths, subj_closed=True):
    if not subj:
        return []
    if not clip_paths:
        return subj
    pc = pyclipper.Pyclipper()
    if subj:
        subj = pyclipper.scale_to_clipper(subj, SCALING_FACTOR)
        pc.AddPaths(subj, pyclipper.PT_SUBJECT, subj_closed)
    if clip_paths:
        clip_paths = pyclipper.scale_to_clipper(clip_paths, SCALING_FACTOR)
        pc.AddPaths(clip_paths, pyclipper.PT_CLIP, True)
    outpaths = pc.Execute(pyclipper.CT_DIFFERENCE, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD)
    outpaths = pyclipper.scale_from_clipper(outpaths, SCALING_FACTOR)
    return outpaths
github cwig / start_follow_read / utils / PAGE_xml.py View on Github external
scores_i.append(area)

    background_scores = []
    total_areas = []
    for p in polys:
        pc = pyclipper.Pyclipper()
        try:
            pc.AddPath(p, pyclipper.PT_CLIP, True)
        except:
            total_areas.append(np.inf)
            background_scores.append(np.inf)
            # print p
            print "Failed to assign text line, probably not an issue"
            continue
        pc.AddPaths([r['bounding_poly'] for r in regions], pyclipper.PT_SUBJECT, True)
        solution = pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)

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

        simple_path = pyclipper.SimplifyPolygon(p, pyclipper.PFT_NONZERO)
        total_area = 0
        for path in simple_path:
            total_area += pyclipper.Area(path)

        total_areas.append(total_area)
        background_score = total_area - area
        background_scores.append(background_score)

    return np.array(scores), np.array(background_scores), np.array(total_areas)
github deeplycloudy / glmtools / glmtools / grid / clipping.py View on Github external
def clip_poly_pair(pc, p, q):
    """"
    pc: an instance of pyclipper.Pyclipper. 
    p:  the polygon by which to clip other polygon q. 

    pc and p may be held fixed through use of functools.partial so that 
    multiple q may be clipped by p.
    """
    pc.Clear()
    pc.AddPath(q, pyclipper.PT_SUBJECT, True)
    pc.AddPath(p, pyclipper.PT_CLIP, True)
    clip_polys = pc.Execute(clip_type=pyclipper.CT_INTERSECTION)
    return clip_polys