Distance function design and Lyapunov techniques for the stability of hybrid trajectories