better end plot = fix fallback to RS

This commit is contained in:
Johann Dreo 2018-12-16 20:26:19 +01:00
commit 0d40f5c246
5 changed files with 72 additions and 46 deletions

View file

@ -25,3 +25,45 @@ def coverage(domain, sensors, sensor_range):
return domain
def line(x0, y0, x1, y1):
"""Compute the set of pixels (integer coordinates) of the line
between the given line (x0,y0) -> (x1,y1).
Use the Bresenham's algorithm.
This make a generator that yield the start and the end points.
"""
dx = x1 - x0
dy = y1 - y0
if dx > 0:
xs = 1
else:
xs = -1
if dy > 0:
ys = 1
else:
xs = -1
dx = abs(dx)
dy = abs(dy)
if dx > dy:
ax, xy, yx, ay = xs, 0, 0, ys
else:
dx, dy = dy, dx
ax, xy, yx, ay = 0, ys, xs, 0
D = 2 * dy - dx
y = 0
for x in range(dx + 1):
yield x0 + x*ax + y*yx , y0 + x*xy + y*ay
if D >= 0:
y += 1
D -= 2 * dx
D += 2 * dy
#TODO maximin trajectories