Assets/SplineTool/Scripts/CorgiSpline/Spline.cs
/// <summary>
/// Call this after moving the first or last Points in the internal array, to ensure the spline stays closed.
/// </summary>
Call this after moving the first or last Points in the internal array, to ensure the spline stays closed.
Call this after moving the first or last Points in the internal array to ensure the spline stays closed .
public void EnsureSplineStaysClosed()
        {
            if (!ClosedSpline) return;
            var length = Points.Length;
            switch (Mode)
            {
                case SplineMode.Linear:
                    Points[length - 1] = Points[0];
                    break;
                case SplineMode.Bezier:
                    var previous_handle0 = Points[length - 5];
                    var previous_anchor0 = Points[length - 4];
                    var to_anchor = previous_anchor0.position - previous_handle0.position;
                    var new_handle0 = previous_anchor0;
                    new_handle0.position += to_anchor;
                    var next_anchor = Points[0];
                    var next_handle = Points[1];
                    var to_next_anchor = next_anchor.position - next_handle.position;
                    var new_handle1 = next_anchor;
                    new_handle1.position += to_next_anchor;
                    Points[length - 3] = new_handle0;
                    Points[length - 2] = new_handle1;
                    Points[length - 1] = next_anchor;
                    break;
                case SplineMode.BSpline:
                    Points[length - 1] = Points[0];
                    break;
                default:
                    break;
            }
        }
public void EnsureSplineStaysClosed ( ) { if ( ! ClosedSpline ) return ; var length = Points . Length ; switch ( Mode ) { case SplineMode . Linear : Points [ length - 1 ] = Points [ 0 ] ; break ; case SplineMode . Bezier : var previous_handle0 = Points [ length - 5 ] ; var previous_anchor0 = Points [ length - 4 ] ; var to_anchor = previous_anchor0 . position - previous_handle0 . position ; var new_handle0 = previous_anchor0 ; new_handle0 . position += to_anchor ; var next_anchor = Points [ 0 ] ; var next_handle = Points [ 1 ] ; var to_next_anchor = next_anchor . position - next_handle . position ; var new_handle1 = next_anchor ; new_handle1 . position += to_next_anchor ; Points [ length - 3 ] = new_handle0 ; Points [ length - 2 ] = new_handle1 ; Points [ length - 1 ] = next_anchor ; break ; case SplineMode . BSpline : Points [ length - 1 ] = Points [ 0 ] ; break ; default : break ; } }
Call this after moving the first or last Points in the internal array, to ensure the spline stays closed.
Call this after moving the first or last Points in the internal array to ensure the spline stays closed .
// not implemented 