Add distance function and default implementation.