Bresenham's line algorithm rasterizes a straight line by selecting integer-coordinate pixels that approximate its slope. It is useful when a digital canvas stores pixels and coordinates as integers, especially for oblique lines. section 5.14
A Clojure implementation organizes the work into these stages:
- Use unchecked integer operators when integer indexing, reduced boxing, and performance are important; a long-based variant is also shown. section 5.14
Drawing a line
Calling (to-points 2 3 10 10) and painting those points on a 12-by-12 canvas produces a stepped diagonal of 1s from approximately [2,3] to [10,10]. Repeated neighboring pixels make the rasterized line look straight at larger scale.
