Corrected checking of absolute value for the differences of x and y coordinates.