@johngroves
WHERE p1.x <> p2.x or p1.y <> p2.y
contains the same logic as
WHERE NOT (a.x = b.x AND a.y = b.y)

In both cases, pairs of points are filtered such that only one of their coordinates needs to be different from the other. In this way, the self join won't pair points with themselves.