Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConicTo.cs
1using System.Threading.Tasks;
2using SkiaSharp;
3
5{
10 {
16 public ConicTo(Layout2DDocument Document, ILayoutElement Parent)
17 : base(Document, Parent)
18 {
19 }
20
24 public override string LocalName => "ConicTo";
25
32 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
33 {
34 return new ConicTo(Document, Parent);
35 }
36
42 public virtual Task Measure(DrawingState State, PathState PathState)
43 {
44 if (this.defined)
45 {
48 }
49
50 return Task.CompletedTask;
51 }
52
59 public virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
60 {
61 if (this.defined)
62 {
63 this.P0 = Path.LastPoint;
64 this.P1 = new SKPoint(this.xCoordinate, this.yCoordinate);
65 this.P2 = new SKPoint(this.xCoordinate2, this.yCoordinate2);
66
69 Path.ConicTo(this.P1, this.P2, this.weight);
70 }
71
72 return Task.CompletedTask;
73 }
74
78 protected SKPoint P0;
79
83 protected SKPoint P1;
84
88 protected SKPoint P2;
89
97 public bool TryGetStart(out float X, out float Y, out float Direction)
98 {
99 // P(t) = ((1 – t)²P₀ + 2wt(1 – t)P₁ + t²P₂) / ((1 – t)² + 2wt(1 – t) + t²)
100 // = ((1-2t+t²)P₀ + (2wt-2wt²)P₁ + t²P₂) / (1-2t+t²+2wt-2wt²+t²)
101 // = (P₀ +t(2wP₁-2P₀) + t²(P₀-2wP₁+P₂)) / (1+t(2w-2)+t²(2-2w))
102 //
103 // P'(t) = ((2wP₁-2P₀+2t(P₀-2wP₁+P₂))*(1+t(2w-2)+t²(2-2w))-(P₀ +t(2wP₁-2P₀) + t²(P₀-2wP₁+P₂))*(2w-2+2t(2-2w)))/(1+t(2w-2)+t²(2-2w))²
104 //
105 // P'(0) = 2w(P₁-P₀)
106 // P'(1) = -P₀-2wP₁+2P₂ = 2(P₂-wP₁)-P₀ Note: Error somewhere. Should be 2w(P₂-P₁) for symmetry
107
108 float w2 = this.weight * 2;
109 float dx = w2 * (P1.X - P0.X);
110 float dy = w2 * (P1.Y - P0.Y);
111
112 X = this.P0.X;
113 Y = this.P0.Y;
114 Direction = CalcDirection(dx, dy);
115
116 return this.defined;
117 }
118
126 public bool TryGetEnd(out float X, out float Y, out float Direction)
127 {
128 float w2 = this.weight * 2;
129 float dx = w2 * (P2.X - P1.X);
130 float dy = w2 * (P2.Y - P1.Y);
131
132 X = this.P2.X;
133 Y = this.P2.Y;
134 Direction = CalcDirection(dx, dy);
135
136 return this.defined;
137 }
138 }
139}
Contains a 2D layout document.
Draws a conic curve to a point, relative to the origio of the current container
Definition: ConicTo.cs:10
bool TryGetEnd(out float X, out float Y, out float Direction)
Tries to get end position and terminating direction.
Definition: ConicTo.cs:126
bool TryGetStart(out float X, out float Y, out float Direction)
Tries to get start position and initial direction.
Definition: ConicTo.cs:97
virtual Task Measure(DrawingState State, PathState PathState)
Measures layout entities and defines unassigned properties.
Definition: ConicTo.cs:42
virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
Draws layout entities.
Definition: ConicTo.cs:59
ConicTo(Layout2DDocument Document, ILayoutElement Parent)
Draws a conic curve to a point, relative to the origio of the current container
Definition: ConicTo.cs:16
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: ConicTo.cs:32
override string LocalName
Local name of type of element.
Definition: ConicTo.cs:24
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 two points and a weight.
Definition: Point2Weight.cs:11
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.