Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def difference(self, poly):
# type: (Polygon) -> List[Polygon]
"""Difference from another polygon.
:param poly: The clip polygon.
:returns: A list of Polygons representing the difference.
"""
clipper = self._prepare_clipper(poly)
if not clipper:
return []
differences = clipper.Execute(
pc.CT_DIFFERENCE, pc.PFT_NONZERO, pc.PFT_NONZERO)
return self._process(differences)
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
"""
General Suggestions:
- Contours should only be sent here if they actually overlap.
This can be checked easily using contour bounds.
- Only perform operations on closed contours.
- contours must have an on curve point
- 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):
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)
# Scale back
ARV = pyclipper.scale_from_clipper(ARV)
# Check if ARV or FRV is empty
if len(ARV) == 0:
# No aircraft in the vicinity
# Map them into the format ARV wants. Outercircle CCW, innercircle CW
ARV_loc[i] = []
FRV_loc[i] = circle_lst
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)
# Scale back