calculates the distance between two positions in 2d space