1 | using System;
|
---|
2 |
|
---|
3 | using SharpVectors.Polynomials;
|
---|
4 |
|
---|
5 | namespace SharpVectors.Dom.Svg
|
---|
6 | {
|
---|
7 | public abstract class SvgPathSegCurvetoCubic : SvgPathSegCurveto
|
---|
8 | {
|
---|
9 | #region constructors
|
---|
10 | protected SvgPathSegCurvetoCubic(SvgPathSegType type) : base(type)
|
---|
11 | {
|
---|
12 | }
|
---|
13 | #endregion
|
---|
14 |
|
---|
15 | #region abstract properties
|
---|
16 | public abstract override SvgPointF AbsXY { get; }
|
---|
17 | public abstract override SvgPointF CubicX1Y1 { get; }
|
---|
18 | public abstract override SvgPointF CubicX2Y2 { get; }
|
---|
19 | #endregion
|
---|
20 |
|
---|
21 | #region protected methods
|
---|
22 | protected override SqrtPolynomial getArcLengthPolynomial()
|
---|
23 | {
|
---|
24 | double c3x, c3y, c2x, c2y, c1x, c1y;
|
---|
25 | SvgPointF p1 = PreviousSeg.AbsXY;
|
---|
26 | SvgPointF p2 = CubicX1Y1;
|
---|
27 | SvgPointF p3 = CubicX2Y2;
|
---|
28 | SvgPointF p4 = AbsXY;
|
---|
29 |
|
---|
30 | // convert curve into polynomial
|
---|
31 | c3x = -1.0*p1.X + 3.0*p2.X - 3.0*p3.X + p4.X;
|
---|
32 | c3y = -1.0*p1.Y + 3.0*p2.Y - 3.0*p3.Y + p4.Y;
|
---|
33 |
|
---|
34 | c2x = 3.0*p1.X - 6.0*p2.X + 3.0*p3.X;
|
---|
35 | c2y = 3.0*p1.Y - 6.0*p2.Y + 3.0*p3.Y;
|
---|
36 |
|
---|
37 | c1x = -3.0*p1.X + 3.0*p2.X;
|
---|
38 | c1y = -3.0*p1.Y + 3.0*p2.Y;
|
---|
39 |
|
---|
40 | // build polynomial
|
---|
41 | // dx = dx/dt
|
---|
42 | // dy = dy/dt
|
---|
43 | // sqrt poly = sqrt( (dx*dx) + (dy*dy) )
|
---|
44 | return new SqrtPolynomial(
|
---|
45 | c1x*c1x + c1y*c1y,
|
---|
46 | 4.0*(c1x*c2x + c1y*c2y),
|
---|
47 | 4.0*(c2x*c2x + c2y*c2y) + 6.0*(c1x*c3x + c1y*c3y),
|
---|
48 | 12.0*(c2x*c3x + c2y*c3y),
|
---|
49 | 9.0*(c3x*c3x + c3y*c3y)
|
---|
50 | );
|
---|
51 | }
|
---|
52 | #endregion
|
---|
53 | }
|
---|
54 | }
|
---|