What is the issue? Your distance formula looks OK.
Why is your distance function ignoring its parameters?
Actually, on a second look, your formula was wrong.
I have re-written your blocks so that they look and work correctly.
There are two points, P1 and P2, each have x,y values
best to test with points on a right angled triangle, e.g. 3,4 > 5 or 120,160 > 200
What did you see?
I see (x2-x1)^2 instead of (x1-x2)^2, but the squaring operation washes away the negative sign, leaving you with a correct result.
but you are correct, it shouldn't make any difference....