Documentation for distance function