add distance scalar function