Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CubicTo.cs
1using System.Threading.Tasks;
2using SkiaSharp;
3
5{
10 {
16 public CubicTo(Layout2DDocument Document, ILayoutElement Parent)
17 : base(Document, Parent)
18 {
19 }
20
24 public override string LocalName => "CubicTo";
25
32 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
33 {
34 return new CubicTo(Document, Parent);
35 }
36
42 public virtual Task Measure(DrawingState State, PathState PathState)
43 {
44 if (this.defined)
45 {
49 }
50
51 return Task.CompletedTask;
52 }
53
60 public virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
61 {
62 if (this.defined)
63 {
64 this.P0 = Path.LastPoint;
65 this.P1 = new SKPoint(this.xCoordinate, this.yCoordinate);
66 this.P2 = new SKPoint(this.xCoordinate2, this.yCoordinate2);
67 this.P3 = new SKPoint(this.xCoordinate3, this.yCoordinate3);
68
72 Path.CubicTo(this.P1, this.P2, this.P3);
73 }
74
75 return Task.CompletedTask;
76 }
77
81 protected SKPoint P0;
82
86 protected SKPoint P1;
87
91 protected SKPoint P2;
92
96 protected SKPoint P3;
97
105 public bool TryGetStart(out float X, out float Y, out float Direction)
106 {
107 // B(t) = (1-t)³P₀+3(1-t)²tP₁+3(1-t)t²P₂+t³P₃
108 // B'(t) = 3(1-t)²(P₁-P₀)+6(1-t)t(P₂-P₁)+3t²(P₃-P₂)
109 //
110 // B'(0) = 3(P₁-P₀)
111 // B'(1) = 3(P₃-P₂)
112 //
113 // Ratio will be compared, so no need to multiply with 3.
114
115 float dx = P1.X - P0.X;
116 float dy = P1.Y - P0.Y;
117
118 X = this.P0.X;
119 Y = this.P0.Y;
120 Direction = CalcDirection(dx, dy);
121
122 return this.defined;
123 }
124
132 public bool TryGetEnd(out float X, out float Y, out float Direction)
133 {
134 float dx = P3.X - P2.X;
135 float dy = P3.Y - P2.Y;
136
137 X = this.P3.X;
138 Y = this.P3.Y;
139 Direction = CalcDirection(dx, dy);
140
141 return this.defined;
142 }
143
144 }
145}
Contains a 2D layout document.
Draws a cubic curve to a point, relative to the origio of the current container
Definition: CubicTo.cs:10
bool TryGetEnd(out float X, out float Y, out float Direction)
Tries to get end position and terminating direction.
Definition: CubicTo.cs:132
CubicTo(Layout2DDocument Document, ILayoutElement Parent)
Draws a cubic curve to a point, relative to the origio of the current container
Definition: CubicTo.cs:16
bool TryGetStart(out float X, out float Y, out float Direction)
Tries to get start position and initial direction.
Definition: CubicTo.cs:105
override string LocalName
Local name of type of element.
Definition: CubicTo.cs:24
virtual Task Measure(DrawingState State, PathState PathState)
Measures layout entities and defines unassigned properties.
Definition: CubicTo.cs:42
virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
Draws layout entities.
Definition: CubicTo.cs:60
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: CubicTo.cs:32
void Set(float X, float Y)
Sets a new coordinate
Definition: PathState.cs:161
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).
float yCoordinate2
Measured Y-coordinate
Definition: Point2.cs:122
float xCoordinate2
Measured X-coordinate
Definition: Point2.cs:117
Abstract base class for layout elements with three points.
Definition: Point3.cs:11
float xCoordinate3
Measured X-coordinate
Definition: Point3.cs:117
float yCoordinate3
Measured Y-coordinate
Definition: Point3.cs:122
float yCoordinate
Measured Y-coordinate
Definition: Point.cs:122
float xCoordinate
Measured X-coordinate
Definition: Point.cs:117
Interface for directed elements.
Base interface for all layout elements.