def disttoedge(self, x, y, d):
rd = numpy.deg2rad(d)
dx, dy = numpy.cos(rd), numpy.sin(rd)
maxx = self.width()
maxy = self.height()
if dx == 0:
lefthit, righthit = sys.maxsize, sys.maxsize
tophit, bothit = (maxy - y) / dy, (-y) / dy
elif dy == 0:
lefthit, righthit = (-x) / dx, (maxx - x) / dx
tophit, bothit = sys.maxsize, sys.maxsize
else:
lefthit, righthit = (-x) / dx, (maxx - x) / dx
tophit, bothit = (maxy - y) / dy, (-y) / dy
# Return smallest positive
dists = list(filter(lambda s: s > 0, [lefthit, righthit, tophit, bothit]))
if len(dists) == 0:
return 0
else:
return min(dists)
评论列表
文章目录