예제 #1
0
        private IEnumerable<PointF> ConvertToPoints(SvgPathSegment arg)
        {
            if (arg is SvgMoveToSegment)
            {
                // Ignore this, as Svg library converts everything to absolute coords
            }
            else if (arg is SvgCubicCurveSegment)
            {
                var curve = arg as SvgCubicCurveSegment;

                for (int i = 0; i < SegmentCount; i++)
                {
                    // Cubic bezier yo
                    var t = i / (double)(SegmentCount - 1);
                    var c1 = Math.Pow(1 - t, 3);
                    var c2 = 3 * Math.Pow(1 - t, 2) * t;
                    var c3 = 3 * (1 - t) * Math.Pow(t, 2);
                    var c4 = Math.Pow(t, 3);

                    yield return new PointF((float)(
                        c1 * curve.Start.X +
                        c2 * curve.FirstControlPoint.X +
                        c3 * curve.SecondControlPoint.X +
                        c4 * curve.End.X), (float)(
                        c1 * curve.Start.Y +
                        c2 * curve.FirstControlPoint.Y +
                        c3 * curve.SecondControlPoint.Y +
                        c4 * curve.End.Y)
                    );
                }
            }
            else
                throw new NotImplementedException();
        }