@armyc2.c5isr.renderer/mil-sym-ts-web 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +57 -0
  3. package/buildNode.bat +2 -0
  4. package/buildWeb.bat +2 -0
  5. package/dist/C5Ren.d.ts +6970 -0
  6. package/dist/C5Ren.js +2 -0
  7. package/dist/C5Ren.js.map +1 -0
  8. package/dist/LICENSE +201 -0
  9. package/dist/README.md +57 -0
  10. package/dist/armyc2.c5isr.renderer-mil-sym-ts-web-2.2.0.tgz +0 -0
  11. package/dist/manifest.json +4 -0
  12. package/dist/package.json +16 -0
  13. package/index.ts +169 -0
  14. package/package.bak +50 -0
  15. package/package.json +40 -0
  16. package/package.node.json +43 -0
  17. package/package.pack.json +19 -0
  18. package/package.packWeb.json +16 -0
  19. package/package.web.json +40 -0
  20. package/src/main/ts/android/graphics/Bitmap.ts +7 -0
  21. package/src/main/ts/android/graphics/Paint.ts +26 -0
  22. package/src/main/ts/android/graphics/Path.ts +78 -0
  23. package/src/main/ts/android/graphics/PointF.ts +14 -0
  24. package/src/main/ts/android/graphics/Rect.ts +18 -0
  25. package/src/main/ts/android/graphics/RectF.ts +50 -0
  26. package/src/main/ts/android/graphics/Region.ts +36 -0
  27. package/src/main/ts/android/graphics/Typeface.ts +11 -0
  28. package/src/main/ts/armyc2/c5isr/JavaLineArray/BasicShapes.ts +99 -0
  29. package/src/main/ts/armyc2/c5isr/JavaLineArray/CChannelPoints2.ts +34 -0
  30. package/src/main/ts/armyc2/c5isr/JavaLineArray/CELineArray.ts +193 -0
  31. package/src/main/ts/armyc2/c5isr/JavaLineArray/Channels.ts +2971 -0
  32. package/src/main/ts/armyc2/c5isr/JavaLineArray/DISMSupport.ts +4008 -0
  33. package/src/main/ts/armyc2/c5isr/JavaLineArray/POINT2.ts +93 -0
  34. package/src/main/ts/armyc2/c5isr/JavaLineArray/Shape2.ts +89 -0
  35. package/src/main/ts/armyc2/c5isr/JavaLineArray/TacticalLines.ts +515 -0
  36. package/src/main/ts/armyc2/c5isr/JavaLineArray/arraysupport.ts +5403 -0
  37. package/src/main/ts/armyc2/c5isr/JavaLineArray/countsupport.ts +1084 -0
  38. package/src/main/ts/armyc2/c5isr/JavaLineArray/flot.ts +2173 -0
  39. package/src/main/ts/armyc2/c5isr/JavaLineArray/lineutility.ts +4934 -0
  40. package/src/main/ts/armyc2/c5isr/JavaLineArray/ref.ts +7 -0
  41. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/Modifier2.ts +5601 -0
  42. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/P1.ts +14 -0
  43. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/TGLight.ts +648 -0
  44. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/clsChannelUtility.ts +647 -0
  45. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/clsMETOC.ts +2994 -0
  46. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/clsUtility.ts +2663 -0
  47. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/mdlGeodesic.ts +669 -0
  48. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsClipPolygon2.ts +971 -0
  49. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsClipQuad.ts +871 -0
  50. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsRenderer.ts +3507 -0
  51. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsRenderer2.ts +500 -0
  52. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsUtility.ts +1089 -0
  53. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsUtilityCPOF.ts +2656 -0
  54. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsUtilityGE.ts +1419 -0
  55. package/src/main/ts/armyc2/c5isr/data/genc.json +1407 -0
  56. package/src/main/ts/armyc2/c5isr/data/msd.json +17311 -0
  57. package/src/main/ts/armyc2/c5isr/data/mse.json +18500 -0
  58. package/src/main/ts/armyc2/c5isr/data/svgd.json +31214 -0
  59. package/src/main/ts/armyc2/c5isr/data/svge.json +30558 -0
  60. package/src/main/ts/armyc2/c5isr/graphics2d/AffineTransform.ts +10 -0
  61. package/src/main/ts/armyc2/c5isr/graphics2d/Area.ts +437 -0
  62. package/src/main/ts/armyc2/c5isr/graphics2d/BasicStroke.ts +429 -0
  63. package/src/main/ts/armyc2/c5isr/graphics2d/BasicTypes.ts +7 -0
  64. package/src/main/ts/armyc2/c5isr/graphics2d/BufferedImage.ts +35 -0
  65. package/src/main/ts/armyc2/c5isr/graphics2d/Font.ts +111 -0
  66. package/src/main/ts/armyc2/c5isr/graphics2d/FontMetrics.ts +29 -0
  67. package/src/main/ts/armyc2/c5isr/graphics2d/FontRenderContext.ts +18 -0
  68. package/src/main/ts/armyc2/c5isr/graphics2d/GeneralPath.ts +211 -0
  69. package/src/main/ts/armyc2/c5isr/graphics2d/Graphics2D.ts +80 -0
  70. package/src/main/ts/armyc2/c5isr/graphics2d/IPathIterator.ts +33 -0
  71. package/src/main/ts/armyc2/c5isr/graphics2d/ImageIO.ts +16 -0
  72. package/src/main/ts/armyc2/c5isr/graphics2d/Line2D.ts +726 -0
  73. package/src/main/ts/armyc2/c5isr/graphics2d/PathIterator.ts +141 -0
  74. package/src/main/ts/armyc2/c5isr/graphics2d/Point.ts +112 -0
  75. package/src/main/ts/armyc2/c5isr/graphics2d/Point2D.ts +261 -0
  76. package/src/main/ts/armyc2/c5isr/graphics2d/Polygon.ts +391 -0
  77. package/src/main/ts/armyc2/c5isr/graphics2d/Rectangle.ts +567 -0
  78. package/src/main/ts/armyc2/c5isr/graphics2d/Rectangle2D.ts +445 -0
  79. package/src/main/ts/armyc2/c5isr/graphics2d/Shape.ts +31 -0
  80. package/src/main/ts/armyc2/c5isr/graphics2d/Stroke.ts +18 -0
  81. package/src/main/ts/armyc2/c5isr/graphics2d/TextLayout.ts +45 -0
  82. package/src/main/ts/armyc2/c5isr/graphics2d/TexturePaint.ts +25 -0
  83. package/src/main/ts/armyc2/c5isr/renderer/IIconRenderer.ts +15 -0
  84. package/src/main/ts/armyc2/c5isr/renderer/IconRenderer.ts +22 -0
  85. package/src/main/ts/armyc2/c5isr/renderer/MilStdIconRenderer.ts +269 -0
  86. package/src/main/ts/armyc2/c5isr/renderer/ModifierRenderer.ts +9882 -0
  87. package/src/main/ts/armyc2/c5isr/renderer/PatternFillRenderer.ts +146 -0
  88. package/src/main/ts/armyc2/c5isr/renderer/SinglePointSVGRenderer.ts +1265 -0
  89. package/src/main/ts/armyc2/c5isr/renderer/shapes/arc.ts +64 -0
  90. package/src/main/ts/armyc2/c5isr/renderer/shapes/bcurve.ts +95 -0
  91. package/src/main/ts/armyc2/c5isr/renderer/shapes/ellipse.ts +93 -0
  92. package/src/main/ts/armyc2/c5isr/renderer/shapes/line.ts +114 -0
  93. package/src/main/ts/armyc2/c5isr/renderer/shapes/path.ts +555 -0
  94. package/src/main/ts/armyc2/c5isr/renderer/shapes/pathiterator.ts +62 -0
  95. package/src/main/ts/armyc2/c5isr/renderer/shapes/point.ts +120 -0
  96. package/src/main/ts/armyc2/c5isr/renderer/shapes/rectangle.ts +431 -0
  97. package/src/main/ts/armyc2/c5isr/renderer/shapes/roundedrectangle.ts +99 -0
  98. package/src/main/ts/armyc2/c5isr/renderer/shapes/types.ts +25 -0
  99. package/src/main/ts/armyc2/c5isr/renderer/shapes/utilities.ts +203 -0
  100. package/src/main/ts/armyc2/c5isr/renderer/utilities/AffiliationColors.ts +104 -0
  101. package/src/main/ts/armyc2/c5isr/renderer/utilities/Color.ts +481 -0
  102. package/src/main/ts/armyc2/c5isr/renderer/utilities/DistanceUnit.ts +40 -0
  103. package/src/main/ts/armyc2/c5isr/renderer/utilities/DrawRules.ts +1323 -0
  104. package/src/main/ts/armyc2/c5isr/renderer/utilities/EntityCode.ts +51 -0
  105. package/src/main/ts/armyc2/c5isr/renderer/utilities/ErrorLogger.ts +736 -0
  106. package/src/main/ts/armyc2/c5isr/renderer/utilities/GENCLookup.ts +106 -0
  107. package/src/main/ts/armyc2/c5isr/renderer/utilities/GeoPixelConversion3D.ts +84 -0
  108. package/src/main/ts/armyc2/c5isr/renderer/utilities/IMultiPointRenderer.ts +87 -0
  109. package/src/main/ts/armyc2/c5isr/renderer/utilities/IPointConversion.ts +34 -0
  110. package/src/main/ts/armyc2/c5isr/renderer/utilities/ImageInfo.ts +324 -0
  111. package/src/main/ts/armyc2/c5isr/renderer/utilities/LRUCache.ts +127 -0
  112. package/src/main/ts/armyc2/c5isr/renderer/utilities/LRUEntry.ts +18 -0
  113. package/src/main/ts/armyc2/c5isr/renderer/utilities/LogLevel.ts +111 -0
  114. package/src/main/ts/armyc2/c5isr/renderer/utilities/MODrawRules.ts +219 -0
  115. package/src/main/ts/armyc2/c5isr/renderer/utilities/MSInfo.ts +1008 -0
  116. package/src/main/ts/armyc2/c5isr/renderer/utilities/MSLookup.ts +882 -0
  117. package/src/main/ts/armyc2/c5isr/renderer/utilities/MilStdAttributes.ts +380 -0
  118. package/src/main/ts/armyc2/c5isr/renderer/utilities/MilStdSymbol.ts +797 -0
  119. package/src/main/ts/armyc2/c5isr/renderer/utilities/Modifiers.ts +1699 -0
  120. package/src/main/ts/armyc2/c5isr/renderer/utilities/PointConversion.ts +178 -0
  121. package/src/main/ts/armyc2/c5isr/renderer/utilities/PointConversionDummy.ts +45 -0
  122. package/src/main/ts/armyc2/c5isr/renderer/utilities/PointConverter3D.ts +126 -0
  123. package/src/main/ts/armyc2/c5isr/renderer/utilities/RectUtilities.ts +118 -0
  124. package/src/main/ts/armyc2/c5isr/renderer/utilities/RendererException.ts +11 -0
  125. package/src/main/ts/armyc2/c5isr/renderer/utilities/RendererSettings.ts +1201 -0
  126. package/src/main/ts/armyc2/c5isr/renderer/utilities/RendererUtilities.ts +591 -0
  127. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGInfo.ts +29 -0
  128. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGLookup.ts +753 -0
  129. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGSymbolInfo.ts +137 -0
  130. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGTextInfo.ts +438 -0
  131. package/src/main/ts/armyc2/c5isr/renderer/utilities/SettingsChangedEvent.ts +19 -0
  132. package/src/main/ts/armyc2/c5isr/renderer/utilities/SettingsChangedEventListener.ts +10 -0
  133. package/src/main/ts/armyc2/c5isr/renderer/utilities/SettingsEventListener.ts +5 -0
  134. package/src/main/ts/armyc2/c5isr/renderer/utilities/Shape2SVG.ts +404 -0
  135. package/src/main/ts/armyc2/c5isr/renderer/utilities/ShapeInfo.ts +525 -0
  136. package/src/main/ts/armyc2/c5isr/renderer/utilities/ShapeUtilities.ts +55 -0
  137. package/src/main/ts/armyc2/c5isr/renderer/utilities/SymbolDimensionInfo.ts +36 -0
  138. package/src/main/ts/armyc2/c5isr/renderer/utilities/SymbolID.ts +1055 -0
  139. package/src/main/ts/armyc2/c5isr/renderer/utilities/SymbolUtilities.ts +2085 -0
  140. package/src/main/ts/armyc2/c5isr/renderer/utilities/TextInfo.ts +157 -0
  141. package/src/main/ts/armyc2/c5isr/web/render/GeoPixelConversion.ts +86 -0
  142. package/src/main/ts/armyc2/c5isr/web/render/MultiPointHandler.ts +3798 -0
  143. package/src/main/ts/armyc2/c5isr/web/render/MultiPointHandlerSVG.ts +412 -0
  144. package/src/main/ts/armyc2/c5isr/web/render/PointConverter.ts +124 -0
  145. package/src/main/ts/armyc2/c5isr/web/render/SymbolModifiers.ts +26 -0
  146. package/src/main/ts/armyc2/c5isr/web/render/WebRenderer.ts +677 -0
  147. package/src/main/ts/armyc2/c5isr/web/render/utilities/JavaRendererUtilities.ts +484 -0
  148. package/src/main/ts/armyc2/c5isr/web/render/utilities/LineInfo.ts +62 -0
  149. package/src/main/ts/armyc2/c5isr/web/render/utilities/SymbolInfo.ts +46 -0
  150. package/src/main/ts/armyc2/c5isr/web/render/utilities/TextInfo.ts +51 -0
  151. package/src/main/ts/org/gavaghan/geodesy/Angle.ts +31 -0
  152. package/src/main/ts/org/gavaghan/geodesy/Ellipsoid.ts +71 -0
  153. package/src/main/ts/org/gavaghan/geodesy/GeodeticCalculator.ts +200 -0
  154. package/src/main/ts/org/gavaghan/geodesy/GeodeticCurve.ts +55 -0
  155. package/src/main/ts/org/gavaghan/geodesy/GeodeticMeasurement.ts +68 -0
  156. package/src/main/ts/org/gavaghan/geodesy/GlobalCoordinates.ts +103 -0
  157. package/src/main/ts/org/gavaghan/geodesy/GlobalPosition.ts +90 -0
  158. package/test/ExportSPImages.js +692 -0
  159. package/test/MPWW.html +556 -0
  160. package/test/MPWorker.js +318 -0
  161. package/test/SPWorker.js +233 -0
  162. package/test/SVGWW.html +363 -0
  163. package/test/singlePointTester3.html +751 -0
  164. package/tsconfig.json +54 -0
  165. package/typedoc.json +30 -0
  166. package/updateVersion.js +21 -0
  167. package/webpack.config.js +34 -0
  168. package/webpackn.config.js +28 -0
  169. package/webpackr.config.js +47 -0
  170. package/webpackw.config.js +23 -0
@@ -0,0 +1,555 @@
1
+ import { PathIterator } from "./pathiterator";
2
+ import { Point } from "./point";
3
+ import { Rectangle } from "./rectangle";
4
+ import { ActionTypes, ShapeTypes } from "./types";
5
+
6
+ export class Path
7
+ {
8
+ private _actions:Array<Array<any>> = [];
9
+ private _dashArray:string|null = null;
10
+ private _startPoint:Point|null=null;
11
+ private _endPoint:Point|null=null;
12
+ private _lastMoveTo:Point|null = null;
13
+ private _rectangle:Rectangle|null = null;
14
+ private _method:String|null = null;//stroke,fill,fillPattern
15
+
16
+ /**
17
+ * @return {ShapeTypes} ShapeTypes.Path
18
+ */
19
+ getShapeType()
20
+ {
21
+ return ShapeTypes.PATH;
22
+ }
23
+
24
+ setLineDash(dashArray:string)
25
+ {
26
+ this._dashArray = dashArray;
27
+ }
28
+
29
+
30
+ getBounds():Rectangle
31
+ {
32
+ if(this._rectangle)
33
+ {
34
+ return new Rectangle(this._rectangle.getX(),
35
+ this._rectangle.getY(),
36
+ this._rectangle.getWidth(),
37
+ this._rectangle.getHeight());
38
+ }
39
+ else
40
+ {
41
+ return null;
42
+ }
43
+ };
44
+
45
+ shift(x:number,y:number)
46
+ {
47
+ var size = this._actions.length;
48
+ var temp = null;
49
+ this._rectangle.shift(x,y);
50
+
51
+ for(var i=0; i<size;i++)
52
+ {
53
+ temp = this._actions[i];
54
+ if(temp[0]===ActionTypes.ACTION_MOVE_TO)
55
+ {
56
+ temp[1] = temp[1] + x;
57
+ temp[2] = temp[2] + y;
58
+ }
59
+ else if(temp[0]===ActionTypes.ACTION_LINE_TO)
60
+ {
61
+ temp[1] = temp[1] + x;
62
+ temp[2] = temp[2] + y;
63
+ }
64
+ else if(temp[0]===ActionTypes.ACTION_CURVE_TO)
65
+ {
66
+ temp[1] = temp[1] + x;
67
+ temp[2] = temp[2] + y;
68
+ temp[3] = temp[3] + x;
69
+ temp[4] = temp[4] + y;
70
+ temp[5] = temp[5] + x;
71
+ temp[6] = temp[6] + y;
72
+ }
73
+ else if(temp[0]===ActionTypes.ACTION_QUAD_TO)
74
+ {
75
+ temp[1] = temp[1] + x;
76
+ temp[2] = temp[2] + y;
77
+ temp[3] = temp[3] + x;
78
+ temp[4] = temp[4] + y;
79
+ }
80
+ else if(temp[0]===ActionTypes.ACTION_ARC_TO)
81
+ {
82
+ temp[1] = temp[1] + x;
83
+ temp[2] = temp[2] + y;
84
+ temp[3] = temp[3] + x;
85
+ temp[4] = temp[4] + y;
86
+ }
87
+ else if(temp[0]===ActionTypes.ACTION_ARC)
88
+ {
89
+ temp[1] = temp[1] + x;
90
+ temp[2] = temp[2] + y;
91
+ }
92
+ }
93
+ this._startPoint.shift(x,y);
94
+ this._endPoint.shift(x,y);
95
+ this._lastMoveTo.shift(x,y);
96
+ }
97
+
98
+ /**
99
+ * The number of this._actions on the path
100
+ */
101
+ getLength()
102
+ {
103
+ this._actions.length;
104
+ };
105
+
106
+ /**
107
+ * Adds a point to the path by moving to the specified coordinates specified
108
+ * @param x
109
+ * @param y
110
+ */
111
+ moveTo(x:number,y:number)
112
+ {
113
+
114
+ if(this._actions.length === 0)
115
+ {
116
+ this._rectangle = new Rectangle(x,y,1,1);
117
+ this._startPoint = new Point(x,y);
118
+ this._endPoint = new Point(x,y);
119
+ //curr_startPoint = new armyc2.c2sd.renderer.Point(x,y);
120
+ //curr_endPoint = new armyc2.c2sd.renderer.Point(x,y);
121
+ }
122
+ this._rectangle.unionPoint(new Point(x,y));
123
+ this._actions.push([ActionTypes.ACTION_MOVE_TO,x,y]);
124
+ this._lastMoveTo = new Point(x,y);
125
+ this._endPoint = new Point(x,y);
126
+ };
127
+ /**
128
+ * Adds a point to the path by drawing a straight line from the current
129
+ * coordinates to the new specified coordinates specified
130
+ * @param x
131
+ * @param y
132
+ */
133
+ lineTo(x:number,y:number){
134
+
135
+ if(this._actions.length === 0)
136
+ {
137
+ this.moveTo(0,0);
138
+ }
139
+ this._actions.push([ActionTypes.ACTION_LINE_TO,x,y]);
140
+ this._rectangle.unionPoint(new Point(x,y));
141
+ this._endPoint = new Point(x,y);
142
+ };
143
+
144
+ /**
145
+ * Adds a point to the path by drawing a straight line from the current
146
+ * coordinates to the new specified coordinates specified
147
+ * @param x
148
+ * @param y
149
+ * @param pattern
150
+ */
151
+ dashedLineTo(x:number,y:number,pattern:Array<number>){
152
+
153
+ if(this._actions.length === 0)
154
+ {
155
+ this.moveTo(0,0);
156
+ }
157
+ var start = this.getCurrentPoint();
158
+ this._actions.push([ActionTypes.ACTION_DASHED_LINE_TO,start.getX(),start.getY(), x, y, pattern]);
159
+ this._rectangle.unionPoint(new Point(x,y));
160
+ this._endPoint = new Point(x,y);
161
+ };
162
+
163
+ /**
164
+ * Adds a curved segment, defined by three new points, to the path by
165
+ * drawing a Bézier curve that intersects both the current coordinates
166
+ * and the specified coordinates (x,y), using the specified points
167
+ * (cp1x,xp1y) and (cp2x,cp2y) as Bézier control points.
168
+ * @param cp1x
169
+ * @param cp1y
170
+ * @param cp2x
171
+ * @param cp2y
172
+ * @param x
173
+ * @param y
174
+ */
175
+ bezierCurveTo(cp1x:number, cp1y:number, cp2x:number, cp2y:number,x:number,y:number){
176
+
177
+ if(this._actions.length === 0)
178
+ {
179
+ this.moveTo(0,0);
180
+ }
181
+ this._actions.push([ActionTypes.ACTION_CURVE_TO,cp1x,cp1y,cp2x,cp2y,x,y]);
182
+ this._rectangle.unionPoint(new Point(cp1x,cp1y));
183
+ this._rectangle.unionPoint(new Point(cp2x,cp2y));
184
+ this._rectangle.unionPoint(new Point(x,y));
185
+ this._endPoint = new Point(x,y);
186
+ };
187
+ /**
188
+ * Adds a curved segment, defined by two new points, to the path by
189
+ * drawing a Quadratic curve that intersects both the current
190
+ * coordinates and the specified coordinates (x,y), using the
191
+ * specified point (cpx,cpy) as a quadratic parametric control point.
192
+ * @param cpx
193
+ * @param cpy
194
+ * @param x
195
+ * @param y
196
+ * @returns
197
+ */
198
+ quadraticCurveTo(cpx:number,cpy:number,x:number,y:number){
199
+
200
+ if(this._actions.length === 0)
201
+ {
202
+ this.moveTo(0,0);
203
+ }
204
+ this._actions.push([ActionTypes.ACTION_QUAD_TO,cpx,cpy,x,y]);
205
+ this._rectangle.unionPoint(new Point(cpx,cpy));
206
+ this._rectangle.unionPoint(new Point(x,y));
207
+ this._endPoint = new Point(x,y);
208
+ };
209
+ /**
210
+ * The arcTo() method creates an arc/curve between two tangents on the canvas.
211
+ * @param x1 The x-coordinate of the beginning of the arc
212
+ * @param y1 The y-coordinate of the beginning of the arc
213
+ * @param x2 The x-coordinate of the end of the arc
214
+ * @param y2 The y-coordinate of the end of the arc
215
+ * @param r The radius of the arc
216
+ * @returns
217
+ */
218
+ arcTo(x1:number,y1:number,x2:number,y2:number,r:number){
219
+
220
+ if(this._actions.length === 0)
221
+ {
222
+ this.moveTo(0,0);
223
+ }
224
+ this._actions.push([ActionTypes.ACTION_ARC_TO,x1,y1,x2,y2]);
225
+ this._rectangle.unionPoint(new Point(x1,y1));
226
+ this._rectangle.unionPoint(new Point(x2,y2));
227
+ this._endPoint = new Point(x2,y2);
228
+ };
229
+ /**
230
+ * The arc() method creates an arc/curve
231
+ * (use to create circles. or parts of circles).
232
+ * @param x The x-coordinate of the center of the circle
233
+ * @param y The y-coordinate of the center of the circle
234
+ * @param r The radius of the circle
235
+ * @param sAngle The starting angle, in degrees
236
+ * (0 is at the 3 -'clock position of the arc's circle)
237
+ * @param eAngle The ending angle, in degrees
238
+ * @param counterclockwise Optional. Specifies wheter the drawing
239
+ * should be counterclockwise or clockwise. False=clockwise,
240
+ * true=counter-clockwise;
241
+ * @returns
242
+ */
243
+ arc(x:number,y:number,r:number,sAngle:number,eAngle:number,counterclockwise:boolean){
244
+
245
+
246
+
247
+ if(counterclockwise !== true)
248
+ {
249
+ counterclockwise = false;
250
+ }
251
+
252
+ //degrees to radians
253
+ var sa = sAngle * (Math.PI / 180),
254
+ ea = eAngle * (Math.PI / 180);
255
+
256
+
257
+ if(this._startPoint===null)
258
+ {
259
+ var sX = r * Math.cos(sa) + x;
260
+ var sY = r * Math.sin(sa) + y;
261
+ this._startPoint = new Point(sX,sY);
262
+ this._rectangle = new Rectangle(sX,sY,1,1);
263
+ }
264
+
265
+
266
+ this._actions.push([ActionTypes.ACTION_ARC,x,y,r,sa,ea,counterclockwise]);
267
+ this._rectangle.union(new Rectangle(x-r,y-r,r*2,r*2));
268
+
269
+ var newX = r * Math.cos(ea) + x;
270
+ var newY = r * Math.sin(ea) + y;
271
+ this._endPoint = new Point(newX,newY);
272
+ this.moveTo(newX,newY);
273
+
274
+ };
275
+ /**
276
+ * Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo.
277
+ * @return
278
+ */
279
+ closePath(){
280
+ this.lineTo(this._lastMoveTo.getX(),this._lastMoveTo.getY());
281
+ this._endPoint = this._lastMoveTo.clone();
282
+ };
283
+ /**
284
+ * @return Point
285
+ */
286
+ getCurrentPoint()
287
+ {
288
+ return this._endPoint.clone();
289
+ };
290
+ /**
291
+ * @return PathIterator
292
+ */
293
+ getPathIterator()
294
+ {
295
+ return new PathIterator(this._actions);
296
+ };
297
+ /**
298
+ * Apply the path to the passed context (doesn't draw)
299
+ * @param context
300
+ * @return
301
+ */
302
+ private setPath(context:OffscreenCanvasRenderingContext2D | any){
303
+
304
+ //context.beginPath();
305
+ var size = this._actions.length;
306
+ var temp = null;
307
+
308
+ for(var i=0; i<size;i++)
309
+ {
310
+ temp = this._actions[i];
311
+
312
+
313
+ if(temp[0]===ActionTypes.ACTION_MOVE_TO)
314
+ {
315
+ //context.moveTo(temp[1],temp[2]);
316
+
317
+ if(i === 0 || this._method !== "fillPattern")
318
+ {
319
+ context.moveTo(temp[1],temp[2]);
320
+ }
321
+ else//no moves in a fill shape except maybe for the first one
322
+ {
323
+ context.lineTo(temp[1],temp[2]);
324
+ }//*/
325
+ }
326
+ else if(temp[0]===ActionTypes.ACTION_LINE_TO)
327
+ {
328
+ context.lineTo(temp[1],temp[2]);
329
+ }
330
+ else if(temp[0]===ActionTypes.ACTION_DASHED_LINE_TO)
331
+ {
332
+ if(this._method === "stroke")
333
+ {
334
+ context.lineTo(temp[3],temp[4]);
335
+
336
+ //function prototype exists in shape utilities class but there doesn't seem to be a need
337
+ //since setLineDash exists.
338
+ //context.dashedLineTo(temp[1],temp[2],temp[3],temp[4],temp[5]);
339
+ }
340
+ else //you don't dash a fill shape
341
+ {
342
+ context.lineTo(temp[3],temp[4]);
343
+ }
344
+ }
345
+ else if(temp[0]===ActionTypes.ACTION_CURVE_TO)
346
+ {
347
+ context.bezierCurveTo(temp[1],temp[2],temp[3],temp[4],temp[5],temp[6]);
348
+ }
349
+ else if(temp[0]===ActionTypes.ACTION_QUAD_TO)
350
+ {
351
+ context.quadraticCurveTo(temp[1],temp[2],temp[3],temp[4]);
352
+ }
353
+ else if(temp[0]===ActionTypes.ACTION_ARC_TO)
354
+ {
355
+ context.arcTo(temp[1],temp[2],temp[3],temp[4],temp[5]);
356
+ }
357
+ else if(temp[0]===ActionTypes.ACTION_ARC)
358
+ {
359
+ context.arc(temp[1],temp[2],temp[3],temp[4],temp[5],temp[6]);
360
+ }//*/
361
+ }
362
+
363
+ };
364
+ /**
365
+ * Draws the path to the passed context
366
+ * @param context
367
+ * @return
368
+ */
369
+ stroke(context:OffscreenCanvasRenderingContext2D){
370
+ this._method = "stroke";
371
+ if(this._dashArray)
372
+ {
373
+ let temp:Array<string> = this._dashArray.split(" ");
374
+ let temp2:Array<number> = new Array();
375
+
376
+ for(let i:number = 0; i < temp.length; i++)
377
+ {
378
+ temp2[i] = parseInt(temp[i]);
379
+ }
380
+
381
+ context.setLineDash(temp2);
382
+ }
383
+ context.beginPath();
384
+ this.setPath(context);
385
+ context.stroke();
386
+ context.setLineDash([]);
387
+ };
388
+ /**
389
+ * Fills the path on the passed context
390
+ * @param context
391
+ * @return
392
+ */
393
+ fill(context:OffscreenCanvasRenderingContext2D){
394
+ this._method = "fill";
395
+ context.beginPath();
396
+ this.setPath(context);
397
+ context.fill();
398
+ };
399
+
400
+ fillPattern(context:OffscreenCanvasRenderingContext2D,fillPattern:CanvasImageSource){
401
+ this._method = "fillPattern";
402
+ context.beginPath();
403
+ this.setPath(context);
404
+ let pattern:CanvasPattern = context.createPattern(fillPattern, "repeat");
405
+ context.fillStyle = pattern;
406
+ context.fill();
407
+ };
408
+
409
+ /**
410
+ * Arc and ArcTo do not covert currently
411
+ */
412
+ toSVGElement(stroke:string | null, strokeWidth:number, fill:string | null, strokeOpacity:number=1, fillOpacity:number=1, lineCap: string | null = null, svgFormat:number=0)
413
+ {
414
+ var format = 1;
415
+ if(svgFormat)
416
+ {
417
+ format = svgFormat;
418
+ }
419
+
420
+ //context.beginPath();
421
+ var size = this._actions.length;
422
+ var temp = null;
423
+ var path = "";
424
+
425
+ for(var i=0; i<size;i++)
426
+ {
427
+ temp = this._actions[i];
428
+
429
+ /*if(path !== "")
430
+ path += " ";*/
431
+
432
+ if(temp[0]===ActionTypes.ACTION_LINE_TO)
433
+ {
434
+ path += "L" + temp[1] + " " + temp[2];
435
+ //context.lineTo(temp[1],temp[2]);
436
+ }
437
+ else if(temp[0]===ActionTypes.ACTION_MOVE_TO)
438
+ {
439
+ //context.moveTo(temp[1],temp[2]);
440
+
441
+ if(i === 0 || this._method !== "fillPattern")
442
+ {
443
+ path += "M" + temp[1] + " " + temp[2];
444
+ //context.moveTo(temp[1],temp[2]);
445
+ }
446
+ else//no moves in a fill shape except maybe for the first one
447
+ {
448
+ path += "L" + temp[1] + " " + temp[2];
449
+ //context.lineTo(temp[1],temp[2]);
450
+ }//*/
451
+ }
452
+ else if(temp[0]===ActionTypes.ACTION_DASHED_LINE_TO)
453
+ {
454
+ path += "L" + temp[3] + " " + temp[4];
455
+ /*if(this._method === "stroke")
456
+ {
457
+ context.dashedLineTo(temp[1],temp[2],temp[3],temp[4],temp[5]);
458
+ }
459
+ else //you don't dash a fill shape
460
+ {
461
+ context.lineTo(temp[3],temp[4]);
462
+ }//*/
463
+ }
464
+ else if(temp[0]===ActionTypes.ACTION_CURVE_TO)
465
+ {
466
+ //C100 100 250 100 250 200
467
+ path += "C" + temp[1] + " " + temp[2] + " " + temp[3] + " " + temp[4] + " " + temp[5] + " " + temp[6];
468
+ //context.bezierCurveTo(temp[1],temp[2],temp[3],temp[4],temp[5],temp[6]);
469
+ }
470
+ else if(temp[0]===ActionTypes.ACTION_QUAD_TO)
471
+ {
472
+ path += "Q" + temp[1] + " " + temp[2] + " " + temp[3] + " " + temp[4];
473
+ //context.quadraticCurveTo(temp[1],temp[2],temp[3],temp[4]);
474
+ }
475
+ else if(temp[0]===ActionTypes.ACTION_ARC_TO)
476
+ {
477
+ //path += "C" + temp[1] + " " + temp[2] + " " + temp[3] + " " + temp[4] + " " + temp[5];
478
+ //context.arcTo(temp[1],temp[2],temp[3],temp[4],temp[5]);
479
+ }
480
+ else if(temp[0]===ActionTypes.ACTION_ARC)
481
+ {
482
+ //context.arc(temp[1],temp[2],temp[3],temp[4],temp[5],temp[6]);
483
+ }//*/
484
+ }
485
+ //TODO: generate path svg element
486
+ var line = '<path d="' + path + '"';
487
+
488
+ if(stroke)
489
+ {
490
+ //line += ' stroke="' + stroke + '"';
491
+ if(format === 2)
492
+ line += ' stroke="' + stroke.replace(/#/g,"%23") + '"';//.replace(/#/g,"%23")
493
+ else
494
+ line += ' stroke="' + stroke + '"';
495
+ /*else
496
+ line += ' stroke="' + stroke.replace(/#/g,"&#35;") + '"';*/
497
+
498
+ if(strokeWidth)
499
+ line += ' stroke-width="' + strokeWidth + '"';
500
+ else
501
+ line += ' stroke-width="2"';
502
+
503
+ if(strokeOpacity !== 1.0)
504
+ {
505
+ //stroke-opacity="0.4"
506
+ line += ' stroke-opacity="' + strokeOpacity + '"';
507
+ }
508
+
509
+ if(lineCap != null &&
510
+ (lineCap.toLowerCase()==="butt" ||
511
+ lineCap.toLowerCase()==="round" ||
512
+ lineCap.toLowerCase()==="square"))
513
+ {
514
+ line += ' stroke-linecap="' + lineCap + '"';
515
+ }
516
+ else
517
+ line += ' stroke-linecap="round"';
518
+ }
519
+
520
+ if(this._dashArray != null)
521
+ line += ' stroke-dasharray="' + this._dashArray + '"';
522
+
523
+ if(fill)
524
+ {
525
+ if(fill.indexOf("url") === 0)
526
+ {
527
+ line += ' fill="url(#fillPattern)"';
528
+ //line += ' fill="url(&#35;fillPattern)"';
529
+ }
530
+ else
531
+ {
532
+ //line += ' fill="' + fill + '"';
533
+ if(format === 2)
534
+ line += ' fill="' + fill.replace(/#/g,"%23") + '"';//text = text.replace(/\</g,"&gt;");
535
+ else
536
+ line += ' fill="' + fill + '"';//text = text.replace(/\</g,"&gt;");
537
+ /*else
538
+ line += ' fill="' + fill.replace(/#/g,"&#35;") + '"';//text = text.replace(/\</g,"&gt;");*/
539
+
540
+ if(fillOpacity !== 1.0)
541
+ {
542
+ //fill-opacity="0.4"
543
+ line += ' fill-opacity="' + fillOpacity + '"';
544
+ }
545
+ }
546
+
547
+ }
548
+ else
549
+ line += ' fill="none"';
550
+
551
+ line += ' />';
552
+ return line;
553
+
554
+ }
555
+ }
@@ -0,0 +1,62 @@
1
+ export class PathIterator
2
+ {
3
+
4
+ //private vars
5
+ private arrActions:Array<Array<any>> = [];
6
+ private size:number = 0;
7
+ private index:number = 0;
8
+
9
+ constructor(actions:Array<any>)
10
+ {
11
+ this.arrActions = actions;
12
+ this.size = actions.length;
13
+ }
14
+ //constructor code
15
+
16
+
17
+ //private functions
18
+
19
+ //public vars/functions
20
+ /**
21
+ * Tests if the iteration is complete.
22
+ *
23
+ */
24
+ isDone(): boolean
25
+ {
26
+ if(this.index === this.size)
27
+ return true;
28
+ return false;
29
+ };
30
+ /**
31
+ * Moves the iterator to the next segment of the path forwards
32
+ * along the primary direction of traversal as long as there are
33
+ * more points in that direction.
34
+ */
35
+ next()
36
+ {
37
+ this.index++;
38
+ };
39
+ /**
40
+ * Returns the coordinates and type of the current path segment in
41
+ * the iteration.
42
+ * The return value is the path-segment type:
43
+ * MOVE_TO, LINE_TO, QUAD_TO, CURVE_TO, or CLOSE.
44
+ * A float array of length 6 must be passed in and can be used to
45
+ * store the coordinates of the point(s).
46
+ * Each point is stored as a pair of float x,y coordinates.
47
+ * MOVE_TO and LINE_TO types returns one point,
48
+ * QUAD_TO returns two points,
49
+ * CURVE_TO returns 3 points.
50
+ * ARC_TO
51
+ * ARC
52
+ * CLOSE will never get returned as it is replace with LINE_TO.
53
+ * @return the path-segment where the first index is the segment type.
54
+ * @see ActionTypes
55
+ */
56
+ currentSegment()
57
+ {
58
+ return this.arrActions[this.index];
59
+ }
60
+
61
+
62
+ }