Calculate distance.