This package currently hosts a single function: Raycast2D.touchedTiles
.
tileSize = 50
from = (25, 75) -- center of tile (0,1)
to = (275, 175) -- center of tile (5,3)
touchedTiles tileSize from to
--> Set.fromList [(0,1),(1,1),(1,2),(2,2),(3,2),(4,2),(4,3),(5,3)]
It is an Elm implementation of the DDA (Digital Differential Analysis) algorithm popularized by OneLoneCoder (Javidx9).
The main idea is that instead of walking the ray by small steps and checking which tile we're in, we instead go all the way to the nearest cell boundary. This uses less CPU and doesn't suffer from inaccuracy (overshooting the finishline, as it were).
You can play with a modified version of this code (such that we can visualize the line segments and seen tiles) in this Ellie.