Do not sqr it.
In 2D the distances are small so they don't exceed the float maximum when squared, so you can compare d^2 to it.
the other optimation is NOT to use ^2
Its slower than x*x, the ^x does not make sense with x < 3 performance wise.
->
xdif = x1 - x2
ydif = y1 - y2
d2 = ( xdif*xdif + ydif*ydif)
if d2 < maxDistance * maxDistance then ...
In 2D the distances are small so they don't exceed the float maximum when squared, so you can compare d^2 to it.
the other optimation is NOT to use ^2
Its slower than x*x, the ^x does not make sense with x < 3 performance wise.
->
xdif = x1 - x2
ydif = y1 - y2
d2 = ( xdif*xdif + ydif*ydif)
if d2 < maxDistance * maxDistance then ...