Our algorithm essentially does:
for each step
for each object of the scene
d = min(d, distance(object))
A possible optimisation is to instead swap the loops, allowing to evaluate first the objects more likely to be close, and stop evaluating expensive background objects as soon as possible.