Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -1 for change origin to 0,0
xc, yc = xc - origin, yc - origin
angle = shape.coord_list[-1]
maj_list, min_list = shape.coord_list[2:-1:2], shape.coord_list[3:-1:2]
if len(maj_list) > 1:
w1, h1 = max(maj_list), max(min_list)
w2, h2 = min(maj_list), min(min_list)
f1 = region_filter.Ellipse(xc, yc, w1, h1) \
& ~region_filter.Ellipse(xc, yc, w2, h2)
f = region_filter.Rotated(f1, angle, xc, yc)
else:
w, h = maj_list[0], min_list[0]
f = region_filter.Rotated(region_filter.Ellipse(xc, yc, w, h),
angle, xc, yc)
elif shape.name == "annulus":
xc, yc = shape.coord_list[:2]
# -1 for change origin to 0,0
xc, yc = xc - origin, yc - origin
r_list = shape.coord_list[2:]
r1 = max(r_list)
r2 = min(r_list)
f = region_filter.Circle(xc, yc, r1) & ~region_filter.Circle(xc, yc, r2)
elif shape.name == "circle":
xc, yc, r = shape.coord_list
# -1 for change origin to 0,0
elif shape.name == "ellipse":
xc, yc = shape.coord_list[:2]
# -1 for change origin to 0,0
xc, yc = xc - origin, yc - origin
angle = shape.coord_list[-1]
maj_list, min_list = shape.coord_list[2:-1:2], shape.coord_list[3:-1:2]
if len(maj_list) > 1:
w1, h1 = max(maj_list), max(min_list)
w2, h2 = min(maj_list), min(min_list)
f1 = region_filter.Ellipse(xc, yc, w1, h1) \
& ~region_filter.Ellipse(xc, yc, w2, h2)
f = region_filter.Rotated(f1, angle, xc, yc)
else:
w, h = maj_list[0], min_list[0]
f = region_filter.Rotated(region_filter.Ellipse(xc, yc, w, h),
angle, xc, yc)
elif shape.name == "annulus":
xc, yc = shape.coord_list[:2]
# -1 for change origin to 0,0
xc, yc = xc - origin, yc - origin
r_list = shape.coord_list[2:]
r1 = max(r_list)
r2 = min(r_list)
f = region_filter.Circle(xc, yc, r1) & ~region_filter.Circle(xc, yc, r2)
# -1 for change origin to 0,0
xc, yc = xc - origin, yc - origin
f1 = region_filter.Ellipse(xc, yc, r21, r22) & ~region_filter.Ellipse(xc, yc, r11, r12)
f2 = f1 & region_filter.AngleRange(xc, yc, a1, a2)
f = region_filter.Rotated(f2, angle, xc, yc)
# f = f2 & region_filter.AngleRange(xc, yc, a1, a2)
elif shape.name == "bpanda":
xc, yc, a1, a2, an, r11, r12, r21, r22, rn, angle = shape.coord_list
# -1 for change origin to 0,0
xc, yc = xc - origin, yc - origin
f1 = region_filter.Box(xc, yc, r21, r22) & ~region_filter.Box(xc, yc, r11, r12)
f2 = f1 & region_filter.AngleRange(xc, yc, a1, a2)
f = region_filter.Rotated(f2, angle, xc, yc)
# f = f2 & region_filter.AngleRange(xc, yc, a1, a2)
else:
warnings.warn("'as_region_filter' does not know how to convert {0}"
" to a region filter.".format(shape.name))
continue
if shape.exclude:
filter_list = [region_filter.RegionOrList(*filter_list) & ~f]
else:
filter_list.append(f)
return region_filter.RegionOrList(*filter_list)