Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def union(paths1, paths2):
if not paths1:
return paths2
if not paths2:
return paths1
pc = pyclipper.Pyclipper()
if paths1:
if paths1[0][0] in (int, float):
raise pyclipper.ClipperException()
paths1 = pyclipper.scale_to_clipper(paths1, SCALING_FACTOR)
pc.AddPaths(paths1, pyclipper.PT_SUBJECT, True)
if paths2:
if paths2[0][0] in (int, float):
raise pyclipper.ClipperException()
paths2 = pyclipper.scale_to_clipper(paths2, SCALING_FACTOR)
pc.AddPaths(paths2, pyclipper.PT_CLIP, True)
try:
outpaths = pc.Execute(pyclipper.CT_UNION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD)
except:
print("paths1={}".format(paths1))
print("paths2={}".format(paths2))
outpaths = pyclipper.scale_from_clipper(outpaths, SCALING_FACTOR)
return outpaths
def union(paths1, paths2):
if not paths1:
return paths2
if not paths2:
return paths1
pc = pyclipper.Pyclipper()
if paths1:
if paths1[0][0] in (int, float):
raise pyclipper.ClipperException()
paths1 = pyclipper.scale_to_clipper(paths1, SCALING_FACTOR)
pc.AddPaths(paths1, pyclipper.PT_SUBJECT, True)
if paths2:
if paths2[0][0] in (int, float):
raise pyclipper.ClipperException()
paths2 = pyclipper.scale_to_clipper(paths2, SCALING_FACTOR)
pc.AddPaths(paths2, pyclipper.PT_CLIP, True)
try:
outpaths = pc.Execute(pyclipper.CT_UNION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD)
except:
print("paths1={}".format(paths1))
print("paths2={}".format(paths2))
outpaths = pyclipper.scale_from_clipper(outpaths, SCALING_FACTOR)
return outpaths
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
return []
try:
solution = pc.Execute(_operationMap[operation],
_fillTypeMap[subjectFillType],
_fillTypeMap[clipFillType])
except pyclipper.ClipperException as exc:
raise ExecutionError(exc)
return [[tuple(p) for p in path] for path in solution]
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)