For points \((x_1,y_1)\) and \((x_2,y_2)\), the horizontal and vertical differences are the legs of a right triangle. Use the same order of subtraction on both axes.
The distance is \(d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\). The square root gives a nonnegative length.
A horizontal segment has zero change in y. Its distance is the absolute difference in x. A vertical segment uses the absolute difference in y.