Use libdistance in k-centers and regularspatial

Substantially simplifies the code.