weight distances by gradient magnitude