How to compute the top of climb/top of descent of a trajectory?