Partitioned distance function
