Пример #1
0
        /// <summary>
        /// Creates a Loop (Closed Spline) path through a given set of points.
        /// </summary>
        /// <param name="AppendTo">Spline should be appended to this path. If null, a new path will be created.</param>
        /// <param name="Points">Points between which the loop will be created.</param>
        /// <returns>Loop path.</returns>
        public static SKPath CreateLoop(SKPath AppendTo, params SKPoint[] Points)
        {
            int i, c = Points.Length;

            if (c == 0)
            {
                throw new ArgumentException("No points provided.", nameof(Points));
            }

            if (AppendTo is null)
            {
                AppendTo = new SKPath();
                AppendTo.MoveTo(Points[0]);
            }
            else
            {
                SKPoint P = AppendTo.LastPoint;

                if (P.X != Points[0].X || P.Y != Points[0].Y)
                {
                    AppendTo.LineTo(Points[0]);
                }
            }

            if (c == 1)
            {
                return(AppendTo);
            }

            float[] V = new float[c];

            for (i = 0; i < c; i++)
            {
                V[i] = Points[i].X;
            }

            GetCubicBezierCoefficients(V, out float[] Ax, out float[] Bx);

            for (i = 0; i < c; i++)
            {
                V[i] = Points[i].Y;
            }

            GetCubicBezierCoefficients(V, out float[] Ay, out float[] By);

            for (i = 0; i < c - 1; i++)
            {
                AppendTo.CubicTo(Ax[i], Ay[i], Bx[i], By[i], Points[i + 1].X, Points[i + 1].Y);
            }

            AppendTo.CubicTo(Ax[i], Ay[i], Bx[i], By[i], Points[0].X, Points[0].Y);
            AppendTo.Close();

            return(AppendTo);
        }
Пример #2
0
        /// <summary>
        /// Creates a Spline path through a given set of points.
        /// </summary>
        /// <param name="AppendTo">Spline should be appended to this path. If null, a new path will be created.</param>
        /// <param name="Points">Points between which the spline will be created.</param>
        /// <returns>Spline path.</returns>
        public static SKPath CreateSpline(SKPath AppendTo, params SKPoint[] Points)
        {
            int i, c = Points.Length;

            if (c == 0)
            {
                throw new ArgumentException("No points provided.", nameof(Points));
            }

            if (AppendTo is null)
            {
                AppendTo = new SKPath();
                AppendTo.MoveTo(Points[0]);
            }
            else
            {
                AppendTo.LineTo(Points[0]);
            }

            if (c == 1)
            {
                return(AppendTo);
            }

            if (c == 2)
            {
                AppendTo.LineTo(Points[1]);
                return(AppendTo);
            }

            double[] V = new double[c];

            for (i = 0; i < c; i++)
            {
                V[i] = Points[i].X;
            }

            GetCubicBezierCoefficients(V, out double[] Ax, out double[] Bx);

            for (i = 0; i < c; i++)
            {
                V[i] = Points[i].Y;
            }

            GetCubicBezierCoefficients(V, out double[] Ay, out double[] By);

            for (i = 0; i < c - 1; i++)
            {
                AppendTo.CubicTo((float)Ax[i], (float)Ay[i], (float)Bx[i], (float)By[i],
                                 Points[i + 1].X, Points[i + 1].Y);
            }

            return(AppendTo);
        }