Example #1
0
        private void CalculatePath()
        {
            calculatedPath.Clear();

            // Sliders may consist of various subpaths separated by two consecutive vertices
            // with the same position. The following loop parses these subpaths and computes
            // their shape independently, consecutively appending them to calculatedPath.

            int start = 0;
            int end   = 0;

            for (int i = 0; i < ControlPoints.Length(); ++i)
            {
                end++;

                if (i == ControlPoints.Length() - 1 || ControlPoints[i] == ControlPoints[i + 1] && i != ControlPoints.Length() - 2)
                {
                    List <Vector2> cpSpan = ControlPoints.GetRange(start, end - start);

                    foreach (Vector2 t in CalculateSubpath(cpSpan))
                    {
                        if (calculatedPath.Count == 0 || calculatedPath.Last() != t)
                        {
                            calculatedPath.Add(t);
                        }
                    }

                    start = end;
                }
            }
        }
Example #2
0
        private List <Vector2> CalculateSubpath(List <Vector2> subControlPoints)
        {
            switch (Type)
            {
            case PathType.Linear:
                return(PathApproximator.ApproximateLinear(subControlPoints));

            case PathType.PerfectCurve:
                //we can only use CircularArc iff we have exactly three control points and no dissection.
                if (ControlPoints.Length() != 3 || subControlPoints.Length() != 3)
                {
                    break;
                }

                // Here we have exactly 3 control points. Attempt to fit a circular arc.
                List <Vector2> subpath = PathApproximator.ApproximateCircularArc(subControlPoints);

                // If for some reason a circular arc could not be fit to the 3 given points, fall back to a numerically stable bezier approximation.
                if (subpath.Count == 0)
                {
                    break;
                }

                return(subpath);

            case PathType.Catmull:
                return(PathApproximator.ApproximateCatmull(subControlPoints));
            }

            return(PathApproximator.ApproximateBezier(subControlPoints));
        }