Make algorithm work with float input?
Closed this issue · 1 comments
waldeland commented
Hi! Great work!
Maybe it is possible to make algorithm work with float input by changing line 32 from:
for x in range(dx + 1):
to
for x in range(int(dx + 1)):
in bresenham.py.
encukou commented
Well, Bresenham's algorithm is famous for only dealing with ints, so you should only call it with ints :)
It would be possible to generalize to floats or fractional pixels, but that should have more sophisticated behavior – like Wu's algorithm, for example.
I'd expect that a line starting at x=1.98 should look almost like a line starting at x=2, rather than at x=1.
If you need simple truncation, cal int()
or round()
before calling bresenham()
.