Tidier implementation of EuclideanDistance