-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWpfPathSource.cs
3905 lines (3890 loc) · 123 KB
/
WpfPathSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
namespace Wholemy {
public class PathSource {
#region #method# IntersectLines(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, x, y)
public static bool IntersectLines(double ax0, double ay0, double ax1, double ay1, double bx0, double by0, double bx1, double by1, ref double x, ref double y) {
var a = (bx1 - bx0) * (ay0 - by0) - (by1 - by0) * (ax0 - bx0);
var b = (ax1 - ax0) * (ay0 - by0) - (ay1 - ay0) * (ax0 - bx0);
var c = (by1 - by0) * (ax1 - ax0) - (bx1 - bx0) * (ay1 - ay0);
if (c != 0.0) {
var ua = a / c;
var ub = b / c;
if (0.0 <= ua && ua <= 1.0 && 0.0 <= ub && ub <= 1.0) {
x = ax0 + ua * (ax1 - ax0);
y = ay0 + ua * (ay1 - ay0);
return true;
} else {
return false;
}
} else {
return false;
if (a == 0 || b == 0) {
//result = new Intersection("Coincident");
} else {
//result = new Intersection("Parallel");
}
}
}
#endregion
#region #method# Rotate1(CX, CY, BX, BY, AR)
/// <summary>Поворачивает координаты #double# вокруг центра по корню четверти круга
/// где 90 градусов равно значению 0.25, а 360 градусов равно значению 1)</summary>
/// <param name="CX">Центр по оси X)</param>
/// <param name="CY">Центр по оси Y)</param>
/// <param name="BX">Старт и возвращаемый результат поворота по оси X)</param>
/// <param name="BY">Старт и возвращаемый результат поворота по оси Y)</param>
/// <param name="AR">Корень четверти от 0.0 до 1.0 отрицательная в обратную сторону)</param>
public static void Rotate1(double CX, double CY, ref double BX, ref double BY, double AR) {
if (AR == 0.0) return;
var TX = BX - CX;
var TY = BY - CY;
if (TX == 0.0 && TY == 0.0) return;
var PI = System.Math.PI / 0.5 * AR;
var Cos = System.Math.Cos(PI);
var Sin = System.Math.Sin(PI);
var X = (Cos * TX - Sin * TY + CX);
var Y = (Sin * TX + Cos * TY + CY);
BX = X;
BY = Y;
}
#endregion
#region #method# GetaR1(CX, CY, BX, BY, AX, AY)
/// <summary>Возвращает корень поворота от 0.0 до 1.0)</summary>
/// <param name="CX">Центр по оси X)</param>
/// <param name="CY">Центр по оси Y)</param>
/// <param name="BX">Старт по оси X)</param>
/// <param name="BY">Старт по оси Y)</param>
/// <param name="AX">Конец по оси X)</param>
/// <param name="AY">Конец по оси Y)</param>
/// <returns>Возвращает корень поворота от 0.0 до 1.0)</returns>
public static double GetaR1(double CX, double CY, double BX, double BY, double AX, double AY) {
var R = (0.5 / System.Math.PI) * (System.Math.Atan2(AY - CY, AX - CX) - System.Math.Atan2(BY - CY, BX - CX));
if (R < 0) R += 1.0;
return R;
}
#endregion
#region #method# Sqrt(X, Y)
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public static double Sqrt(double X, double Y) {
return System.Math.Sqrt(X * X + Y * Y);
}
#endregion
#region #method# RootOffset(x, y, X, Y)
public static double RootOffset(double x, double y, out double X, out double Y) {
var L = System.Math.Sqrt(x * x + y * y);
X = -y / L;
Y = x / L;
return L;
}
#endregion
#region #method# SetMulLen(MX, MY, EX, EY, Value)
public static double SetMulLen(double MX, double MY, ref double EX, ref double EY, double Value) {
var L = Sqrt(MX - EX, MY - EY);
if (L > 0) {
Value *= L;
EX = MX + (EX - MX) / L * Value;
EY = MY + (EY - MY) / L * Value;
}
return Value;
}
#endregion
#region #static# #method# Inline(X0, Y0, X1, Y1, X2, Y2)
public static bool Inline(double X0, double Y0, double X1, double Y1, double X2, double Y2) {
var l01 = Sqrt(X0 - X1, Y0 - Y1);
var l02 = Sqrt(X0 - X2, Y0 - Y2);
var l12 = Sqrt(X1 - X2, Y1 - Y2);
var R = 1.0;
if (l01 >= l02 && l01 >= l12) { R = l01 - (l02 + l12); }
if (l02 >= l01 && l02 >= l12) { R = l02 - (l01 + l12); }
if (l12 >= l01 && l12 >= l02) { R = l12 - (l01 + l02); }
return R > -0.000001 && R < 0.000001;
}
#endregion
#region #static# #method# Inline(X0, Y0, X1, Y1, X2, Y2, X3, Y3)
public static bool Inline(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3) {
return Inline(X0, Y0, X1, Y1, X2, Y2) && Inline(X1, Y1, X2, Y2, X3, Y3);
}
#endregion
#region #static# #method# DivRoots(Roots)
public static double[] DivRoots(double[] Roots = null) {
if (Roots != null) {
var L = Roots.Length;
var R = new double[L];
var I = 0;
var P = 0.0;
while (I < L) {
var A = Roots[I];
var S = (A - P) / (1.0 - P);
R[I] = S;
P = A;
I++;
}
return R;
}
return null;
}
#endregion
#region #static# #method# AddRoots(A, Roots)
public static double[] AddRoots(double A, double[] Roots = null) {
if (double.IsNaN(A) || A <= 0.0 || A >= 1.0) return Roots;
if (Roots == null) Roots = new double[] { A };
var L = Roots.Length;
var I = 0;
var R = 0;
if (L == 0) Roots = new double[] { A };
while (I < L) {
var B = Roots[I];
if (A == B) return Roots;
if (B < A) { R = I + 1; } else { break; }
I++;
}
var NewRoots = new double[L + 1];
if (R > 0) System.Array.Copy(Roots, NewRoots, R);
NewRoots[I] = A;
if (I < L) System.Array.Copy(Roots, I, NewRoots, I + 1, L - I);
return NewRoots;
}
#endregion
#region #static# #method# AddBoxRoots(A, B, C, Roots)
public static double[] AddBoxRoots(double A, double B, double C, double[] Roots = null) {
var D = A - (B * 2) + C;
if (D != 0.0) {
var L = System.Math.Sqrt(B * B - A * C);
if (!double.IsNaN(L)) {
C = -A + B;
A = -(-L + C) / D;
B = -(L + C) / D;
Roots = AddRoots(A, Roots);
Roots = AddRoots(B, Roots);
}
}
return Roots;
}
#endregion
public static readonly double Arc14 = 4.0 / 3.0 * System.Math.Tan(System.Math.PI / 8);
#region #invisible#
#if TRACE
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
#endif
#endregion
private System.Windows.Media.StreamGeometry LastPath;
#region #invisible#
#if TRACE
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
#endif
#endregion
private System.Windows.Media.GeometryCombineMode LastMode;
public System.Windows.Media.Geometry Geometry {
get {
var G = this.LastPath;
if (G == null && Figures != null) { this.LastPath = G = FiguresToGeometry(); }
return G;
}
}
#region #invisible#
#if TRACE
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
#endif
#endregion
private List CombinedFigures;
public List Combined {
get {
var C = this.CombinedFigures;
if (C == null) {
var G = this.LastPath;
System.Windows.Media.PathGeometry GG = null;
if (G == null && Figures != null) {
this.LastPath = G = FiguresToGeometry();
}
if (G != null) {
var P = new System.Windows.Media.PathGeometry();
GG = System.Windows.Media.PathGeometry.Combine(P, G, System.Windows.Media.GeometryCombineMode.Union, null, Tolerance, ToleranceType);
C = this.CombinedFigures = GetGeometry(GG);
}
}
return C;
}
}
public PathSource() { }
public double Tolerance = 0.5;
public System.Windows.Media.ToleranceType ToleranceType = System.Windows.Media.ToleranceType.Absolute;
public bool IsUnited = true;
public bool IsFilled = true;
public bool IsClozed = true;
public bool Inverted;
private Preset RootM;
private Preset RootE;
#region #class# Preset
public class Preset {
public double Value;
public Preset(double Value) {
if (Value < 0 || Value > 1) throw new System.ArgumentOutOfRangeException();
this.Value = Value;
}
}
#endregion
#region #method# PresetRoot(Root)
public void PresetRoot(double Root) {
if (Root < 0) {
this.RootE = new Preset(-Root);
} else {
this.RootM = new Preset(Root);
}
}
#endregion
#region #method# PresetRoot(RootM, RootE)
public void PresetRoot(double RootM, double RootE) {
if (RootM < 0) RootM = -RootM;
if (RootE < 0) RootE = -RootE;
this.RootE = new Preset(RootM);
this.RootM = new Preset(RootE);
}
#endregion
private Change Mod;
private List Figures;
private FigureProcessing ProcessingFigure;
/// <summary>Толщина линий)</summary>
public double Thickness;
public bool IsBoned;
public bool IsRoundM;
public bool IsRoundE;
public const double QualityMax = 0.5;
public const double QualityBut = 0.05;
public const double QualityMin = 0.005;
#region #property# Figures
// private Figure[] Figures {
// #region #through#
//#if TRACE
// [System.Diagnostics.DebuggerStepThrough]
//#endif
// #endregion
// get {
// var Count = this.FigureSize;
// var Array = new Figure[Count--];
// var Cache = this.FigureLast;
// while (Count >= 0) {
// Array[Count--] = Cache;
// Cache = Cache.Prev;
// }
// return Array;
// }
// }
#endregion
#region #method# FiguresToGeometry
private System.Windows.Media.StreamGeometry FiguresToGeometry() {
if (Figures == null) return null;
var Stream = new System.Windows.Media.StreamGeometry();
Stream.FillRule = IsUnited ? System.Windows.Media.FillRule.Nonzero : System.Windows.Media.FillRule.EvenOdd;
var Context = Stream.Open();
var Figure = Figures.Base as Figure;
while (Figure != null) {
var Curves = Figure.Curves;
if (Curves != null && Curves.Count > 0) {
var Cache = Curves.Base as Curve;
var Value = Cache.Line;
Context.BeginFigure(new System.Windows.Point(Value.MX, Value.MY), Figure.IsFilled, Figure.IsClozed);
Value.To(Context);
var PreX = Value.EX;
var PreY = Value.EY;
Cache = Cache.Next as Curve;
while (Cache != null) {
Value = Cache.Line;
Value.If(Context, PreX, PreY);
Value.To(Context);
PreX = Value.EX;
PreY = Value.EY;
Cache = Cache.Next as Curve;
}
}
Figure = Figure.Next as Figure;
}
Context.Close();
return Stream;
}
#endregion
#region #method# CombineToGeometry
public System.Windows.Media.Geometry CombineToGeometry() {
var Path = FiguresToGeometry();
return Path;
}
#endregion
#region #method# GetGeometry(Geometry)
public List GetGeometry(System.Windows.Media.Geometry Geometry) {
var FigureList = new List();
var Path = Geometry as System.Windows.Media.PathGeometry;
if (Path == null) Path = Geometry.GetFlattenedPathGeometry(Tolerance, ToleranceType);
var Figures = Path.Figures;
foreach (var Figure in Figures) {
var F = new Figure(Figure.IsFilled, Figure.IsClosed);
var P0 = Figure.StartPoint;
var Segments = Figure.Segments;
var SegmentList = new List();
foreach (var Segment in Segments) {
var MX = P0.X;
var MY = P0.Y;
if (Segment is System.Windows.Media.LineSegment) {
var S = (System.Windows.Media.LineSegment)Segment;
var P1 = S.Point;
SegmentList.AddLast(new Curve(P0.X, P0.Y, P1.X, P1.Y));
P0 = P1;
} else if (Segment is System.Windows.Media.PolyLineSegment) {
var Poly = (System.Windows.Media.PolyLineSegment)Segment;
var Points = Poly.Points;
var C = Points.Count;
for (var I = 0; I < C; I++) {
var P1 = Points[I];
SegmentList.AddLast(new Curve(P0.X, P0.Y, P1.X, P1.Y));
P0 = P1;
}
} else if (Segment is System.Windows.Media.QuadraticBezierSegment) {
var S = (System.Windows.Media.QuadraticBezierSegment)Segment;
var P1 = S.Point1;
var P2 = S.Point2;
SegmentList.AddLast(new Curve(P0.X, P0.Y, P1.X, P1.Y, P2.X, P2.Y));
P0 = P2;
} else if (Segment is System.Windows.Media.PolyQuadraticBezierSegment) {
var Poly = (System.Windows.Media.PolyQuadraticBezierSegment)Segment;
var Points = Poly.Points;
var C = Points.Count;
for (var I = 0; I < C; I += 2) {
var P1 = Points[I];
var P2 = Points[I + 1];
SegmentList.AddLast(new Curve(P0.X, P0.Y, P1.X, P1.Y, P2.X, P2.Y));
P0 = P2;
}
} else if (Segment is System.Windows.Media.BezierSegment) {
var S = (System.Windows.Media.BezierSegment)Segment;
var P1 = S.Point1;
var P2 = S.Point2;
var P3 = S.Point3;
SegmentList.AddLast(new Curve(P0.X, P0.Y, P1.X, P1.Y, P2.X, P2.Y, P3.X, P3.Y));
P0 = P3;
} else if (Segment is System.Windows.Media.PolyBezierSegment) {
var Poly = (System.Windows.Media.PolyBezierSegment)Segment;
var Points = Poly.Points;
var C = Points.Count;
for (var I = 0; I < C; I += 3) {
var P1 = Points[I];
var P2 = Points[I + 1];
var P3 = Points[I + 2];
SegmentList.AddLast(new Curve(P0.X, P0.Y, P1.X, P1.Y, P2.X, P2.Y, P3.X, P3.Y));
P0 = P3;
}
} else {
throw new System.NotSupportedException();
}
}
if (SegmentList.Count > 0) {
F.Curves = SegmentList;
FigureList.AddLast(F);
}
}
return FigureList;
}
#endregion
#region #method# Begin[Hollow = H|Filled = F][Closed = z]
public void Begin() {
End();
this.ProcessingFigure = new FigureProcessing(this.IsFilled, this.IsClozed);
}
public void BeginHz() {
End();
this.ProcessingFigure = new FigureProcessing(false, true);
}
public void BeginH() {
End();
this.ProcessingFigure = new FigureProcessing(false, false);
}
public void BeginFz() {
End();
this.ProcessingFigure = new FigureProcessing(true, true);
}
public void BeginF() {
End();
this.ProcessingFigure = new FigureProcessing(true, false);
}
#endregion
#region #method# End
public void End() {
var Figure = this.ProcessingFigure;
if (Figure != null) {
Figure.End();
var Curves = Figure.Curves;
if (Curves != null && Curves.Count > 0) {
var Figures = this.Figures;
if (Figures == null) { this.Figures = Figures = new List(); }
Figures.AddLast(Figure);
}
this.ProcessingFigure = null;
this.LastPath = null;
this.CombinedFigures = null;
}
}
#endregion
#region #method# AddCurve(Line)
public Curve AddCurve(Line Line) {
var Figure = DemandFigure();
var Inverted = this.Inverted;
var LineItem = new Curve(Line.Change(this.Mod, Inverted));
var Curves = Figure.ProcessingCurves;
if (Curves == null) Curves = Figure.ProcessingCurves = new List();
if (Inverted) { Curves.AddBase(LineItem); } else { Curves.AddLast(LineItem); }
return LineItem;
}
#endregion
#region #method# AddCurve(MX, MY, EX, EY)
public Curve AddCurve(double MX, double MY, double EX, double EY) {
return AddCurve(new Line(MX, MY, EX, EY));
}
#endregion
#region #method# AddCurve(MX, MY, QX, QY, EX, EY)
public Curve AddCurve(double MX, double MY, double QX, double QY, double EX, double EY) {
return AddCurve(new Quadratic(MX, MY, QX, QY, EX, EY));
}
#endregion
#region #method# DemandFigure
public FigureProcessing DemandFigure() {
var Figure = this.ProcessingFigure;
if (Figure == null) throw new System.InvalidOperationException();
return Figure;
}
#endregion
#region #method# AddCurve(MX, MY, cmX, cmY, ceX, ceY, EX, EY)
public Curve AddCurve(double MX, double MY, double cmX, double cmY, double ceX, double ceY, double EX, double EY) {
return AddCurve(new Cubic(MX, MY, cmX, cmY, ceX, ceY, EX, EY));
}
#endregion
#region #method# AddBone(Line)
public Curve AddBone(Line Line) {
var Figure = DemandFigure();
var Inverted = this.Inverted;
var LineItem = new Curve(Line.Change(this.Mod, Inverted));
var Curves = Figure.ProcessingBones;
if (Curves == null) Curves = Figure.ProcessingBones = new List();
if (Inverted) { Curves.AddBase(LineItem); } else { Curves.AddLast(LineItem); }
return LineItem;
}
#endregion
#region #method# AddBone(MX, MY, EX, EY)
public Curve AddBone(double MX, double MY, double EX, double EY) {
return AddBone(new Line(MX, MY, EX, EY));
}
#endregion
#region #method# AddBone(MX, MY, QX, QY, EX, EY)
public Curve AddBone(double MX, double MY, double QX, double QY, double EX, double EY) {
return AddBone(new Quadratic(MX, MY, QX, QY, EX, EY));
}
#endregion
#region #method# AddBone(MX, MY, cmX, cmY, ceX, ceY, EX, EY)
public Curve AddBone(double MX, double MY, double cmX, double cmY, double ceX, double ceY, double EX, double EY) {
return AddBone(new Cubic(MX, MY, cmX, cmY, ceX, ceY, EX, EY));
}
#endregion
#region #method# CutRotate
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void CutRotate() {
this.Mod = this.Mod?.Next;
}
#endregion
#region #method# AddRotate(AN, CX, CY)
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void AddRotate(double AN, double CX, double CY, Mods Mods = Mods.All) {
this.Mod = new RotAsMod(this.Mod, AN, CX, CY, Mods);
}
#endregion
#region #method# SetRotate(AN, CX, CY)
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void SetRotate(double AN, double CX, double CY) {
this.Mod = new RotAsMod(this.Mod?.Next, AN, CX, CY);
}
#endregion
#region #method# AddRotate(AX, AY, CX, CY)
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void AddRotate(double AX, double AY, double CX, double CY, bool CW = false, Mods Mods = Mods.All) {
this.Mod = new RotOfMod(this.Mod, AX, AY, CX, CY, CW, Mods);
}
#endregion
#region #method# AddRotate(CX, CY, BX, BY, AX, AY)
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void AddRotate(double CX, double CY, double BX, double BY, double AX, double AY, Mods Mods = Mods.All) {
this.Mod = new RotateMod(this.Mod, CX, CY, BX, BY, AX, AY, Mods);
}
#endregion
#region #method# SetRotate(AX, AY, CX, CY)
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void SetRotate(double AX, double AY, double CX, double CY, bool CW = false) {
this.Mod = new RotOfMod(this.Mod?.Next, AX, AY, CX, CY, CW);
}
#endregion
#region #method# CutResize
public void CutResize() {
this.Mod = this.Mod?.Next;
}
#endregion
#region #method# AddResizeMoved(WH, W, H, XY, X, Y)
/// <summary>Добавляет изменение размера и смещение координат по указанному размеру)</summary>
/// <param name="WH">Ширина и высота где единица это текущий размер)</param>
/// <param name="W">Ширина где единица это текущий размер)</param>
/// <param name="H">Высота где единица это текущий размер)</param>
/// <param name="XY">Горизонтальное и вертикальное смещение)</param>
/// <param name="X">Горизонтальное смещение)</param>
/// <param name="Y">Вертикальное смещение)</param>
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void AddResizeMoved(double WH = 1.0, double W = 1.0, double H = 1.0, double XY = 0.0, double X = 0.0, double Y = 0.0) {
W *= WH;
H *= WH;
X += XY;
Y += XY;
X *= W;
Y *= H;
if (W != 1.0 || H != 1.0 || X != 0.0 || Y != 0.0) {
this.Mod = new ResizeMod(this.Mod, W, H, X, Y);
}
}
#endregion
#region #method# SetResizeMoved(WH, W, H, XY, X, Y)
/// <summary>Добавляет или устанавливает изменение размера и смещение координат по указанному размеру)</summary>
/// <param name="WH">Ширина и высота где единица это текущий размер)</param>
/// <param name="W">Ширина где единица это текущий размер)</param>
/// <param name="H">Высота где единица это текущий размер)</param>
/// <param name="XY">Горизонтальное и вертикальное смещение)</param>
/// <param name="X">Горизонтальное смещение)</param>
/// <param name="Y">Вертикальное смещение)</param>
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void SetResizeMoved(double WH = 1.0, double W = 1.0, double H = 1.0, double XY = 0.0, double X = 0.0, double Y = 0.0) {
this.Mod = this.Mod?.Next;
W *= WH;
H *= WH;
X += XY;
Y += XY;
X *= W;
Y *= H;
if (W != 1.0 || H != 1.0 || X != 0.0 || Y != 0.0) {
this.Mod = new ResizeMod(this.Mod, W, H, X, Y);
}
}
#endregion
#region #method# AddResizeMovA(WH, W, H, XY, X, Y)
/// <summary>Добавляет изменение размера и смещение координат после изменения размера)</summary>
/// <param name="WH">Ширина и высота где единица это текущий размер)</param>
/// <param name="W">Ширина где единица это текущий размер)</param>
/// <param name="H">Высота где единица это текущий размер)</param>
/// <param name="XY">Горизонтальное и вертикальное смещение)</param>
/// <param name="X">Горизонтальное смещение)</param>
/// <param name="Y">Вертикальное смещение)</param>
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void AddResizeMovA(double WH = 1.0, double W = 1.0, double H = 1.0, double XY = 0.0, double X = 0.0, double Y = 0.0) {
W *= WH;
H *= WH;
X += XY;
Y += XY;
if (W != 1.0 || H != 1.0 || X != 0.0 || Y != 0.0) {
this.Mod = new ResizeMod(this.Mod, W, H, X, Y);
}
}
#endregion
#region #method# SetResizeMovA(WH, W, H, XY, X, Y)
/// <summary>Добавляет или устанавливает изменение размера и смещение координат после изменения размера)</summary>
/// <param name="WH">Ширина и высота где единица это текущий размер)</param>
/// <param name="W">Ширина где единица это текущий размер)</param>
/// <param name="H">Высота где единица это текущий размер)</param>
/// <param name="XY">Горизонтальное и вертикальное смещение)</param>
/// <param name="X">Горизонтальное смещение)</param>
/// <param name="Y">Вертикальное смещение)</param>
#region #through#
#if TRACE
[System.Diagnostics.DebuggerStepThrough]
#endif
#endregion
public void SetResizeMovA(double WH = 1.0, double W = 1.0, double H = 1.0, double XY = 0.0, double X = 0.0, double Y = 0.0) {
this.Mod = this.Mod?.Next;
W *= WH;
H *= WH;
X += XY;
Y += XY;
if (W != 1.0 || H != 1.0 || X != 0.0 || Y != 0.0) {
this.Mod = new ResizeMod(this.Mod, W, H, X, Y);
}
}
#endregion
#region #class# ResizeMod
public class ResizeMod : Change {
public double SX, SY, MX, MY;
public ResizeMod(Change Next, double SX, double SY, double MX, double MY, Mods Mods = Mods.All) : base(Next, Mods) {
this.SX = SX;
this.SY = SY;
this.MX = MX;
this.MY = MY;
}
public override void Modify(ref double X, ref double Y, bool x, bool y) {
if (x || y) {
var RX = X;
var RY = Y;
if (x) X = RX * SX + MX;
if (y) Y = RY * SY + MY;
}
}
}
#endregion
#region #class# Change
public abstract class Change {
public readonly Change Next;
public readonly Mods Mods;
public Change(Change Next, Mods Mods) {
this.Next = Next;
this.Mods = Mods;
}
public abstract void Modify(ref double X, ref double Y, bool x, bool y);
}
#endregion
#region #enum# Mods
[System.Flags]
public enum Mods {
MX = 1,
MY = 2,
Mxy = MX | MY,
EX = 4,
EY = 8,
Exy = EX | EY,
QX = 16,
QY = 32,
Qxy = QX | QY,
cmX = 64,
cmY = 128,
cmxy = cmX | cmY,
ceX = 256,
ceY = 512,
cexy = ceX | ceY,
CX = cmX | ceX,
CY = cmY | ceY,
Cxy = cmxy | cexy,
All = Mxy | Exy | Qxy | Cxy
}
#endregion
#region #class# RotAsMod
public class RotateMod : Change {
public double AR, CX, CY;
public RotateMod(Change Next, double CX, double CY, double AR, Mods Mods = Mods.All) : base(Next, Mods) {
this.AR = AR;
this.CX = CX;
this.CY = CY;
}
public RotateMod(Change Next, double CX, double CY, double BX, double BY, double AX, double AY, Mods Mods = Mods.All) : base(Next, Mods) {
this.AR = AR = GetaR1(CX, CY, BX, BY, AX, AY);
this.CX = CX;
this.CY = CY;
}
public override void Modify(ref double X, ref double Y, bool x, bool y) {
if (x || y) {
var AX = X;
var AY = Y;
Rotate1(this.CX, this.CY, ref AX, ref AY, this.AR);
if (x) X = AX;
if (y) Y = AY;
}
}
}
public class RotAsMod : Change {
public double A, CX, CY;
public RotAsMod(Change Next, double A, double CX, double CY, Mods Mods = Mods.All) : base(Next, Mods) {
this.A = A;
this.CX = CX;
this.CY = CY;
}
public override void Modify(ref double X, ref double Y, bool x, bool y) {
if (x || y) {
var RX = X;
var RY = Y;
var A = this.A;
var CX = this.CX;
var CY = this.CY;
A = A * System.Math.PI / 180.0;
var AC = System.Math.Cos(A);
var AS = System.Math.Sin(A);
RX -= CX;
RY -= CY;
if (x) X = ((RX * AC) - (RY * AS)) + CX;
if (y) Y = ((RX * AS) + (RY * AC)) + CY;
}
}
}
#endregion
#region #class# RotOfMod
public class RotOfMod : Change {
public readonly double AR;
public readonly double AX, AY, CX, CY;
public readonly bool CW;
public RotOfMod(Change Next, double AX, double AY, double CX, double CY, bool CW, Mods Mods = Mods.All) : base(Next, Mods) {
this.AX = AX;
this.AY = AY;
this.CX = CX;
this.CY = CY;
this.CW = CW;
}
public override void Modify(ref double X, ref double Y, bool x, bool y) {
if (x || y) {
var RX = X;
var RY = Y;
var AX = this.AX;
var AY = this.AY;
var CX = this.CX;
var CY = this.CY;
double A;
if (((CX < AX && CY < AY) || (CX > AX && CY > AY)) ^ CW) {
A = (AY > CY ? AY - CY : CY - AY) / (AX > CX ? CX - AX : AX - CX);
} else {
A = (AX > CX ? CX - AX : AX - CX) / (AY > CY ? AY - CY : CY - AY);
}
if (!CW) A = -A;
A = System.Math.Atan(A);
var AC = System.Math.Cos(A);
var AS = System.Math.Sin(A);
RX -= CX;
RY -= CY;
if (x) X = ((RX * AC) - (RY * AS)) + CX;
if (y) Y = ((RX * AS) + (RY * AC)) + CY;
}
}
}
#endregion
#region #class# Figure
public class Figure : Item {
public bool IsFilled;
public bool IsClozed;
public List Curves;
public List Bones;
#region #new# (IsFilled, IsClozed)
public Figure(bool IsFilled, bool IsClozed) {
this.IsFilled = IsFilled;
this.IsClozed = IsClozed;
}
#endregion
#region #method# ToString
public override string ToString() {
var I = System.Globalization.CultureInfo.InvariantCulture;
var S = "Figure";
var Curves = this.Curves;
if (Curves != null) { S += " Curves = " + Curves.Count.ToString(I); }
var Bones = this.Bones;
if (Bones != null) { S += " Bones = " + Bones.Count.ToString(I); }
if (IsFilled) S += " IsFilled";
if (IsClozed) S += " IsClozed";
return S;
}
#endregion
}
#endregion
#region #class# FigureProcessing
public class FigureProcessing : Figure {
public List ProcessingCurves;
public List ProcessingBones;
#region #new# (IsFilled, IsClozed)
public FigureProcessing(bool IsFilled, bool IsClozed) : base(IsFilled, IsClozed) {
}
#endregion
#region #method# ToString
public override string ToString() {
var I = System.Globalization.CultureInfo.InvariantCulture;
var S = base.ToString();
var ProcessingCurves = this.ProcessingCurves;
if (ProcessingCurves != null) { S += " ProcessingCurves = " + ProcessingCurves.Count.ToString(I); }
var ProcessingBones = this.ProcessingBones;
if (ProcessingBones != null) { S += " ProcessingBones = " + ProcessingBones.Count.ToString(I); }
return S;
}
#endregion
#region #method# End
public void End() {
var Bones = this.Bones;
var ProcessingBones = this.ProcessingBones;
if (ProcessingBones != null && ProcessingBones.Count > 0) {
if (Bones != null) {
Bones.AddLast(ProcessingBones);
} else {
this.Bones = ProcessingBones;
}
this.ProcessingBones = null;
}
var Curves = this.Curves;
var ProcessingCurves = this.ProcessingCurves;
if (ProcessingCurves != null && ProcessingCurves.Count > 0) {
if (Curves != null) {
Curves.AddLast(ProcessingCurves);
} else {
this.Curves = ProcessingCurves;
}
this.ProcessingCurves = null;
}
}
#endregion
}
#endregion
#region #class# Line
public class Line {
public double MX;
public double MY;
public double EX;
public double EY;
#region #new#
public Line() { }
#endregion
#region #new# (MX, MY, EX, EY)
public Line(double MX, double MY, double EX, double EY) {
this.MX = MX; this.MY = MY; this.EX = EX; this.EY = EY;
}
#endregion
#region #method# Invert
public virtual void Invert() {
var V = this.EX;
this.EX = this.MX;
this.MX = V;
V = this.EY;
this.EY = this.MY;
this.MY = V;
}
#endregion
#region #method# Change(Mod, Inverted)
public virtual Line Change(Change Mod, bool Inverted) {
var MX = this.MX; var MY = this.MY; var EX = this.EX; var EY = this.EY;
while (Mod != null) {
Mod.Modify(ref MX, ref MY, (Mod.Mods & Mods.MX) != 0, (Mod.Mods & Mods.MY) != 0);
Mod.Modify(ref EX, ref EY, (Mod.Mods & Mods.EX) != 0, (Mod.Mods & Mods.EY) != 0);
Mod = Mod.Next;
}
if (Inverted)
return new Line(EX, EY, MX, MY);
return new Line(MX, MY, EX, EY);
}
#endregion
#region #method# If(Context, X, Y)
public virtual void If(System.Windows.Media.StreamGeometryContext Context, double X, double Y) {
if (!double.Equals(X, MX) || !double.Equals(Y, MY)) {
if (Sqrt(X - MX, Y - MY) > 10.0) {
}
Context.LineTo(new System.Windows.Point(MX, MY), true, true);
}
}
#endregion
#region #method# To(Context)
public virtual void To(System.Windows.Media.StreamGeometryContext Context) {
Context.LineTo(new System.Windows.Point(EX, EY), true, true);
}
#endregion
#region #method# ToPathString
public virtual string ToPathString() {
var I = System.Globalization.CultureInfo.InvariantCulture;
return "L" + EX.ToString(I) + "," + EY.ToString(I);
}
#endregion
#region #method# ToCompessedString(Prev)
public virtual string ToCompessedString(Line Prev) {
var S = "";
var I = System.Globalization.CultureInfo.InvariantCulture;
if (this.Prefix == 'L') {
if (Prev == null) { S = "M" + MX.ToString(I) + "," + MY.ToString(I); }
if (MX == EX) {
var V = "V" + EY.ToString(I);
var v = "v" + (EY - MY).ToString(I);
if (v.Length < V.Length) { S += v; } else { S += V; }
} else if (MY == EY) {
var H = "H" + EX.ToString(I);
var h = "h" + (EX - MX).ToString(I);
if (h.Length < H.Length) { S += h; } else { S += H; }
} else {
var L = "L" + EX.ToString(I) + "," + EY.ToString(I);
var l = "l" + (EX - MX).ToString(I) + "," + (EY - MY).ToString(I);
if (l.Length < L.Length) { S += l; } else { S += L; }
}
}
return S;
}
#endregion
#region #method# ToString
public override string ToString() {
var I = System.Globalization.CultureInfo.InvariantCulture;
return "M" + MX.ToString(I) + "," + MY.ToString(I) + "L" + EX.ToString(I) + "," + EY.ToString(I);
}
#endregion
#region #method# ToArcC(Acw)
public Cubic ToArcC(bool Acw = false) {
var MX = this.MX;
var MY = this.MY;
var EX = this.EX;
var EY = this.EY;
var cmX = MX;
var cmY = MY;
var ceX = EX;
var ceY = EY;
if (((MX < EX && MY < EY) || (MX > EX && MY > EY)) ^ Acw) {
cmX += ((EX - MX) * Arc14);
ceY += ((MY - EY) * Arc14);
} else {
cmY += ((EY - MY) * Arc14);
ceX += ((MX - EX) * Arc14);
}
return new Cubic(MX, MY, cmX, cmY, ceX, ceY, EX, EY);
}
#endregion
#region #method# Cuted(r0)
public Line Cuted(double r0) {
if ((r0 < 1.0) && (r0 > -1.0)) {
if (r0 != 0.0) {
var root = r0 < 0.0 ? 1.0 + r0 : r0;
var x00 = this.MX;
var y00 = this.MY;
var x11 = this.EX;
var y11 = this.EY;
var x01 = (x11 - x00) * root + x00;
var y01 = (y11 - y00) * root + y00;
if (r0 < 0.0) {
this.MX = x00; this.MY = y00;
this.EX = x01; this.EY = y01;
} else {
this.MX = x01; this.MY = y01;
this.EX = x11; this.EY = y11;
}
}
}
return this;
}
#endregion
#region #method# Cuted(r0, r1)
public Line Cuted(double r0, double r1) {
if ((r0 < 1.0) && (r0 > -1.0)) {
r1 = (r1 / (1.0 - r0));
while (r0 != 0.0) {
var root = r0 < 0.0 ? 1.0 + r0 : r0;
var x00 = this.MX;
var y00 = this.MY;
var x11 = this.EX;