distance (x, y) (a, b) = delX + delY where
  delX
    | a == 0 = 0
    | a > 0  = (a - x)^2
    | a < 0  = (x - 1 - a)^2
  delY
    | b == 0 = 0
    | b > 0  = (b - y)^2
    | b < 0  = (y - 1 - b)^2
distance (x, y) (a, b) = delX + delY where
  delX
    | a == 0 = 0
    | a > 0  = (a - x)^2
    | a < 0  = (x - 1 - a)^2
  delY
    | b == 0 = 0
    | b > 0  = (b - y)^2
    | b < 0  = (y - 1 - b)^2
distance (x, y) (a, b) = delX + delY where
  delX
    | a == 0 = 0
    | a > 0  = (a - x)^2
    | a < 0  = (x - 1 - a)^2
  delY
    | b == 0 = 0
    | b > 0  = (b - y)^2
    | b < 0  = (y - 1 - b)^2