예제 #1
0
    def __check_direct_edge(self, point0, point1):

        pc = pyclipper.Pyclipper()
        pc.AddPath([point0, point1], pyclipper.PT_SUBJECT, False)
        pc.AddPath(self.bound, pyclipper.PT_CLIP, True)
        result = pyclipper.OpenPathsFromPolyTree(
            pc.Execute2(pyclipper.CT_DIFFERENCE, pyclipper.PFT_EVENODD,
                        pyclipper.PFT_EVENODD))
        if len(result) != 0:
            return False
        for poly in self.holes:
            pc.Clear()
            pc.AddPath([point0, point1], pyclipper.PT_SUBJECT, False)
            pc.AddPath(poly, pyclipper.PT_CLIP, True)
            result = pyclipper.OpenPathsFromPolyTree(
                pc.Execute2(pyclipper.CT_DIFFERENCE, pyclipper.PFT_EVENODD,
                            pyclipper.PFT_EVENODD))

            if len(result) != 1 or \
                result[0][0][0] != point0[0] or\
                result[0][0][1] != point0[1] or\
                result[0][1][0] != point1[0] or\
                result[0][1][1] != point1[1]:

                return False

        return True
예제 #2
0
 def test_execute2(self):
     pc = pyclipper.PyclipperOffset()
     self.add_path(pc, PATH_CLIP_1)
     solution = pc.Execute2(2.0)
     self.assertIsInstance(solution, pyclipper.PyPolyNode)
     self.assertEqual(len(pyclipper.OpenPathsFromPolyTree(solution)), 0)
     self.assertEqual(len(pyclipper.ClosedPathsFromPolyTree(solution)), 1)
예제 #3
0
def clip_lines(lines, contours):
    """ Clip lines with contours.
    Return collection of open polygons ordered by y axis
    """
    # TODO simplify lines
    c = pc.Pyclipper()
    c.AddPaths(contours, pc.PT_CLIP)
    c.AddPaths(lines, pc.PT_SUBJECT, False)

    tree = c.Execute2(pc.CT_INTERSECTION)

    paths = pc.OpenPathsFromPolyTree(tree)

    return _to_ndarrays(paths)
예제 #4
0
 def test_open_paths_from_polytree(self):
     paths = pyclipper.OpenPathsFromPolyTree(self.tree)
     self.check_paths(paths, 2)