Global distance calculation