Fixes the signess of distance calculations and compares to
solve the last buildwarning about (X + c) < X and signdness.