Example #1
0
        /// <summary>
        ///     Get the segment between each adjacent control points of current spline.
        /// </summary>
        /// <param name="self">The spline instance.</param>
        /// <param name="index">
        ///     Index of the segment. The value can be -1 which means the segment formed by the extra head control point
        ///     and the first control point of the spline; and <see cref="ISpline.PointCount" />-1 which means the segment
        ///     formed by the last control point of the spline and extra tail control point.
        /// </param>
        public static Segment3 GetSegment(this ISpline self, int index)
        {
            var pc = self.PointCount;

            if (index < -1 || index > pc - 1)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            if (index == -1)
            {
                return(new Segment3(self.GetExtraHeadPoint(), self[0]));
            }
            if (index == pc - 1)
            {
                return(new Segment3(self[pc - 1], self.GetExtraTailPoint()));
            }
            return(new Segment3(self[index], self[index + 1]));
        }