Beispiel #1
0
        private List <Vector2> calculateSubpath(List <Vector2> subControlPoints)
        {
            switch (CurveType)
            {
            case CurveTypes.Linear:
                return(subControlPoints);

            case CurveTypes.PerfectCurve:
                // If we have a different amount than 3 control points, use bezier for perfect curves.
                if (ControlPoints.Count != 3)
                {
                    return(new BezierApproximator(subControlPoints).CreateBezier());
                }
                else
                {
                    Debug.Assert(subControlPoints.Count == 3);

                    // Here we have exactly 3 control points. Attempt to fit a circular arc.
                    List <Vector2> subpath = new CircularArcApproximator(subControlPoints[0], subControlPoints[1], subControlPoints[2]).CreateArc();

                    if (subpath.Count == 0)
                    {
                        // For some reason a circular arc could not be fit to the 3 given points. Fall back
                        // to a numerically stable bezier approximation.
                        subpath = new BezierApproximator(subControlPoints).CreateBezier();
                    }

                    return(subpath);
                }

            default:
                return(new BezierApproximator(subControlPoints).CreateBezier());
            }
        }
Beispiel #2
0
        private List<Vector2> calculateSubpath(List<Vector2> subControlPoints)
        {
            switch (CurveType)
            {
                case CurveTypes.Linear:
                    return subControlPoints;
                case CurveTypes.PerfectCurve:
                    // If we have a different amount than 3 control points, use bezier for perfect curves.
                    if (ControlPoints.Count != 3)
                        return new BezierApproximator(subControlPoints).CreateBezier();
                    else
                    {
                        Debug.Assert(subControlPoints.Count == 3);

                        // Here we have exactly 3 control points. Attempt to fit a circular arc.
                        List<Vector2> subpath = new CircularArcApproximator(subControlPoints[0], subControlPoints[1], subControlPoints[2]).CreateArc();

                        if (subpath.Count == 0)
                            // For some reason a circular arc could not be fit to the 3 given points. Fall back
                            // to a numerically stable bezier approximation.
                            subpath = new BezierApproximator(subControlPoints).CreateBezier();

                        return subpath;
                    }
                default:
                    return new BezierApproximator(subControlPoints).CreateBezier();
            }
        }