\$\begingroup\$

OCaml, 145 164

let(%)(a,b)(c,d)=(c-a)*(c-a)+(d-b)*(d-b) let t a b c d=a%b+a%c=b%c&&d%c+d%b=b%c&&a%b=a%c&&d%c=d%b let q(a,b,c,d)=t a b c d||t a c d b||t a b d c

Run like this:

q ((0,0),(2,1),(3,-1),(1,-2))

Let's deobfuscate and explain a bit.

First we define a norm:

let norm (ax,ay) (bx,by) = (bx-ax)*(bx-ax)+(by-ay)*(by-ay)

You'll notice that there is no call to sqrt, it's not needed here.

let is_square_with_fixed_layout a b c d = (norm a b) + (norm a c) = norm b c && (norm d c) + (norm d b) = norm b c && norm a b = norm a c && norm d c = norm d b

Here a, b, c and d are points. We assume that these points are layed out like this:

a - b | / | c - d

If we have a square then all these conditions must hold:

a b c is a right triangle

b c d is a right triangle

the smaller sides of each right triangle have the same norms

Observe that the following always holds:

is_square_with_fixed_layout r s t u = is_square_with_fixed_layout r t s u

We will use that to simplify our test function below.

Since our input is not ordered, we also have to check all permutations. Without loss of generality we can avoid permuting the first point:

let is_square (a,b,c,d) = is_square_with_fixed_layout a b c d || is_square_with_fixed_layout a c b d || is_square_with_fixed_layout a c d b || is_square_with_fixed_layout a b d c || is_square_with_fixed_layout a d b c || is_square_with_fixed_layout a d c b

After simplification:

let is_square (a,b,c,d) = is_square_with_fixed_layout a b c d || is_square_with_fixed_layout a c d b || is_square_with_fixed_layout a b d c

Edit: followed M.Giovannini's advice.