added check for the last point in the spline

to make sure that the spline segment connects first and last objects