//--------------------------------------------------------------------------------------------------

        void _ImportClosePathSegment(SvgPathSegClosePath svgSegment, ref int startPoint, ref int firstPoint)
        {
            if (_Points[startPoint].IsEqual(_Points[firstPoint], Double.Epsilon))
            {
                // Replace last point
                var segment = _Segments.LastOrDefault();
                if (segment != null)
                {
                    for (int i = 0; i < segment.Points.Length; i++)
                    {
                        if (segment.Points[i] == startPoint)
                        {
                            segment.Points[i] = firstPoint;
                        }
                    }
                    _Points.Remove(startPoint);
                }
            }
            else
            {
                _Segments.Add(new SketchSegmentLine(startPoint, firstPoint));
            }
            startPoint = -1;
            firstPoint = -1;
        }
        public static SvgPathSegClosePath Create(SvgPathSegment firstSegment, SvgPathSegment lastSegment)
        {
            var seg = new SvgPathSegClosePath {
                Start = lastSegment?.Start ?? Pnt2d.Origin,
                End   = firstSegment?.End ?? Pnt2d.Origin
            };

            return(seg);
        }
        internal static IEnumerable <SvgPathSegment> Create(string pathString, SvgConverter conv)
        {
            SvgPathSegment lastSegment  = null;
            SvgPathSegment firstSegment = null;
            int            next         = 0;

            while (next < pathString.Length)
            {
                int start = next;
                next = pathString.IndexOfAny(_PathCommands, start + 1);
                if (next == -1)
                {
                    next = pathString.Length;
                }

                IEnumerable <SvgPathSegment> newSegments = null;
                var commandString = pathString.Substring(start, next - start);
                switch (char.ToLower(commandString[0]))
                {
                case 'm':
                    newSegments = SvgPathSegMoveto.Create(lastSegment, commandString, conv);
                    break;

                case 'l':
                case 'h':
                case 'v':
                    newSegments = SvgPathSegLineto.Create(lastSegment, commandString, conv);
                    break;

                case 'c':
                case 's':
                    newSegments = SvgPathSegCurvetoCubic.Create(lastSegment, commandString, conv);
                    break;

                case 'q':
                case 't':
                    newSegments = SvgPathSegCurvetoQuadratic.Create(lastSegment, commandString, conv);
                    break;

                case 'a':
                    newSegments = SvgPathSegArc.Create(lastSegment, commandString, conv);
                    break;

                case 'z':
                    lastSegment = SvgPathSegClosePath.Create(firstSegment, lastSegment);
                    yield return(lastSegment);

                    firstSegment = null;
                    continue;
                }

                if (newSegments == null)
                {
                    continue;
                }

                foreach (var segment in newSegments)
                {
                    if (firstSegment == null)
                    {
                        firstSegment = segment;
                    }
                    lastSegment = segment;
                    yield return(segment);
                }
            }
        }