Generalized distance