n_segments function

Vectorised function to calculate number of segments given a max segment length