changed to distance squared comparison operations where feasible