@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,669 @@
1
+ import { type double, type int } from "../graphics2d/BasicTypes";
2
+
3
+ import { Rectangle2D } from "../graphics2d/Rectangle2D"
4
+ import { POINT2 } from "../JavaLineArray/POINT2"
5
+ import { ref } from "../JavaLineArray/ref"
6
+ import { ErrorLogger } from "../renderer/utilities/ErrorLogger"
7
+ import { RendererException } from "../renderer/utilities/RendererException"
8
+
9
+ /**
10
+ * Class to calculate the geodesic based shapes for the Fire Support Areas
11
+ *
12
+ */
13
+ export class mdlGeodesic {
14
+ private static readonly _className: string = "mdlGeodesic";
15
+ private static readonly sm_a: double = 6378137;
16
+
17
+ private static DegToRad(deg: double): double {
18
+ return deg / 180.0 * Math.PI;
19
+ }
20
+
21
+ private static RadToDeg(rad: double): double {
22
+ return rad / Math.PI * 180.0;
23
+ }
24
+ /**
25
+ * Returns the azimuth from true north between two points
26
+ * @param c1
27
+ * @param c2
28
+ * @return the azimuth from c1 to c2
29
+ */
30
+ public static GetAzimuth(c1: POINT2,
31
+ c2: POINT2): double {//was private
32
+ let theta: double = 0;
33
+ try {
34
+ let lat1: double = mdlGeodesic.DegToRad(c1.y);
35
+ let lon1: double = mdlGeodesic.DegToRad(c1.x);
36
+ let lat2: double = mdlGeodesic.DegToRad(c2.y);
37
+ let lon2: double = mdlGeodesic.DegToRad(c2.x);
38
+ //formula
39
+ //θ = atan2( sin(Δlong).cos(lat2),
40
+ //cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )
41
+ //var theta:Number = Math.atan2( Math.sin(lon2-lon1)*Math.cos(lat2),
42
+ //Math.cos(lat1)*Math.sin(lat2) − Math.sin(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1) );
43
+ let y: double = Math.sin(lon2 - lon1);
44
+ y *= Math.cos(lat2);
45
+ let x: double = Math.cos(lat1);
46
+ x *= Math.sin(lat2);
47
+ let z: double = Math.sin(lat1);
48
+ z *= Math.cos(lat2);
49
+ z *= Math.cos(lon2 - lon1);
50
+ x = x - z;
51
+ theta = Math.atan2(y, x);
52
+ theta = mdlGeodesic.RadToDeg(theta);
53
+ } catch (exc) {
54
+ if (exc instanceof Error) {
55
+ //console.log(e.message);
56
+ //clsUtility.WriteFile("Error in mdlGeodesic.GetAzimuth");
57
+ ErrorLogger.LogException(mdlGeodesic._className, "GetAzimuth",
58
+ new RendererException("Failed inside GetAzimuth", exc));
59
+ } else {
60
+ throw exc;
61
+ }
62
+ }
63
+ return theta;//RadToDeg(k);
64
+ }
65
+ /**
66
+ * Calculates the distance in meters between two geodesic points.
67
+ * Also calculates the azimuth from c1 to c2 and from c2 to c1.
68
+ *
69
+ * @param c1 the first point
70
+ * @param c2 the last point
71
+ * @param a12 OUT - an object with a member to hold the calculated azimuth in degrees from c1 to c2
72
+ * @param a21 OUT - an object with a member to hold the calculated azimuth in degrees from c2 to c1
73
+ * @return the distance in meters between c1 and c2
74
+ */
75
+ public static geodesic_distance(c1: POINT2,
76
+ c2: POINT2,
77
+ a12: ref<number[]> | null,
78
+ a21: ref<number[]> | null): double {
79
+ let h: double = 0;
80
+ try {
81
+ //formula
82
+ //R = earth’s radius (mean radius = 6,371km)
83
+ //Δlat = lat2− lat1
84
+ //Δlong = long2− long1
85
+ //a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
86
+ //c = 2.atan2(√a, √(1−a))
87
+ //d = R.c
88
+ if (a12 != null && a21 != null) {
89
+ a12.value = new Array<number>(1);
90
+ a21.value = new Array<number>(1);
91
+ //set the azimuth
92
+ a12.value[0] = mdlGeodesic.GetAzimuth(c1, c2);
93
+ a21.value[0] = mdlGeodesic.GetAzimuth(c2, c1);
94
+ }
95
+ //c1.x+=360;
96
+ let dLat: double = mdlGeodesic.DegToRad(c2.y - c1.y);
97
+ let dLon: double = mdlGeodesic.DegToRad(c2.x - c1.x);
98
+
99
+ let b: double = 0;
100
+ let lat1: double = 0;
101
+ let lat2: double = 0;
102
+ let e: double = 0;
103
+ let f: double = 0;
104
+ let g: double = 0;
105
+ let k: double = 0;
106
+ b = Math.sin(dLat / 2);
107
+ lat1 = mdlGeodesic.DegToRad(c1.y);
108
+ lat2 = mdlGeodesic.DegToRad(c2.y);
109
+ e = Math.sin(dLon / 2);
110
+ f = Math.cos(lat1);
111
+ g = Math.cos(lat2);
112
+ //uncomment this to test calculation
113
+ //var a:Number = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(DegToRad(c1.y)) * Math.cos(DegToRad(c2.y)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
114
+ let a: double = b * b + f * g * e * e;
115
+ h = Math.sqrt(a);
116
+ k = Math.sqrt(1 - a);
117
+ h = 2 * Math.atan2(h, k);
118
+ } catch (exc) {
119
+ if (exc instanceof Error) {
120
+ //console.log(e.message);
121
+ //clsUtility.WriteFile("Error in mdlGeodesic.geodesic_distance");
122
+ ErrorLogger.LogException(mdlGeodesic._className, "geodesic_distance",
123
+ new RendererException("Failed inside geodesic_distance", exc));
124
+ } else {
125
+ throw exc;
126
+ }
127
+ }
128
+ return mdlGeodesic.sm_a * h;
129
+ }
130
+ /**
131
+ * Calculates a geodesic point and given distance and azimuth from the srating geodesic point
132
+ *
133
+ * @param start the starting point
134
+ * @param distance the distance in meters
135
+ * @param azimuth the azimuth or bearing in degrees
136
+ *
137
+ * @return the calculated point
138
+ */
139
+ public static geodesic_coordinate(start: POINT2,
140
+ distance: double,
141
+ azimuth: double): POINT2 {
142
+ let pt: POINT2;
143
+ try {
144
+ //formula
145
+ //lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))
146
+ //lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))
147
+
148
+ let a: double = 0;
149
+ let b: double = 0;
150
+ let c: double = 0;
151
+ let d: double = 0;
152
+ let e: double = 0;
153
+ let f: double = 0;
154
+ let g: double = 0;
155
+ let h: double = 0;
156
+ let
157
+ j: double = 0;
158
+ let k: double = 0;
159
+ let l: double = 0;
160
+ let m: double = 0;
161
+ let n: double = 0;
162
+ let p: double = 0;
163
+ let q: double = 0;
164
+
165
+ a = mdlGeodesic.DegToRad(start.y);
166
+ b = Math.cos(a);
167
+ c = mdlGeodesic.DegToRad(azimuth);
168
+ d = Math.sin(a);
169
+ e = Math.cos(distance / mdlGeodesic.sm_a);
170
+ f = Math.sin(distance / mdlGeodesic.sm_a);
171
+ g = Math.cos(c);
172
+ //uncomment to test calculation
173
+ //var lat2:Number = RadToDeg(Math.asin(Math.sin(DegToRad(start.y)) * Math.cos(DegToRad(distance / sm_a)) + Math.cos(DegToRad(start.y)) * Math.sin(DegToRad(distance / sm_a)) * Math.cos(DegToRad(azimuth))));
174
+ //lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))
175
+ //var lat2:Number = RadToDeg(Math.asin(Math.sin(DegToRad(start.y)) * Math.cos(distance / sm_a) + Math.cos(DegToRad(start.y)) * Math.sin(distance / sm_a) * Math.cos(DegToRad(azimuth))));
176
+ //double lat2 = RadToDeg(Math.asin(Math.sin(DegToRad(start.y)) * Math.cos(distance / sm_a) + Math.cos(DegToRad(start.y)) * Math.sin(distance / sm_a) * Math.cos(DegToRad(azimuth))));
177
+ let lat: double = mdlGeodesic.RadToDeg(Math.asin(d * e + b * f * g));
178
+ h = Math.sin(c);
179
+ k = Math.sin(h);
180
+ l = Math.cos(a);
181
+ m = mdlGeodesic.DegToRad(lat);
182
+ n = Math.sin(m);
183
+ p = Math.atan2(h * f * b, e - d * n);
184
+ //uncomment to test calculation
185
+ //var lon2:Number = start.x + DegToRad(Math.atan2(Math.sin(DegToRad(azimuth)) * Math.sin(DegToRad(distance / sm_a)) * Math.cos(DegToRad(start.y)), Math.cos(DegToRad(distance / sm_a)) - Math.sin(DegToRad(start.y)) * Math.sin(DegToRad(lat))));
186
+ //lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))
187
+ //var lon2:Number = start.x + RadToDeg(Math.atan2(Math.sin(DegToRad(azimuth)) * Math.sin(distance / sm_a) * Math.cos(DegToRad(start.y)), Math.cos(distance / sm_a) - Math.sin(DegToRad(start.y)) * Math.sin(DegToRad(lat2))));
188
+ let lon: double = start.x + mdlGeodesic.RadToDeg(p);
189
+ pt = new POINT2(lon, lat);
190
+ } catch (exc) {
191
+ if (exc instanceof Error) {
192
+ //clsUtility.WriteFile("Error in mdlGeodesic.geodesic_distance");
193
+ ErrorLogger.LogException(mdlGeodesic._className, "geodesic_coordinate",
194
+ new RendererException("Failed inside geodesic_coordinate", exc));
195
+ } else {
196
+ throw exc;
197
+ }
198
+ }
199
+ return pt;
200
+ }
201
+ /**
202
+ * Calculates an arc from geodesic point and uses them for the change 1 circular symbols
203
+ *
204
+ * @param pPoints array of 3 points, currently the last 2 points are the same. The first point
205
+ * is the center and the next point defines the radius.
206
+ *
207
+ * @return points for the geodesic circle
208
+ */
209
+ public static GetGeodesicArc(pPoints: POINT2[]): Array<POINT2> | null {
210
+ let pPoints2: Array<POINT2> = new Array();
211
+ try {
212
+ if (pPoints == null) {
213
+ return null;
214
+ }
215
+ if (pPoints.length < 3) {
216
+ return null;
217
+ }
218
+
219
+ let ptCenter: POINT2 = new POINT2(pPoints[0]);
220
+ let pt1: POINT2 = new POINT2(pPoints[1]);
221
+ let pt2: POINT2 = new POINT2(pPoints[2]);
222
+ let ptTemp: POINT2;
223
+ let a12b: ref<number[]> = new ref();
224
+ let dist2: double = 0.0;
225
+ let dist1: double = 0.0;
226
+ let a12: ref<number[]> = new ref();
227
+ let a21: ref<number[]> = new ref();
228
+ //distance and azimuth from the center to the 1st point
229
+ dist1 = mdlGeodesic.geodesic_distance(ptCenter, pt1, a12, a21);
230
+ let saveAzimuth: double = a21.value[0];
231
+ //distance and azimuth from the center to the 2nd point
232
+ dist2 = mdlGeodesic.geodesic_distance(ptCenter, pt2, a12b, a21);
233
+ //if the points are nearly the same we want 360 degree range fan
234
+ if (Math.abs(a21.value[0] - saveAzimuth) <= 1) {
235
+ if (a12.value[0] < 360) {
236
+ a12.value[0] += 360;
237
+ }
238
+
239
+ a12b.value[0] = a12.value[0] + 360;
240
+ }
241
+
242
+ let a12c: ref<number[]> = new ref();
243
+ let j: int = 0;
244
+ if (a12b.value[0] < 0) {
245
+ a12b.value[0] = 360 + a12b.value[0];
246
+ }
247
+ if (a12.value[0] < 0) {
248
+ a12.value[0] = 360 + a12.value[0];
249
+ }
250
+ if (a12b.value[0] < a12.value[0]) {
251
+ a12b.value[0] = a12b.value[0] + 360;
252
+ }
253
+ a12c.value = new Array<number>(1);
254
+ for (j = 0; j <= 100; j++) {
255
+
256
+ a12c.value[0] = a12.value[0] + (j as double / 100.0) * (a12b.value[0] - a12.value[0]);
257
+ ptTemp = mdlGeodesic.geodesic_coordinate(ptCenter, dist1, a12c.value[0]);
258
+ pPoints2.push(ptTemp);
259
+ }
260
+
261
+ //if the points are nearly the same we want 360 degree range fan
262
+ //with no line from the center
263
+ if (Math.abs(a21.value[0] - saveAzimuth) > 1) {
264
+ pPoints2.push(ptCenter);
265
+ }
266
+
267
+ if (a12.value[0] < a12b.value[0]) {
268
+ pPoints2.push(pt1);
269
+ } else {
270
+ pPoints2.push(pt2);
271
+ }
272
+ } catch (exc) {
273
+ if (exc instanceof Error) {
274
+ //clsUtility.WriteFile("Error in mdlGeodesic.GetGeodesicArc");
275
+ ErrorLogger.LogException(mdlGeodesic._className, "GetGeodesicArc",
276
+ new RendererException("Failed inside GetGeodesicArc", exc));
277
+ } else {
278
+ throw exc;
279
+ }
280
+ }
281
+ return pPoints2;
282
+ }
283
+ /**
284
+ * Calculates the sector points for a sector range fan.
285
+ *
286
+ * @param pPoints array of 3 points. The first point
287
+ * is the center and the next two points define either side of the sector
288
+ * @param pPoints2 OUT - the calculated geodesic sector points
289
+ *
290
+ * @return true if the sector is a circle
291
+ */
292
+ public static GetGeodesicArc2(pPoints: Array<POINT2>,
293
+ pPoints2: Array<POINT2>): boolean {
294
+ let circle: boolean = false;
295
+ try {
296
+ let ptCenter: POINT2 = new POINT2(pPoints[0]);
297
+ let pt1: POINT2 = new POINT2(pPoints[1]);
298
+ let pt2: POINT2 = new POINT2(pPoints[2]);
299
+
300
+ let a12b: ref<number[]> = new ref();
301
+ //double dist2 = 0d;
302
+ let dist1: double = 0;
303
+ let a12: ref<number[]> = new ref();
304
+ let a21: ref<number[]> = new ref();
305
+ //double lat2c = 0.0;
306
+ //distance and azimuth from the center to the 1st point
307
+ //geodesic_distance(lonCenter, latCenter, lon1, lat1, ref dist1, ref a12, ref a21);
308
+ dist1 = mdlGeodesic.geodesic_distance(ptCenter, pt1, a12, a21);
309
+ let saveAzimuth: double = a21.value[0];
310
+ //distance and azimuth from the center to the 2nd point
311
+ //geodesic_distance(lonCenter, latCenter, lon2, lat2, ref dist2, ref a12b, ref a21);
312
+ let dist2: double = mdlGeodesic.geodesic_distance(ptCenter, pt2, a12b, a21);
313
+ //if the points are nearly the same we want 360 degree range fan
314
+ if (Math.abs(a21.value[0] - saveAzimuth) <= 1) {
315
+ if (a12.value[0] < 360) {
316
+ a12.value[0] += 360;
317
+ }
318
+ a12b.value[0] = a12.value[0] + 360;
319
+ circle = true;
320
+ }
321
+
322
+ //assume caller has set pPoints2 as new Array
323
+
324
+ let a12c: ref<number[]> = new ref();
325
+ a12c.value = new Array<number>(1);
326
+ let j: int = 0;
327
+ let pPoint: POINT2 = new POINT2();
328
+ if (a12b.value[0] < 0) {
329
+ a12b.value[0] = 360 + a12b.value[0];
330
+ }
331
+ if (a12.value[0] < 0) {
332
+ a12.value[0] = 360 + a12.value[0];
333
+ }
334
+ if (a12b.value[0] < a12.value[0]) {
335
+ a12b.value[0] = a12b.value[0] + 360;
336
+ }
337
+ for (j = 0; j <= 100; j++) {
338
+
339
+ a12c.value[0] = a12.value[0] + (j as double / 100) * (a12b.value[0] - a12.value[0]);
340
+ pPoint = mdlGeodesic.geodesic_coordinate(ptCenter, dist1, a12c.value[0]);
341
+ pPoints2.push(pPoint);
342
+ }
343
+ } catch (exc) {
344
+ if (exc instanceof Error) {
345
+ //console.log(e.message);
346
+ //clsUtility.WriteFile("Error in mdlGeodesic.GetGeodesicArc2");
347
+ ErrorLogger.LogException(mdlGeodesic._className, "GetGeodesicArc2",
348
+ new RendererException("Failed inside GetGeodesicArc2", exc));
349
+ } else {
350
+ throw exc;
351
+ }
352
+ }
353
+ return circle;
354
+ }
355
+ /**
356
+ * returns intersection of two lines, each defined by a point and a bearing
357
+ * <a href="http://creativecommons.org/licenses/by/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/88x31.png"></a><br>This work is licensed under a <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.
358
+ * @param p1 1st point
359
+ * @param brng1 first line bearing in degrees from true north
360
+ * @param p2 2nd point
361
+ * @param brng2 2nd point bearing in degrees from true north
362
+ * @return
363
+ * @deprecated
364
+ */
365
+ public static IntersectLines(p1: POINT2,
366
+ brng1: double,
367
+ p2: POINT2,
368
+ brng2: double): POINT2 | null {
369
+ let ptResult: POINT2;
370
+ try {
371
+ let lat1: double = mdlGeodesic.DegToRad(p1.y);//p1._lat.toRad();
372
+ let lon1: double = mdlGeodesic.DegToRad(p1.x);//p1._lon.toRad();
373
+ let lat2: double = mdlGeodesic.DegToRad(p2.y);//p2._lat.toRad();
374
+ let lon2: double = mdlGeodesic.DegToRad(p2.x);//p2._lon.toRad();
375
+ let brng13: double = mdlGeodesic.DegToRad(brng1);//brng1.toRad();
376
+ let brng23: double = mdlGeodesic.DegToRad(brng2);//brng2.toRad();
377
+ let dLat: double = lat2 - lat1;
378
+ let dLon: double = lon2 - lon1;
379
+
380
+
381
+ let dist12: double = 2 * Math.asin(Math.sqrt(Math.sin(dLat / 2) * Math.sin(dLat / 2) +
382
+ Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2)));
383
+
384
+ if (dist12 === 0) {
385
+ return null;
386
+ }
387
+
388
+ let brngA: double = Math.acos((Math.sin(lat2) - Math.sin(lat1) * Math.cos(dist12)) /
389
+ (Math.sin(dist12) * Math.cos(lat1)));
390
+
391
+ if (Number.isNaN(brngA)) {
392
+ brngA = 0; // protect against rounding
393
+ }
394
+ let brngB: double = Math.acos((Math.sin(lat1) - Math.sin(lat2) * Math.cos(dist12)) /
395
+ (Math.sin(dist12) * Math.cos(lat2)));
396
+
397
+ let brng12: double = 0;
398
+ let brng21: double = 0;
399
+ if (Math.sin(lon2 - lon1) > 0) {
400
+ brng12 = brngA;
401
+ brng21 = 2 * Math.PI - brngB;
402
+ } else {
403
+ brng12 = 2 * Math.PI - brngA;
404
+ brng21 = brngB;
405
+ }
406
+
407
+ let alpha1: double = (brng13 - brng12 + Math.PI) % (2 * Math.PI) - Math.PI; // angle 2-1-3
408
+ let alpha2: double = (brng21 - brng23 + Math.PI) % (2 * Math.PI) - Math.PI; // angle 1-2-3
409
+
410
+ if (Math.sin(alpha1) === 0 && Math.sin(alpha2) === 0) {
411
+ return null; // infinite intersections
412
+ }
413
+ if (Math.sin(alpha1) * Math.sin(alpha2) < 0) {
414
+ return null; // ambiguous intersection
415
+ }
416
+ //alpha1 = Math.abs(alpha1);
417
+ //alpha2 = Math.abs(alpha2); // ... Ed Williams takes abs of alpha1/alpha2, but seems to break calculation?
418
+ let alpha3: double = Math.acos(-Math.cos(alpha1) * Math.cos(alpha2) +
419
+ Math.sin(alpha1) * Math.sin(alpha2) * Math.cos(dist12));
420
+
421
+ let dist13: double = Math.atan2(Math.sin(dist12) * Math.sin(alpha1) * Math.sin(alpha2),
422
+ Math.cos(alpha2) + Math.cos(alpha1) * Math.cos(alpha3));
423
+
424
+ let lat3: double = Math.asin(Math.sin(lat1) * Math.cos(dist13) +
425
+ Math.cos(lat1) * Math.sin(dist13) * Math.cos(brng13));
426
+ let dLon13: double = Math.atan2(Math.sin(brng13) * Math.sin(dist13) * Math.cos(lat1),
427
+ Math.cos(dist13) - Math.sin(lat1) * Math.sin(lat3));
428
+ let lon3: double = lon1 + dLon13;
429
+ lon3 = (lon3 + Math.PI) % (2 * Math.PI) - Math.PI; // normalise to -180..180º
430
+
431
+ //return new POINT2(lat3.toDeg(), lon3.toDeg());
432
+ ptResult = new POINT2(mdlGeodesic.RadToDeg(lon3), mdlGeodesic.RadToDeg(lat3));
433
+
434
+ } catch (exc) {
435
+ if (exc instanceof Error) {
436
+ ErrorLogger.LogException(mdlGeodesic._className, "IntersectLines",
437
+ new RendererException("Failed inside IntersectLines", exc));
438
+ } else {
439
+ throw exc;
440
+ }
441
+ }
442
+ return ptResult;
443
+ }
444
+ /**
445
+ * Normalizes geo points for arrays which span the IDL
446
+ *
447
+ * @param geoPoints
448
+ * @return
449
+ */
450
+ public static normalize_points(geoPoints: Array<POINT2>): Array<POINT2> {
451
+ let normalizedPts: Array<POINT2>;
452
+ try {
453
+ if (geoPoints == null || geoPoints.length === 0) {
454
+ return normalizedPts;
455
+ }
456
+
457
+ let j: int = 0;
458
+ let minx: double = geoPoints[0].x;
459
+ let maxx: double = minx;
460
+ let spansIDL: boolean = false;
461
+ let pt: POINT2;
462
+ let n: int = geoPoints.length;
463
+ //for (j = 1; j < geoPoints.length; j++)
464
+ for (j = 1; j < n; j++) {
465
+ pt = geoPoints[j];
466
+ if (pt.x < minx) {
467
+ minx = pt.x;
468
+ }
469
+ if (pt.x > maxx) {
470
+ maxx = pt.x;
471
+ }
472
+ }
473
+ if (maxx - minx > 180) {
474
+ spansIDL = true;
475
+ }
476
+
477
+ if (!spansIDL) {
478
+ return geoPoints;
479
+ }
480
+
481
+ normalizedPts = new Array();
482
+ n = geoPoints.length;
483
+ //for (j = 0; j < geoPoints.length; j++)
484
+ for (j = 0; j < n; j++) {
485
+ pt = geoPoints[j];
486
+ if (pt.x < 0) {
487
+ pt.x += 360;
488
+ }
489
+ normalizedPts.push(pt);
490
+ }
491
+ } catch (exc) {
492
+ if (exc instanceof Error) {
493
+ ErrorLogger.LogException(mdlGeodesic._className, "normalize_pts",
494
+ new RendererException("Failed inside normalize_pts", exc));
495
+ } else {
496
+ throw exc;
497
+ }
498
+ }
499
+ return normalizedPts;
500
+ }
501
+
502
+ /**
503
+ * calculates the geodesic MBR, intended for regular shaped areas
504
+ *
505
+ * @param geoPoints
506
+ * @return
507
+ */
508
+ public static geodesic_mbr(geoPoints: Array<POINT2>): Rectangle2D | null {
509
+ let rect2d: Rectangle2D;
510
+ try {
511
+ if (geoPoints == null || geoPoints.length === 0) {
512
+ return null;
513
+ }
514
+
515
+ let normalizedPts: Array<POINT2> = mdlGeodesic.normalize_points(geoPoints);
516
+ let ulx: double = normalizedPts[0].x;
517
+ let lrx: double = ulx;
518
+ let uly: double = normalizedPts[0].y;
519
+ let lry: double = uly;
520
+ let j: int = 0;
521
+ let pt: POINT2;
522
+ let n: int = normalizedPts.length;
523
+ //for(j=1;j<normalizedPts.length;j++)
524
+ for (j = 1; j < n; j++) {
525
+ pt = normalizedPts[j];
526
+ if (pt.x < ulx) {
527
+
528
+ ulx = pt.x;
529
+ }
530
+
531
+ if (pt.x > lrx) {
532
+
533
+ lrx = pt.x;
534
+ }
535
+
536
+
537
+ if (pt.y > uly) {
538
+
539
+ uly = pt.y;
540
+ }
541
+
542
+ if (pt.y < lry) {
543
+
544
+ lry = pt.y;
545
+ }
546
+
547
+ }
548
+ let ul: POINT2 = new POINT2(ulx, uly);
549
+ let ur: POINT2 = new POINT2(lrx, uly);
550
+ let lr: POINT2 = new POINT2(lrx, lry);
551
+ let width: double = mdlGeodesic.geodesic_distance(ul, ur, null, null);
552
+ let height: double = mdlGeodesic.geodesic_distance(ur, lr, null, null);
553
+ rect2d = new Rectangle2D(ulx, uly, width, height);
554
+ } catch (exc) {
555
+ if (exc instanceof Error) {
556
+ ErrorLogger.LogException(mdlGeodesic._className, "geodesic_mbr",
557
+ new RendererException("Failed inside geodesic_mbr", exc));
558
+ } else {
559
+ throw exc;
560
+ }
561
+ }
562
+ return rect2d;
563
+ }
564
+
565
+ /**
566
+ * Currently used by AddModifiers for greater accuracy on center labels
567
+ *
568
+ * @param geoPoints
569
+ * @return
570
+ */
571
+ public static geodesic_center(geoPoints: Array<POINT2>): POINT2 | null {
572
+ let pt: POINT2;
573
+ try {
574
+ if (geoPoints == null || geoPoints.length === 0) {
575
+ return null;
576
+ }
577
+
578
+
579
+ let rect2d: Rectangle2D = mdlGeodesic.geodesic_mbr(geoPoints);
580
+ let deltax: double = rect2d.getWidth() / 2;
581
+ let deltay: double = rect2d.getHeight() / 2;
582
+ let ul: POINT2 = new POINT2(rect2d.x, rect2d.y);
583
+ //first walk east by deltax
584
+ let ptEast: POINT2 = mdlGeodesic.geodesic_coordinate(ul, deltax, 90);
585
+ //next walk south by deltay;
586
+ pt = mdlGeodesic.geodesic_coordinate(ptEast, deltay, 180);
587
+
588
+ } catch (exc) {
589
+ if (exc instanceof Error) {
590
+ ErrorLogger.LogException(mdlGeodesic._className, "geodesic_center",
591
+ new RendererException("Failed inside geodesic_center", exc));
592
+ } else {
593
+ throw exc;
594
+ }
595
+ }
596
+ return pt;
597
+ }
598
+ /**
599
+ * rotates a point from a center point in degrees
600
+ * @param ptCenter center point to rotate about
601
+ * @param ptRotate point to rotate
602
+ * @param rotation rotation angle in degrees
603
+ * @return
604
+ */
605
+ private static geoRotatePoint(ptCenter: POINT2, ptRotate: POINT2, rotation: double): POINT2 | null {
606
+ try {
607
+ let bearing: double = mdlGeodesic.GetAzimuth(ptCenter, ptRotate);
608
+ let dist: double = mdlGeodesic.geodesic_distance(ptCenter, ptRotate, null, null);
609
+ return mdlGeodesic.geodesic_coordinate(ptCenter, dist, bearing + rotation);
610
+ } catch (exc) {
611
+ if (exc instanceof Error) {
612
+ ErrorLogger.LogException(mdlGeodesic._className, "geoRotatePoint",
613
+ new RendererException("Failed inside geoRotatePoint", exc));
614
+ } else {
615
+ throw exc;
616
+ }
617
+ }
618
+ return null;
619
+ }
620
+ /**
621
+ * Calculates points for a geodesic ellipse and rotates the points by rotation
622
+ * @param ptCenter
623
+ * @param majorRadius
624
+ * @param minorRadius
625
+ * @param rotation rotation angle in degrees
626
+ * @return
627
+ */
628
+ public static getGeoEllipse(ptCenter: POINT2, majorRadius: double, minorRadius: double, rotation: double): POINT2[] {
629
+ let pEllipsePoints: POINT2[];
630
+ try {
631
+ pEllipsePoints = new Array<POINT2>(37);
632
+ //int l=0;
633
+ let pt: POINT2;
634
+ let dFactor: double = 0;
635
+ let azimuth: double = 0;
636
+ let a: double = 0;
637
+ let b: double = 0;
638
+ let dist: double = 0;
639
+ let bearing: double = 0;
640
+ let ptLongitude: POINT2;
641
+ let ptLatitude: POINT2;
642
+ for (let l: int = 1; l < 37; l++) {
643
+ dFactor = (10.0 * l) * Math.PI / 180.0;
644
+ a = majorRadius * Math.cos(dFactor);
645
+ b = minorRadius * Math.sin(dFactor);
646
+ //dist=Math.sqrt(a*a+b*b);
647
+ //azimuth = (10.0 * l);// * Math.PI / 180.0;
648
+ //azimuth=90-azimuth;
649
+ //pt = geodesic_coordinate(ptCenter,dist,azimuth);
650
+ //pt = geodesic_coordinate(ptCenter,dist,azimuth);
651
+ ptLongitude = mdlGeodesic.geodesic_coordinate(ptCenter, a, 90);
652
+ ptLatitude = mdlGeodesic.geodesic_coordinate(ptCenter, b, 0);
653
+ //pt=new POINT2(ptLatitude.x,ptLongitude.y);
654
+ pt = new POINT2(ptLongitude.x, ptLatitude.y);
655
+ //pEllipsePoints[l-1]=pt;
656
+ pEllipsePoints[l - 1] = mdlGeodesic.geoRotatePoint(ptCenter, pt, -rotation);
657
+ }
658
+ pEllipsePoints[36] = new POINT2(pEllipsePoints[0]);
659
+ } catch (exc) {
660
+ if (exc instanceof Error) {
661
+ ErrorLogger.LogException(mdlGeodesic._className, "GetGeoEllipse",
662
+ new RendererException("GetGeoEllipse", exc));
663
+ } else {
664
+ throw exc;
665
+ }
666
+ }
667
+ return pEllipsePoints;
668
+ }
669
+ }