refactored the code to compute the index of a spline segment, to locate it all in one place