Distance function structure implemented