def offset_default(polygon_stack, val): path = polygon_stack.polygons po = pyclipper.PyclipperOffset() po.AddPaths(path, pyclipper.JT_SQUARE, pyclipper.ET_CLOSEDPOLYGON) offseted = po.Execute(scale_value_to_clipper(val)) return offseted
def single_polygon_offset(single_line, val): path = single_line # path = pyclipper.ReversePaths(polygon_stack.polygons) # for polygon_index in range(len(path)): # if not pyclipper.Orientation(path[polygon_index]): # path[polygon_index] = pyclipper.ReversePath(path[polygon_index]) po = pyclipper.PyclipperOffset() po.AddPath(path, pyclipper.JT_SQUARE, pyclipper.ET_CLOSEDPOLYGON) offseted = po.Execute(scale_value_to_clipper(float(val))) return offseted
def offset(polygon_stack, val): path = polygon_stack.polygons # path = pyclipper.ReversePaths(polygon_stack.polygons) # for polygon_index in range(len(path)): # if not pyclipper.Orientation(path[polygon_index]): # path[polygon_index] = pyclipper.ReversePath(path[polygon_index]) po = pyclipper.PyclipperOffset() po.AddPaths(path, pyclipper.JT_MITER, pyclipper.ET_CLOSEDPOLYGON) offseted = po.Execute(scale_value_to_clipper(val)) return offseted
def lines_offset(lines, offset_value, does_visualize=False): pc = pyclipper.PyclipperOffset() pc.AddPaths(lines, pyclipper.JT_SQUARE, pyclipper.ET_OPENSQUARE) solution = pc.Execute(scale_value_to_clipper(offset_value)) # solution = pyclipper.scale_from_clipper(solution) if does_visualize: import matplotlib.pyplot as plt for line in lines: plt.plot([i[0] for i in line], [i[1] for i in line]) for line in solution: plt.plot([i[0] for i in line], [i[1] for i in line]) plt.plot([line[-1][0], line[0][0]], [line[-1][1], line[0][1]]) plt.show() return solution
def detect_islands(self): po = pyclipper.PyclipperOffset() po.MiterLimit = 2 base = 1#pow(10, 15) empty_poly = PolygonStack([[[base, base], [base + 1, base], [base + 1, base + 1], [base, base + 1]]]) polys = pyclipper.PolyTreeToPaths( diff_layers_as_polytree(self.layers[self.index], empty_poly.polygons, True)) po.AddPaths(polys, pyclipper.JT_MITER, pyclipper.ET_CLOSEDPOLYGON) islandStack = IslandStack( po.Execute2(scale_value_to_clipper(-config.LINE_WIDTH/2))) return islandStack.get_islands()