2using System.Threading.Tasks;
24 : base(Document, Parent)
35 this.spline?.Dispose();
50 set => this.head = value;
59 set => this.tail = value;
66 public override Task
FromXml(XmlElement Input)
71 return base.FromXml(Input);
80 base.ExportAttributes(Output);
94 return new Spline(Document, Parent);
118 private static SKPoint[] ToPoints(
Vertex[] Points)
120 int c = Points.Length;
122 SKPoint[] P =
new SKPoint[c];
124 for (i = 0; i < c; i++)
125 P[i] =
new SKPoint(Points[i].XCoordinate, Points[i].YCoordinate);
146 public static SKPath
CreateSpline(SKPath AppendTo, params SKPoint[] Points)
148 return CreateSpline(AppendTo, out _, out _, out _, out _, Points);
151 private static SKPath CreateSpline(SKPath AppendTo,
152 out
float[] Ax, out
float[] Ay, out
float[] Bx, out
float[] By,
153 params SKPoint[] Points)
155 int i, c = Points.Length;
157 throw new ArgumentException(
"No points provided.", nameof(Points));
159 if (AppendTo is
null)
161 AppendTo =
new SKPath();
162 AppendTo.MoveTo(Points[0]);
166 SKPoint P = AppendTo.LastPoint;
168 if (P.X != Points[0].X || P.Y != Points[0].Y)
169 AppendTo.LineTo(Points[0]);
174 Ax = Ay = Bx = By =
null;
180 AppendTo.LineTo(Points[1]);
181 Ax = Ay = Bx = By =
null;
185 float[] V =
new float[c];
187 for (i = 0; i < c; i++)
190 GetCubicBezierCoefficients(V, out Ax, out Bx);
192 for (i = 0; i < c; i++)
195 GetCubicBezierCoefficients(V, out Ay, out By);
197 for (i = 0; i < c - 1; i++)
198 AppendTo.CubicTo(Ax[i], Ay[i], Bx[i], By[i], Points[i + 1].X, Points[i + 1].Y);
252 int N = V.Length - 1;
258 float r32, r33, r34, r35;
259 float[,] Rows =
new float[N2, 3];
378 Rows[i, 2] -= a * Rows[i + 1, 2];
389 Rows[i, 2] -= a * Rows[i + 1, 2];
402 base.CopyContents(Destination);
404 if (Destination is
Spline Dest)
418 await base.DoMeasureDimensions(State);
425 this.headElement =
Shape;
430 this.Document.TryGetElement(RefId.
Result, out Element) &&
431 Element is
Shape Shape2)
433 this.tailElement = Shape2;
436 this.spline?.Dispose();
440 private Shape headElement;
441 private Shape tailElement;
442 private SKPath spline;
456 SKPaint Pen = await this.
GetPen(State);
460 State.
Canvas.DrawPath(this.spline, Pen);
462 if (!(this.tailElement is
null) || !(this.headElement is
null))
466 this.tailElement?.
DrawTail(State,
this, Pen, Fill);
467 this.headElement?.
DrawHead(State,
this, Pen, Fill);
471 await base.Draw(State);
474 private void CheckSpline()
476 if (this.spline is
null)
478 this.spline = CreateSpline(
null, out this.ax, out this.ay,
479 out this.bx, out this.by, ToPoints(this.points));
490 public bool TryGetStart(out
float X, out
float Y, out
float Direction)
521 X = Y = Direction = 0;
532 public bool TryGetEnd(out
float X, out
float Y, out
float Direction)
554 float dx = 3 * (P2.XCoordinate - this.bx[c - 2]);
555 float dy = 3 * (P2.YCoordinate - this.by[c - 2]);
563 X = Y = Direction = 0;
573 base.ExportStateAttributes(Output);
Contains a 2D layout document.
void Export(XmlWriter Output)
Exports the attribute.
void ExportState(XmlWriter Output)
Exports the state of the attribute.
static async Task< EvaluationResult< T > > TryEvaluate(Attribute< T > Attribute, Variables Session)
Tries to evaluate the attribute value.
Result of asynchronous evaluation.
T Result
Evaluated result, if successful.
bool Ok
If evaluation was successful.
StringAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
SKCanvas Canvas
Current drawing canvas.
Variables Session
Current session.
Layout2DDocument Document
Layout document.
bool defined
If element is well-defined.
static float CalcDirection(float x1, float y1, float x2, float y2)
Calculates the direction of the pen when drawing from (x1,y1) to (x2,y2).
Defines a shape for use elsewhere in the layout.
Task DrawTail(DrawingState State, IDirectedElement DirectedElement, SKPaint DefaultPen, SKPaint DefaultFill)
Draws shape as a tail
Task DrawHead(DrawingState State, IDirectedElement DirectedElement, SKPaint DefaultPen, SKPaint DefaultFill)
Draws shape as a head
Defines a vertex in the graf
float YCoordinate
Measured Y-coordinate
float XCoordinate
Measured X-coordinate
Interface for directed elements.
Base interface for all layout elements.
Layout2DDocument Document
Layout document.