@pirireis/webglobeplugins 0.9.11 → 0.9.13

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 (179) hide show
  1. package/Math/angle-calculation.js +9 -11
  2. package/Math/arc.js +38 -41
  3. package/Math/bounds/line-bbox.js +79 -83
  4. package/Math/constants.js +4 -9
  5. package/Math/frustum/types.js +1 -2
  6. package/Math/juction/arc-plane.js +33 -36
  7. package/Math/juction/line-sphere.js +15 -18
  8. package/Math/juction/plane-plane.js +20 -23
  9. package/Math/line.js +42 -47
  10. package/Math/methods.js +69 -92
  11. package/Math/plane.js +33 -38
  12. package/Math/quaternion.js +48 -55
  13. package/Math/types.js +1 -2
  14. package/Math/utils.js +2 -4
  15. package/Math/vec3.js +46 -52
  16. package/algorithms/search-binary.js +5 -8
  17. package/altitude-locator/draw-subset-obj.js +8 -11
  18. package/altitude-locator/plugin.js +114 -133
  19. package/altitude-locator/types.js +1 -3
  20. package/arrowfield/adaptor.js +3 -7
  21. package/arrowfield/index.js +3 -10
  22. package/arrowfield/plugin.js +63 -69
  23. package/bearing-line/index.js +2 -8
  24. package/bearing-line/plugin.js +218 -248
  25. package/circle-line-chain/chain-list-map.js +82 -92
  26. package/circle-line-chain/plugin.js +147 -182
  27. package/circle-line-chain/util.js +1 -5
  28. package/compass-rose/compass-rose-padding-flat.js +111 -140
  29. package/compass-rose/compass-text-writer.js +63 -75
  30. package/compass-rose/index.js +3 -7
  31. package/compassrose/compassrose.js +50 -57
  32. package/compassrose/index.js +2 -8
  33. package/heatwave/index.js +3 -10
  34. package/heatwave/isobar/objectarraylabels.js +50 -56
  35. package/heatwave/isobar/plugin.js +111 -170
  36. package/heatwave/isobar/quadtreecontours.js +78 -96
  37. package/heatwave/plugins/heatwaveglobeshell.js +73 -94
  38. package/index.js +12 -58
  39. package/package.json +1 -1
  40. package/partialrings/buffer-manager.js +32 -70
  41. package/partialrings/index.js +2 -41
  42. package/partialrings/plugin.js +55 -98
  43. package/partialrings/program.js +141 -59
  44. package/pin/pin-object-array.js +89 -97
  45. package/pin/pin-point-totem.js +21 -22
  46. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +11 -14
  47. package/point-heat-map/plugin-webworker.js +45 -53
  48. package/point-heat-map/point-to-heat-map-flow.js +46 -51
  49. package/point-tracks/key-methods.js +2 -5
  50. package/point-tracks/plugin.js +141 -170
  51. package/programs/arrowfield/index.js +2 -7
  52. package/programs/arrowfield/logic.js +172 -67
  53. package/programs/arrowfield/object.js +35 -43
  54. package/programs/data2legend/density-to-legend.js +47 -26
  55. package/programs/data2legend/point-to-density-texture.js +56 -34
  56. package/programs/float2legendwithratio/index.js +2 -8
  57. package/programs/float2legendwithratio/logic.js +88 -45
  58. package/programs/float2legendwithratio/object.js +45 -54
  59. package/programs/globe-util/is-globe-moved.js +10 -13
  60. package/programs/globeshell/index.js +2 -8
  61. package/programs/globeshell/wiggle/index.js +2 -8
  62. package/programs/globeshell/wiggle/logic.js +191 -101
  63. package/programs/globeshell/wiggle/object.js +35 -43
  64. package/programs/helpers/blender/program.js +36 -22
  65. package/programs/helpers/fadeaway/index.js +2 -7
  66. package/programs/helpers/fadeaway/logic.js +36 -17
  67. package/programs/helpers/fadeaway/object.js +11 -18
  68. package/programs/helpers/index.js +2 -8
  69. package/programs/index.js +9 -58
  70. package/programs/line-on-globe/angled-line.js +95 -39
  71. package/programs/line-on-globe/circle-accurate-3d.js +86 -39
  72. package/programs/line-on-globe/circle-accurate-flat.js +116 -64
  73. package/programs/line-on-globe/circle-accurate.js +113 -46
  74. package/programs/line-on-globe/circle.js +106 -44
  75. package/programs/line-on-globe/degree-padding-around-circle-3d.js +89 -42
  76. package/programs/line-on-globe/lines-color-instanced-flat.js +84 -43
  77. package/programs/line-on-globe/linestrip.js +126 -63
  78. package/programs/line-on-globe/naive-accurate-flexible.js +126 -59
  79. package/programs/line-on-globe/to-the-surface.js +62 -35
  80. package/programs/line-on-globe/util.js +2 -5
  81. package/programs/picking/pickable-renderer.js +127 -46
  82. package/programs/point-on-globe/element-globe-surface-glow.js +83 -46
  83. package/programs/point-on-globe/element-point-glow.js +112 -47
  84. package/programs/point-on-globe/square-pixel-point.js +80 -34
  85. package/programs/programcache.js +14 -19
  86. package/programs/rings/distancering/circleflatprogram.js +76 -70
  87. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +168 -194
  88. package/programs/rings/distancering/circlepaddysharedbuffer.js +121 -200
  89. package/programs/rings/distancering/index.js +5 -14
  90. package/programs/rings/distancering/paddyflatprogram.js +87 -70
  91. package/programs/rings/distancering/paddyflatprogram2d.js +89 -72
  92. package/programs/rings/distancering/paddyflatprogram3d.js +87 -70
  93. package/programs/rings/index.js +1 -17
  94. package/programs/rings/partial-ring/piece-of-pie.js +144 -44
  95. package/programs/totems/camerauniformblock.js +65 -56
  96. package/programs/totems/canvas-webglobe-info.js +49 -45
  97. package/programs/totems/gpu-selection-uniform-block.js +45 -45
  98. package/programs/totems/index.js +2 -40
  99. package/programs/two-d/pixel-padding-for-compass.js +94 -36
  100. package/programs/util.js +7 -10
  101. package/programs/vectorfields/index.js +3 -23
  102. package/programs/vectorfields/logics/drawrectangleparticles.js +73 -35
  103. package/programs/vectorfields/logics/index.js +4 -12
  104. package/programs/vectorfields/logics/pixelbased.js +94 -41
  105. package/programs/vectorfields/logics/ubo.js +32 -32
  106. package/programs/vectorfields/pingpongbuffermanager.js +30 -37
  107. package/rangerings/enum.js +2 -5
  108. package/rangerings/index.js +5 -15
  109. package/rangerings/plugin.js +223 -286
  110. package/rangerings/rangeringangletext.js +122 -137
  111. package/rangerings/ring-account.js +53 -75
  112. package/shaders/fragment-toy/firework.js +55 -4
  113. package/shaders/fragment-toy/singularity.js +56 -5
  114. package/timetracks/adaptors-line-strip.js +27 -44
  115. package/timetracks/adaptors.js +48 -67
  116. package/timetracks/index.js +5 -19
  117. package/timetracks/plugin-line-strip.js +65 -79
  118. package/timetracks/plugin.js +71 -85
  119. package/timetracks/program-line-strip.js +297 -107
  120. package/timetracks/program.js +421 -118
  121. package/timetracks/programpoint-line-strip.js +98 -48
  122. package/timetracks/programpoint.js +91 -48
  123. package/util/account/bufferoffsetmanager.js +72 -98
  124. package/util/account/index.js +3 -23
  125. package/util/account/single-attribute-buffer-management/buffer-manager.js +44 -48
  126. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +68 -98
  127. package/util/account/single-attribute-buffer-management/index.js +4 -9
  128. package/util/account/single-attribute-buffer-management/object-store.js +29 -34
  129. package/util/account/single-attribute-buffer-management/types.js +1 -2
  130. package/util/account/util.js +2 -8
  131. package/util/algorithms/search-binary.js +5 -8
  132. package/util/check/get.js +5 -9
  133. package/util/check/typecheck.js +13 -24
  134. package/util/geometry/index.js +10 -18
  135. package/util/gl-util/buffer/attribute-loader.js +10 -26
  136. package/util/gl-util/buffer/index.js +2 -5
  137. package/util/gl-util/draw-options/methods.js +10 -15
  138. package/util/gl-util/uniform-block/manager.js +69 -72
  139. package/util/heatwavedatamanager/datamanager.js +56 -119
  140. package/util/heatwavedatamanager/index.js +3 -10
  141. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +38 -47
  142. package/util/heatwavedatamanager/pointcoordsmeta.js +9 -13
  143. package/util/index.js +13 -57
  144. package/util/interpolation/timetrack/index.js +2 -5
  145. package/util/interpolation/timetrack/timetrack-interpolator.js +30 -36
  146. package/util/interpolation/timetrack/web-worker-str.js +180 -5
  147. package/util/interpolation/timetrack/web-worker.js +4 -6
  148. package/util/jshelpers/data-filler.js +8 -11
  149. package/util/jshelpers/equality.js +1 -3
  150. package/util/jshelpers/index.js +2 -37
  151. package/util/jshelpers/timefilters.js +8 -10
  152. package/util/picking/fence.js +8 -11
  153. package/util/picking/picker-displayer.js +49 -58
  154. package/util/programs/draw-texture-on-canvas.js +41 -26
  155. package/util/programs/index.js +1 -17
  156. package/util/programs/shapesonglobe.js +104 -68
  157. package/util/programs/supersampletotextures.js +45 -43
  158. package/util/programs/texturetoglobe.js +99 -52
  159. package/util/shaderfunctions/geometrytransformations.js +323 -35
  160. package/util/shaderfunctions/index.js +2 -18
  161. package/util/shaderfunctions/nodata.js +8 -5
  162. package/util/shaderfunctions/noisefunctions.js +40 -12
  163. package/util/surface-line-data/arcs-to-cuts.js +20 -23
  164. package/util/webglobe/gldefaultstates.js +1 -4
  165. package/util/webglobe/index.js +2 -18
  166. package/util/webglobe/rasteroverlay.js +36 -41
  167. package/util/webglobjectbuilders.js +70 -93
  168. package/util/webglobjectbuilders1.js +63 -82
  169. package/waveparticles/adaptor.js +7 -10
  170. package/waveparticles/index.js +3 -10
  171. package/waveparticles/plugin.js +82 -90
  172. package/wind/imagetovectorfieldandmagnitude.js +16 -19
  173. package/wind/index.js +5 -14
  174. package/wind/plugin.js +454 -291
  175. package/wind/vectorfieldimage.js +6 -8
  176. package/write-text/attached-text-writer.js +48 -54
  177. package/write-text/context-text.js +52 -63
  178. package/write-text/context-text3.js +71 -80
  179. package/write-text/index.js +1 -5
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TextureToGlobeProgram = void 0;
4
- var webglobjectbuilders_1 = require("../webglobjectbuilders");
5
- var __1 = require("..");
6
- var __2 = require("..");
1
+ import { createProgram } from "../webglobjectbuilders";
2
+ import { shaderfunctions } from "..";
3
+ import { latLongBboxtoPixelXYBbox } from "..";
7
4
  /** TODO:
8
5
  * 3d icin calistir
9
6
  */
10
7
  //TODO: DELETE THIS FILE.
11
- var TextureToGlobeProgram = /** @class */ (function () {
12
- function TextureToGlobeProgram(gl, globe) {
8
+ class TextureToGlobeProgram {
9
+ constructor(gl, globe) {
13
10
  this.globe = globe;
14
11
  this.gl = gl;
15
12
  this._is3D = true;
@@ -17,9 +14,9 @@ var TextureToGlobeProgram = /** @class */ (function () {
17
14
  this._resizeHandler = this._resizeEventHandler.bind(this);
18
15
  window.addEventListener('resize', this._resizeHandler, true);
19
16
  }
20
- TextureToGlobeProgram.prototype._initUniforms = function () {
21
- var _a = this, gl = _a.gl, _programWrapper = _a._programWrapper;
22
- var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
17
+ _initUniforms() {
18
+ const { gl, _programWrapper } = this;
19
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
23
20
  gl.useProgram(_programWrapper.program);
24
21
  // set u_alpha
25
22
  gl.uniformMatrix3fv(_programWrapper.u_bbox_matrix, false, new Float32Array([
@@ -31,14 +28,65 @@ var TextureToGlobeProgram = /** @class */ (function () {
31
28
  gl.uniform1f(_programWrapper.u_is3D, 1.0);
32
29
  gl.uniform1f(_programWrapper.height, 0.0);
33
30
  gl.useProgram(currentProgram);
34
- };
35
- TextureToGlobeProgram.prototype._createProgramWrapper = function () {
36
- var gl = this.gl;
37
- var vertexSource = "#version 300 es\n precision highp float;\n\n in vec2 a_position;\n\n uniform mat3 u_bbox_matrix;\n\n uniform mat4 u_model_view_matrix;\n uniform mat4 u_proj_matrix;\n uniform vec3 u_transpos;\n\n uniform vec2 u_mapWH;\n uniform vec2 u_scrWH;\n\n uniform bool u_is3D;\n uniform float height; \n\n out vec2 v_texcoord;\n\n\n " + __1.shaderfunctions.pixelXYToCartesian3DPoint + "\n " + __1.shaderfunctions.pixelXYToCartesian2DPoint + "\n\n\n void main() {\n vec3 pos = u_bbox_matrix * vec3(a_position, height);\n if(u_is3D){\n pos = pixelXYToCartesian3DPoint(pos);\n gl_Position = u_proj_matrix * u_model_view_matrix * vec4(pos - u_transpos, 1.0);\n } else {\n vec2 xy = pixelXYToCartesian2DPoint(pos.xy, u_transpos.xy, u_mapWH, u_scrWH);\n gl_Position = u_proj_matrix * vec4(xy.x, xy.y, 0.0, 1.0);\n }\n gl_PointSize = 100.0;\n v_texcoord = a_position * 0.5 + 0.5; // need a check\n }\n ";
38
- var fragmentSource = "#version 300 es\n precision highp float;\n\n in vec2 v_texcoord;\n\n uniform float u_alpha;\n uniform sampler2D u_texture;\n\n out vec4 outColor;\n\n void main() {\n // outColor = texture(u_texture, v_texcoord);\n // outColor.a *= u_alpha;\n outColor = vec4(1.0, 0.0, 0.0, 0.5);\n } \n ";
39
- var program = (0, webglobjectbuilders_1.createProgram)(gl, vertexSource, fragmentSource);
40
- var vao = gl.createVertexArray();
41
- var buffer = gl.createBuffer();
31
+ }
32
+ _createProgramWrapper() {
33
+ const gl = this.gl;
34
+ const vertexSource = `#version 300 es
35
+ precision highp float;
36
+
37
+ in vec2 a_position;
38
+
39
+ uniform mat3 u_bbox_matrix;
40
+
41
+ uniform mat4 u_model_view_matrix;
42
+ uniform mat4 u_proj_matrix;
43
+ uniform vec3 u_transpos;
44
+
45
+ uniform vec2 u_mapWH;
46
+ uniform vec2 u_scrWH;
47
+
48
+ uniform bool u_is3D;
49
+ uniform float height;
50
+
51
+ out vec2 v_texcoord;
52
+
53
+
54
+ ` + shaderfunctions.pixelXYToCartesian3DPoint + `
55
+ ` + shaderfunctions.pixelXYToCartesian2DPoint + `
56
+
57
+
58
+ void main() {
59
+ vec3 pos = u_bbox_matrix * vec3(a_position, height);
60
+ if(u_is3D){
61
+ pos = pixelXYToCartesian3DPoint(pos);
62
+ gl_Position = u_proj_matrix * u_model_view_matrix * vec4(pos - u_transpos, 1.0);
63
+ } else {
64
+ vec2 xy = pixelXYToCartesian2DPoint(pos.xy, u_transpos.xy, u_mapWH, u_scrWH);
65
+ gl_Position = u_proj_matrix * vec4(xy.x, xy.y, 0.0, 1.0);
66
+ }
67
+ gl_PointSize = 100.0;
68
+ v_texcoord = a_position * 0.5 + 0.5; // need a check
69
+ }
70
+ `;
71
+ const fragmentSource = `#version 300 es
72
+ precision highp float;
73
+
74
+ in vec2 v_texcoord;
75
+
76
+ uniform float u_alpha;
77
+ uniform sampler2D u_texture;
78
+
79
+ out vec4 outColor;
80
+
81
+ void main() {
82
+ // outColor = texture(u_texture, v_texcoord);
83
+ // outColor.a *= u_alpha;
84
+ outColor = vec4(1.0, 0.0, 0.0, 0.5);
85
+ }
86
+ `;
87
+ const program = createProgram(gl, vertexSource, fragmentSource);
88
+ const vao = gl.createVertexArray();
89
+ const buffer = gl.createBuffer();
42
90
  gl.bindVertexArray(vao);
43
91
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
44
92
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
@@ -47,7 +95,7 @@ var TextureToGlobeProgram = /** @class */ (function () {
47
95
  1, 1,
48
96
  0, 1
49
97
  ]), gl.STATIC_DRAW);
50
- var a_position = -gl.getAttribLocation(program, 'a_position');
98
+ const a_position = -gl.getAttribLocation(program, 'a_position');
51
99
  gl.enableVertexAttribArray(a_position);
52
100
  gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
53
101
  gl.bindVertexArray(null);
@@ -63,10 +111,10 @@ var TextureToGlobeProgram = /** @class */ (function () {
63
111
  u_bbox_matrix: gl.getUniformLocation(program, 'u_bbox_matrix'),
64
112
  u_is3D: gl.getUniformLocation(program, 'u_is3D'),
65
113
  };
66
- };
67
- TextureToGlobeProgram.prototype.draw = function (modelViewMatrix, projectionMatrix, transPos, texture) {
114
+ }
115
+ draw(modelViewMatrix, projectionMatrix, transPos, texture) {
68
116
  // console.log('draw')
69
- var _a = this, gl = _a.gl, _programWrapper = _a._programWrapper, _is3D = _a._is3D;
117
+ const { gl, _programWrapper, _is3D } = this;
70
118
  gl.useProgram(_programWrapper.program);
71
119
  gl.bindVertexArray(_programWrapper.vao);
72
120
  gl.uniformMatrix4fv(_programWrapper.u_model_view_matrix, false, modelViewMatrix);
@@ -76,15 +124,15 @@ var TextureToGlobeProgram = /** @class */ (function () {
76
124
  gl.bindTexture(gl.TEXTURE_2D, texture);
77
125
  gl.uniform1i(_programWrapper.u_texture, 0);
78
126
  if (!_is3D) {
79
- var mapWH = this.globe.api_GetCurrentWorldWH();
127
+ const mapWH = this.globe.api_GetCurrentWorldWH();
80
128
  gl.uniform2f(_programWrapper.u_mapWH, mapWH.width, mapWH.height);
81
129
  }
82
130
  gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
83
131
  gl.drawArrays(gl.POINTS, 0, 4);
84
- };
85
- TextureToGlobeProgram.prototype.setBBox = function (minx, maxx, miny, maxy) {
86
- var _a = this, gl = _a.gl, _programWrapper = _a._programWrapper;
87
- var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
132
+ }
133
+ setBBox(minx, maxx, miny, maxy) {
134
+ const { gl, _programWrapper } = this;
135
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
88
136
  gl.useProgram(_programWrapper.program);
89
137
  gl.uniformMatrix3fv(_programWrapper.u_bbox_matrix, false, new Float32Array([
90
138
  maxx - minx, 0, minx,
@@ -92,41 +140,40 @@ var TextureToGlobeProgram = /** @class */ (function () {
92
140
  0, 0, 1
93
141
  ]));
94
142
  gl.useProgram(currentProgram);
95
- };
96
- TextureToGlobeProgram.prototype.setLatLongBBox = function (minx, maxx, miny, maxy) {
97
- var bboxMatrix = (0, __2.latLongBboxtoPixelXYBbox)(minx, miny, maxx, maxy);
98
- var _a = this, gl = _a.gl, _programWrapper = _a._programWrapper;
99
- var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
143
+ }
144
+ setLatLongBBox(minx, maxx, miny, maxy) {
145
+ const bboxMatrix = latLongBboxtoPixelXYBbox(minx, miny, maxx, maxy);
146
+ const { gl, _programWrapper } = this;
147
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
100
148
  gl.useProgram(_programWrapper.program);
101
149
  gl.uniformMatrix3fv(_programWrapper.u_bbox_matrix, false, bboxMatrix);
102
150
  gl.useProgram(currentProgram);
103
- };
104
- TextureToGlobeProgram.prototype.setScreenWH = function () {
105
- var _a = this, gl = _a.gl, _programWrapper = _a._programWrapper, globe = _a.globe;
106
- var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
151
+ }
152
+ setScreenWH() {
153
+ const { gl, _programWrapper, globe } = this;
154
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
107
155
  gl.useProgram(_programWrapper.program);
108
156
  gl.uniform2f(_programWrapper.u_scrWH, globe.api_ScrW(), globe.api_ScrH());
109
157
  gl.useProgram(currentProgram);
110
- };
111
- TextureToGlobeProgram.prototype.resize = function () {
112
- var globe = this.globe;
158
+ }
159
+ resize() {
160
+ const { globe } = this;
113
161
  this.setScreenWH();
114
- };
115
- TextureToGlobeProgram.prototype.setGeometry = function () {
116
- var _a = this, gl = _a.gl, globe = _a.globe, _programWrapper = _a._programWrapper;
162
+ }
163
+ setGeometry() {
164
+ const { gl, globe, _programWrapper } = this;
117
165
  this._is3D = globe.api_GetCurrentGeometry() === 0;
118
- var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
166
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
119
167
  gl.useProgram(_programWrapper.program);
120
168
  gl.uniform1f(_programWrapper.u_is3D, this._is3D ? 1.0 : 0.0);
121
169
  gl.useProgram(currentProgram);
122
170
  this.resize();
123
- };
124
- TextureToGlobeProgram.prototype.free = function () {
171
+ }
172
+ free() {
125
173
  window.removeEventListener('resize', this._resizeHandler, true);
126
- };
127
- TextureToGlobeProgram.prototype._resizeEventHandler = function () {
174
+ }
175
+ _resizeEventHandler() {
128
176
  this.resize();
129
- };
130
- return TextureToGlobeProgram;
131
- }());
132
- exports.TextureToGlobeProgram = TextureToGlobeProgram;
177
+ }
178
+ }
179
+ export { TextureToGlobeProgram };
@@ -1,45 +1,333 @@
1
- "use strict";
2
1
  // Z in kolometers
3
2
  //
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.circleOnSphere = exports.circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate = exports.circleLimpFromLongLatRadCenterMercatorCompass_accurate = exports.circleLimpFromLongLatRadCenterCartesian3D_accurate = exports.slerp = exports.realDistanceOnSphereR1 = exports.circleCircumferenceInterPolationOf2PointsRadian = exports.angleBetweenTwoPointsRadian = exports.cartesianToSpherical = exports.circleLimpFromLongLatRadCenterMercatorCompass = exports.circleLimpFromLongLatRadCenterMercatorRealDistancePadding = exports.circleLimpFromLongLatRadCenterMercatorRealDistance = exports.circleLimpFromLongLatRadCenterMercatorRealDistanceNew = exports.circleLimpFromLongLatRadCenterCartesian3D = exports.longLatRadToCartesian3DWithR = exports.longLatRadToCartesian3D = exports.longLatRadToMercator = exports.cartesian3DToGLPosition = exports.mercatorXYToGLPosition = exports.pixelXYToCartesian2DPoint = exports.pixelXYToCartesian3DPoint = exports.R_3D = exports.POLE_BY_PI = exports.PI = exports.R = exports.POLE = void 0;
6
- exports.POLE = "\n#ifndef POLE\n#define POLE 20037508.34\n#endif\n";
7
- exports.R = "\n#ifndef R\n#define R 6378137.0\n#endif\n";
8
- exports.PI = "\n#ifndef PI\n#define PI 3.141592653589793\n\n#endif\n";
9
- exports.POLE_BY_PI = " \n#ifndef POLE_BY_PI\n#define POLE_BY_PI 6378137.0\n#endif\n";
10
- exports.R_3D = "\n#ifndef R_3D\n#define R_3D 6378.137\n#endif\n";
11
- exports.pixelXYToCartesian3DPoint = exports.R_3D + exports.PI + "\nvec3 pixelXYToCartesian3DPoint( vec3 position) {\n float longRad = PI * (2.0 * position.x - 1.0);\n float latRad = PI * position.y;\n float radius = R_3D + position.z;\n float x = radius * sin(latRad) * cos(longRad);\n float y = radius * sin(latRad) * sin(longRad);\n float z = radius * cos(latRad);\n return vec3(x, y, z);\n}\n";
12
- exports.pixelXYToCartesian2DPoint = exports.PI + exports.POLE + exports.POLE_BY_PI + "\nvec2 pixelXYToCartesian2DPoint( vec2 position, vec2 translate, vec2 mapWH, vec2 screenWH) {\n float x = (2.0 * position.x - 1.0) * POLE;\n x = ((x - translate.x) / mapWH.x) * screenWH.x; \n float y = log( tan( ( 1.0 - position.y ) * PI / 2.0 ) ) * POLE_BY_PI;\n y = (1.0 - (y - translate.y) / mapWH.y) * screenWH.y;\n return vec2(x, y);\n}\n";
3
+ export const POLE = `
4
+ #ifndef POLE
5
+ #define POLE 20037508.34
6
+ #endif
7
+ `;
8
+ export const R = `
9
+ #ifndef R
10
+ #define R 6378137.0
11
+ #endif
12
+ `;
13
+ export const PI = `
14
+ #ifndef PI
15
+ #define PI 3.141592653589793
16
+
17
+ #endif
18
+ `;
19
+ export const POLE_BY_PI = `
20
+ #ifndef POLE_BY_PI
21
+ #define POLE_BY_PI 6378137.0
22
+ #endif
23
+ `;
24
+ export const R_3D = `
25
+ #ifndef R_3D
26
+ #define R_3D 6378.137
27
+ #endif
28
+ `;
29
+ export const pixelXYToCartesian3DPoint = R_3D + PI + `
30
+ vec3 pixelXYToCartesian3DPoint( vec3 position) {
31
+ float longRad = PI * (2.0 * position.x - 1.0);
32
+ float latRad = PI * position.y;
33
+ float radius = R_3D + position.z;
34
+ float x = radius * sin(latRad) * cos(longRad);
35
+ float y = radius * sin(latRad) * sin(longRad);
36
+ float z = radius * cos(latRad);
37
+ return vec3(x, y, z);
38
+ }
39
+ `;
40
+ export const pixelXYToCartesian2DPoint = PI + POLE + POLE_BY_PI + `
41
+ vec2 pixelXYToCartesian2DPoint( vec2 position, vec2 translate, vec2 mapWH, vec2 screenWH) {
42
+ float x = (2.0 * position.x - 1.0) * POLE;
43
+ x = ((x - translate.x) / mapWH.x) * screenWH.x;
44
+ float y = log( tan( ( 1.0 - position.y ) * PI / 2.0 ) ) * POLE_BY_PI;
45
+ y = (1.0 - (y - translate.y) / mapWH.y) * screenWH.y;
46
+ return vec2(x, y);
47
+ }
48
+ `;
13
49
  // TODO: rename it to mercatorXYToGLPosition
14
- exports.mercatorXYToGLPosition = "\nvec4 mercatorXYToGLPosition( vec2 position) { // projection, translate, mapWH, screenWH comes from camera uniform block\n float x = (( position.x - translate.x ) / mapWH.x) * screenWH.x;\n float y = (1.0 - (position.y - translate.y) / mapWH.y) * screenWH.y;\n return projection * vec4(x, y, 0.0, 1.0);\n} \n";
15
- exports.cartesian3DToGLPosition = "\nvec4 cartesian3DToGLPosition( vec3 position) {\n return projection * view * vec4(position - translate, 1.0);\n}\n";
50
+ export const mercatorXYToGLPosition = `
51
+ vec4 mercatorXYToGLPosition( vec2 position) { // projection, translate, mapWH, screenWH comes from camera uniform block
52
+ float x = (( position.x - translate.x ) / mapWH.x) * screenWH.x;
53
+ float y = (1.0 - (position.y - translate.y) / mapWH.y) * screenWH.y;
54
+ return projection * vec4(x, y, 0.0, 1.0);
55
+ }
56
+ `;
57
+ export const cartesian3DToGLPosition = `
58
+ vec4 cartesian3DToGLPosition( vec3 position) {
59
+ return projection * view * vec4(position - translate, 1.0);
60
+ }
61
+ `;
16
62
  // pi / pole = 2 / R
17
- exports.longLatRadToMercator = exports.R + exports.PI + "\nvec2 longLatRadToMercator( vec2 longLatRad) {\n float x = R * longLatRad.x;\n float y = R * log( tan( PI / 4.0 + longLatRad.y / 2.0 ) );\n y -= mix(-60.0, 60.0, abs(longLatRad.y + PI / 8.0) / (PI / 4.0));\n return vec2(x, y);\n}\n";
18
- exports.longLatRadToCartesian3D = exports.R_3D + "\nvec3 longLatRadToCartesian3D( vec2 longLat) {\n float x = R_3D * cos(longLat.y) * cos(longLat.x);\n float y = R_3D * cos(longLat.y) * sin(longLat.x);\n float z = R_3D * sin(longLat.y);\n return vec3(x, y, z);\n}\n";
19
- exports.longLatRadToCartesian3DWithR = "\nvec3 longLatRadToCartesian3DWithR( vec2 longLat, float radius) {\n float x = radius * cos(longLat.y) * cos(longLat.x);\n float y = radius * cos(longLat.y) * sin(longLat.x);\n float z = radius * sin(longLat.y);\n return vec3(x, y, z);\n}\n";
63
+ export const longLatRadToMercator = R + PI + `
64
+ vec2 longLatRadToMercator( vec2 longLatRad) {
65
+ float x = R * longLatRad.x;
66
+ float y = R * log( tan( PI / 4.0 + longLatRad.y / 2.0 ) );
67
+ y -= mix(-60.0, 60.0, abs(longLatRad.y + PI / 8.0) / (PI / 4.0));
68
+ return vec2(x, y);
69
+ }
70
+ `;
71
+ export const longLatRadToCartesian3D = R_3D + `
72
+ vec3 longLatRadToCartesian3D( vec2 longLat) {
73
+ float x = R_3D * cos(longLat.y) * cos(longLat.x);
74
+ float y = R_3D * cos(longLat.y) * sin(longLat.x);
75
+ float z = R_3D * sin(longLat.y);
76
+ return vec3(x, y, z);
77
+ }
78
+ `;
79
+ export const longLatRadToCartesian3DWithR = `
80
+ vec3 longLatRadToCartesian3DWithR( vec2 longLat, float radius) {
81
+ float x = radius * cos(longLat.y) * cos(longLat.x);
82
+ float y = radius * cos(longLat.y) * sin(longLat.x);
83
+ float z = radius * sin(longLat.y);
84
+ return vec3(x, y, z);
85
+ }
86
+ `;
20
87
  // TODO: Make it precise. It doesnt use haversine formula. If this changes, change the formmula which calculates text position.
21
- exports.circleLimpFromLongLatRadCenterCartesian3D = exports.R + "\nvec3 circleLimpFromLongLatRadCenterCartesian3D( vec2 center, float radius, float angle) {\n vec3 geoW = longLatRadToCartesian3D(center);\n vec3 normal = normalize(geoW);\n vec3 tangent1 = cross(normal, vec3(0.0, 0.0, -1.0));\n if ( length(tangent1) < 0.1 ){ tangent1 = cross(normal, vec3(0.0, -1.0, 0.0)); }\n tangent1 = normalize(tangent1);\n // rotate tangent with given angle\n tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);\n float radius_in_angle = radius/R;\n float projected_radius = sin(radius_in_angle) * R / 1000.0;\n return (geoW * cos(radius_in_angle))+ tangent1 * projected_radius;\n }\n";
88
+ export const circleLimpFromLongLatRadCenterCartesian3D = R + `
89
+ vec3 circleLimpFromLongLatRadCenterCartesian3D( vec2 center, float radius, float angle) {
90
+ vec3 geoW = longLatRadToCartesian3D(center);
91
+ vec3 normal = normalize(geoW);
92
+ vec3 tangent1 = cross(normal, vec3(0.0, 0.0, -1.0));
93
+ if ( length(tangent1) < 0.1 ){ tangent1 = cross(normal, vec3(0.0, -1.0, 0.0)); }
94
+ tangent1 = normalize(tangent1);
95
+ // rotate tangent with given angle
96
+ tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);
97
+ float radius_in_angle = radius/R;
98
+ float projected_radius = sin(radius_in_angle) * R / 1000.0;
99
+ return (geoW * cos(radius_in_angle))+ tangent1 * projected_radius;
100
+ }
101
+ `;
22
102
  // TODO: Make it precise. Y axis is not correct.
23
- exports.circleLimpFromLongLatRadCenterMercatorRealDistanceNew = exports.PI + "\nvec2 circleLimpFromLongLatRadCenterMercatorRealDistance(vec2 center, float radius, float angle) {\n float ang = angle + PI / 2.0; // Shift angle to align with +x axis\n float r = radius / R;\n float cos_r = cos(r);\n float sin_r = sin(r);\n\n float sin_lat = sin(center.y) * cos_r + cos(center.y) * sin_r * cos(ang);\n float lat = asin(sin_lat);\n\n float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);\n float longi = center.x + delta_long;\n \n\n return vec2(\n R * longi,\n R * log(tan(PI / 4.0 + lat / 2.0)) \n );\n}";
24
- exports.circleLimpFromLongLatRadCenterMercatorRealDistance = exports.PI + "\nvec2 circleLimpFromLongLatRadCenterMercatorRealDistance(vec2 center, float radius, float angle){\n float ang = angle + PI / 2.0; // this is there because the other methods are implemented in, angle 0 is +x axis orientatation\n float r = radius / R;\n float sin_lat = sin(center.y) * cos(r) + cos(center.y) * sin(r) * cos(ang);\n float lat = asin(sin_lat);\n float longi = center.x + atan(sin(ang) * sin(r) * cos(center.y), cos(r) - sin(center.y) * sin_lat);\n return longLatRadToMercator(vec2(longi, lat));\n}\n";
103
+ export const circleLimpFromLongLatRadCenterMercatorRealDistanceNew = PI + `
104
+ vec2 circleLimpFromLongLatRadCenterMercatorRealDistance(vec2 center, float radius, float angle) {
105
+ float ang = angle + PI / 2.0; // Shift angle to align with +x axis
106
+ float r = radius / R;
107
+ float cos_r = cos(r);
108
+ float sin_r = sin(r);
109
+
110
+ float sin_lat = sin(center.y) * cos_r + cos(center.y) * sin_r * cos(ang);
111
+ float lat = asin(sin_lat);
112
+
113
+ float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
114
+ float longi = center.x + delta_long;
115
+
116
+
117
+ return vec2(
118
+ R * longi,
119
+ R * log(tan(PI / 4.0 + lat / 2.0))
120
+ );
121
+ }`;
122
+ export const circleLimpFromLongLatRadCenterMercatorRealDistance = PI + `
123
+ vec2 circleLimpFromLongLatRadCenterMercatorRealDistance(vec2 center, float radius, float angle){
124
+ float ang = angle + PI / 2.0; // this is there because the other methods are implemented in, angle 0 is +x axis orientatation
125
+ float r = radius / R;
126
+ float sin_lat = sin(center.y) * cos(r) + cos(center.y) * sin(r) * cos(ang);
127
+ float lat = asin(sin_lat);
128
+ float longi = center.x + atan(sin(ang) * sin(r) * cos(center.y), cos(r) - sin(center.y) * sin_lat);
129
+ return longLatRadToMercator(vec2(longi, lat));
130
+ }
131
+ `;
25
132
  // TODO: reconstruct this function
26
- exports.circleLimpFromLongLatRadCenterMercatorRealDistancePadding = "\nvec2 circleLimpFromLongLatRadCenterMercatorRealDistancePadding(vec2 center, float radius, float angle){\n float radius_radian = radius / R;\n float new_angle;\n if (angle != - 1.5707963267948966192313216916398) {\n float section = floor(angle / (PI / 2.0)) + 1.0;\n float lat = center.y - radius_radian * sin(angle);\n float scale = 1.0 / abs(cos(lat));\n new_angle = atan(tan(angle) * scale);\n if (section == 2.0) {\n new_angle = mod(new_angle, PI);\n } else if (section == 3.0) {\n new_angle = new_angle + PI;\n }\n } else {\n new_angle = angle;\n }\n float new_lat = center.y - radius_radian * sin(new_angle);\n float new_scale = 1.0 / abs(cos(new_lat));\n\n vec2 center_ = longLatRadToMercator(center);\n float x = center_.x + new_scale * radius * cos(new_angle);\n float y = center_.y - new_scale * radius * sin(new_angle);\n return vec2(x, y);\n}\n";
27
- exports.circleLimpFromLongLatRadCenterMercatorCompass = "\nvec2 circleLimpFromLongLatRadCenterMercatorCompass(vec2 center, float radius, float angle){\n vec2 center_ = longLatRadToMercator(center);\n float y = -sin(angle) * radius + center_.y;\n float x = cos(angle) * radius + center_.x;\n return vec2(x, y);\n} ";
133
+ export const circleLimpFromLongLatRadCenterMercatorRealDistancePadding = `
134
+ vec2 circleLimpFromLongLatRadCenterMercatorRealDistancePadding(vec2 center, float radius, float angle){
135
+ float radius_radian = radius / R;
136
+ float new_angle;
137
+ if (angle != - 1.5707963267948966192313216916398) {
138
+ float section = floor(angle / (PI / 2.0)) + 1.0;
139
+ float lat = center.y - radius_radian * sin(angle);
140
+ float scale = 1.0 / abs(cos(lat));
141
+ new_angle = atan(tan(angle) * scale);
142
+ if (section == 2.0) {
143
+ new_angle = mod(new_angle, PI);
144
+ } else if (section == 3.0) {
145
+ new_angle = new_angle + PI;
146
+ }
147
+ } else {
148
+ new_angle = angle;
149
+ }
150
+ float new_lat = center.y - radius_radian * sin(new_angle);
151
+ float new_scale = 1.0 / abs(cos(new_lat));
152
+
153
+ vec2 center_ = longLatRadToMercator(center);
154
+ float x = center_.x + new_scale * radius * cos(new_angle);
155
+ float y = center_.y - new_scale * radius * sin(new_angle);
156
+ return vec2(x, y);
157
+ }
158
+ `;
159
+ export const circleLimpFromLongLatRadCenterMercatorCompass = `
160
+ vec2 circleLimpFromLongLatRadCenterMercatorCompass(vec2 center, float radius, float angle){
161
+ vec2 center_ = longLatRadToMercator(center);
162
+ float y = -sin(angle) * radius + center_.y;
163
+ float x = cos(angle) * radius + center_.x;
164
+ return vec2(x, y);
165
+ } `;
28
166
  // Function to convert Cartesian coordinates back to spherical (latitude, longitude)
29
- exports.cartesianToSpherical = "\nvec2 cartesianToSpherical(vec3 point) {\n float lat = degrees(asin(point.z)); // Latitude\n float lon = degrees(atan(point.y, point.x)); // Longitude\n\n return vec2(lat, lon);\n} ";
167
+ export const cartesianToSpherical = `
168
+ vec2 cartesianToSpherical(vec3 point) {
169
+ float lat = degrees(asin(point.z)); // Latitude
170
+ float lon = degrees(atan(point.y, point.x)); // Longitude
171
+
172
+ return vec2(lat, lon);
173
+ } `;
30
174
  // Main function to calculate an intermediate point
31
- exports.angleBetweenTwoPointsRadian = "\nfloat angleBetweenTwoPointsRadian(vec2 start_, vec2 end_) {\n float start_lat = log(tan((1.0 - start_.y) * PI / 2.0));\n float end_lat = log(tan((1.0 - end_.y) * PI / 2.0));\n float angle = atan((end_lat - start_lat) / (end_.x - start_.x));\n return angle;\n}\n";
32
- exports.circleCircumferenceInterPolationOf2PointsRadian = "\nfloat circleCircumferenceInterPolationOf2PointsRadian(vec2 center, vec2 target, float bearing_angle, float ratio) {\n vec2 t = target - center;\n float mainAngle = atan(t.x, t.y);\n float angle = mainAngle - * ratio;\n return angle;\n}\n";
33
- exports.realDistanceOnSphereR1 = "\nfloat realDistanceOnSphereR1(vec2 longLat1, vec2 longLat2) {\n float dLat = longLat2.y - longLat1.y;\n float dLong = longLat2.x - longLat1.x;\n float a = sin(dLat / 2.0) * sin(dLat / 2.0) + cos(longLat1.y) * cos(longLat2.y) * sin(dLong / 2.0) * sin(dLong / 2.0);\n float c = 2.0 * atan(sqrt(a), sqrt(1.0 - a));\n return c;\n}\n";
34
- var pointsOnSphereBetween = "\nvec3 pointsOnSphereBetween(vec3 a, vec3 b, float ratio) {\n // Normalize the input points to ensure they are on the unit sphere\n a = normalize(a);\n b = normalize(b);\n\n // Compute the dot product and clamp it to avoid numerical issues\n // float dotProduct = clamp(dot(a, b), -1.0, 1.0);\n\n // Compute the angle between the points\n float theta = acos(dot(a, b));\n\n // Handle the edge case where the points are nearly identical\n if (theta < 0.0001) {\n return normalize(mix(a, b, ratio)); // Linear interpolation as fallback\n }\n\n // Compute the interpolated point using spherical linear interpolation (slerp)\n float sinTheta = sin(theta);\n float factorA = sin((1.0 - ratio) * theta) / sinTheta;\n float factorB = sin(ratio * theta) / sinTheta;\n\n vec3 result = factorA * a + factorB * b;\n\n // Return the normalized result to ensure it lies on the sphere\n return normalize(result);\n}";
35
- var slerp = "\n".concat(pointsOnSphereBetween, "\nvec3 slerp(vec3 A, vec3 B, float t) {\n return pointsOnSphereBetween(A, B, t) * mix(length(A), length(B), t);\n}\n");
36
- exports.slerp = slerp;
37
- var circleLimpFromLongLatRadCenterCartesian3D_accurate = exports.R + "\nvec3 circleLimpFromLongLatRadCenterCartesian3D_accurate( vec3 geoW, float radius, float angle) {\n vec3 normal = normalize(geoW);\n vec3 tangent1 = cross(normal, vec3(0.0, 0.0, -1.0));\n if ( length(tangent1) < 0.1 ){ tangent1 = cross(normal, vec3(0.0, -1.0, 0.0)); }\n tangent1 = normalize(tangent1);\n // rotate tangent with given angle\n tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);\n float radius_in_angle = radius/R;\n float projected_radius = sin(radius_in_angle) * R / 1000.0;\n return (geoW * cos(radius_in_angle)) + tangent1 * projected_radius;\n}";
38
- exports.circleLimpFromLongLatRadCenterCartesian3D_accurate = circleLimpFromLongLatRadCenterCartesian3D_accurate;
39
- var circleOnSphere = "\nvec3 rotateVectorAroundAxis(vec3 v, vec3 axis, float angle) {\n float c = cos(angle);\n float s = sin(angle);\n float t = 1.0 - c;\n vec3 normalizedAxis = normalize(axis); // Ensure axis is unit length\n\n return vec3(\n (t * normalizedAxis.x * normalizedAxis.x + c) * v.x +\n (t * normalizedAxis.x * normalizedAxis.y - s * normalizedAxis.z) * v.y +\n (t * normalizedAxis.x * normalizedAxis.z + s * normalizedAxis.y) * v.z,\n\n (t * normalizedAxis.x * normalizedAxis.y + s * normalizedAxis.z) * v.x +\n (t * normalizedAxis.y * normalizedAxis.y + c) * v.y +\n (t * normalizedAxis.y * normalizedAxis.z - s * normalizedAxis.x) * v.z,\n\n (t * normalizedAxis.x * normalizedAxis.z - s * normalizedAxis.y) * v.x +\n (t * normalizedAxis.y * normalizedAxis.z + s * normalizedAxis.x) * v.y +\n (t * normalizedAxis.z * normalizedAxis.z + c) * v.z\n );\n\n // Alternative, more compact way using cross and dot products:\n // vec3 crossProd = cross(normalizedAxis, v);\n // float dotProd = dot(normalizedAxis, v);\n // return v * c + crossProd * s + normalizedAxis * dotProd * t;\n}\n\n/**\n * @brief Calculates a point on a circle drawn on the surface of a sphere.\n * The sphere is assumed to be centered at the origin (0,0,0).\n * The circle's center on the sphere surface is M, and H is a starting point on the circle.\n * The function returns the point obtained by rotating H around the axis defined by M by angle A.\n *\n * @param M The center point of the circle on the sphere's surface. The vector from the origin to M defines the rotation axis.\n * @param H A starting point on the circle (also on the sphere's surface).\n * @param A The angle of rotation in radians. Use radians(degrees) if your input is in degrees.\n * @return A vec3 representing the calculated point on the sphere's surface.\n */\nvec3 circleOnSphere(vec3 M, vec3 H, float A) {\n // The rotation axis is the vector from the origin to the circle's center point M on the sphere.\n // This axis vector needs to be normalized for the rotation formula.\n vec3 rotationAxis = normalize(M);\n\n // Rotate the starting point H around the rotation axis by angle A.\n vec3 rotatedPoint = rotateVectorAroundAxis(H, rotationAxis, A);\n\n // Optional but recommended: Re-normalize the result to ensure it stays exactly on the sphere's surface,\n // counteracting potential floating-point inaccuracies, especially if the original sphere radius was 1.\n // If the sphere has a different radius R, you might want to normalize and multiply by R:\n // float radius = length(M); // Assuming M is exactly on the surface\n // return normalize(rotatedPoint) * radius;\n // If it's a unit sphere:\n // return normalize(rotatedPoint);\n\n // For simplicity, returning the direct result of rotation. Assume M and H were perfectly on the sphere.\n return rotatedPoint;\n}";
40
- exports.circleOnSphere = circleOnSphere;
41
- var circleLimpFromLongLatRadCenterMercatorCompass_accurate = "\nvec2 circleLimpFromLongLatRadCenterMercatorCompass_accurate(vec2 center, float radius, float angle){\n float y = -sin(angle) * radius + center.y;\n float x = cos(angle) * radius + center.x;\n return vec2(x, y);\n} ";
42
- exports.circleLimpFromLongLatRadCenterMercatorCompass_accurate = circleLimpFromLongLatRadCenterMercatorCompass_accurate;
175
+ export const angleBetweenTwoPointsRadian = `
176
+ float angleBetweenTwoPointsRadian(vec2 start_, vec2 end_) {
177
+ float start_lat = log(tan((1.0 - start_.y) * PI / 2.0));
178
+ float end_lat = log(tan((1.0 - end_.y) * PI / 2.0));
179
+ float angle = atan((end_lat - start_lat) / (end_.x - start_.x));
180
+ return angle;
181
+ }
182
+ `;
183
+ export const circleCircumferenceInterPolationOf2PointsRadian = `
184
+ float circleCircumferenceInterPolationOf2PointsRadian(vec2 center, vec2 target, float bearing_angle, float ratio) {
185
+ vec2 t = target - center;
186
+ float mainAngle = atan(t.x, t.y);
187
+ float angle = mainAngle - * ratio;
188
+ return angle;
189
+ }
190
+ `;
191
+ export const realDistanceOnSphereR1 = `
192
+ float realDistanceOnSphereR1(vec2 longLat1, vec2 longLat2) {
193
+ float dLat = longLat2.y - longLat1.y;
194
+ float dLong = longLat2.x - longLat1.x;
195
+ float a = sin(dLat / 2.0) * sin(dLat / 2.0) + cos(longLat1.y) * cos(longLat2.y) * sin(dLong / 2.0) * sin(dLong / 2.0);
196
+ float c = 2.0 * atan(sqrt(a), sqrt(1.0 - a));
197
+ return c;
198
+ }
199
+ `;
200
+ const pointsOnSphereBetween = `
201
+ vec3 pointsOnSphereBetween(vec3 a, vec3 b, float ratio) {
202
+ // Normalize the input points to ensure they are on the unit sphere
203
+ a = normalize(a);
204
+ b = normalize(b);
205
+
206
+ // Compute the dot product and clamp it to avoid numerical issues
207
+ // float dotProduct = clamp(dot(a, b), -1.0, 1.0);
208
+
209
+ // Compute the angle between the points
210
+ float theta = acos(dot(a, b));
211
+
212
+ // Handle the edge case where the points are nearly identical
213
+ if (theta < 0.0001) {
214
+ return normalize(mix(a, b, ratio)); // Linear interpolation as fallback
215
+ }
216
+
217
+ // Compute the interpolated point using spherical linear interpolation (slerp)
218
+ float sinTheta = sin(theta);
219
+ float factorA = sin((1.0 - ratio) * theta) / sinTheta;
220
+ float factorB = sin(ratio * theta) / sinTheta;
221
+
222
+ vec3 result = factorA * a + factorB * b;
223
+
224
+ // Return the normalized result to ensure it lies on the sphere
225
+ return normalize(result);
226
+ }`;
227
+ const slerp = `
228
+ ${pointsOnSphereBetween}
229
+ vec3 slerp(vec3 A, vec3 B, float t) {
230
+ return pointsOnSphereBetween(A, B, t) * mix(length(A), length(B), t);
231
+ }
232
+ `;
233
+ const circleLimpFromLongLatRadCenterCartesian3D_accurate = R + `
234
+ vec3 circleLimpFromLongLatRadCenterCartesian3D_accurate( vec3 geoW, float radius, float angle) {
235
+ vec3 normal = normalize(geoW);
236
+ vec3 tangent1 = cross(normal, vec3(0.0, 0.0, -1.0));
237
+ if ( length(tangent1) < 0.1 ){ tangent1 = cross(normal, vec3(0.0, -1.0, 0.0)); }
238
+ tangent1 = normalize(tangent1);
239
+ // rotate tangent with given angle
240
+ tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);
241
+ float radius_in_angle = radius/R;
242
+ float projected_radius = sin(radius_in_angle) * R / 1000.0;
243
+ return (geoW * cos(radius_in_angle)) + tangent1 * projected_radius;
244
+ }`;
245
+ const circleOnSphere = `
246
+ vec3 rotateVectorAroundAxis(vec3 v, vec3 axis, float angle) {
247
+ float c = cos(angle);
248
+ float s = sin(angle);
249
+ float t = 1.0 - c;
250
+ vec3 normalizedAxis = normalize(axis); // Ensure axis is unit length
251
+
252
+ return vec3(
253
+ (t * normalizedAxis.x * normalizedAxis.x + c) * v.x +
254
+ (t * normalizedAxis.x * normalizedAxis.y - s * normalizedAxis.z) * v.y +
255
+ (t * normalizedAxis.x * normalizedAxis.z + s * normalizedAxis.y) * v.z,
256
+
257
+ (t * normalizedAxis.x * normalizedAxis.y + s * normalizedAxis.z) * v.x +
258
+ (t * normalizedAxis.y * normalizedAxis.y + c) * v.y +
259
+ (t * normalizedAxis.y * normalizedAxis.z - s * normalizedAxis.x) * v.z,
260
+
261
+ (t * normalizedAxis.x * normalizedAxis.z - s * normalizedAxis.y) * v.x +
262
+ (t * normalizedAxis.y * normalizedAxis.z + s * normalizedAxis.x) * v.y +
263
+ (t * normalizedAxis.z * normalizedAxis.z + c) * v.z
264
+ );
265
+
266
+ // Alternative, more compact way using cross and dot products:
267
+ // vec3 crossProd = cross(normalizedAxis, v);
268
+ // float dotProd = dot(normalizedAxis, v);
269
+ // return v * c + crossProd * s + normalizedAxis * dotProd * t;
270
+ }
271
+
272
+ /**
273
+ * @brief Calculates a point on a circle drawn on the surface of a sphere.
274
+ * The sphere is assumed to be centered at the origin (0,0,0).
275
+ * The circle's center on the sphere surface is M, and H is a starting point on the circle.
276
+ * The function returns the point obtained by rotating H around the axis defined by M by angle A.
277
+ *
278
+ * @param M The center point of the circle on the sphere's surface. The vector from the origin to M defines the rotation axis.
279
+ * @param H A starting point on the circle (also on the sphere's surface).
280
+ * @param A The angle of rotation in radians. Use radians(degrees) if your input is in degrees.
281
+ * @return A vec3 representing the calculated point on the sphere's surface.
282
+ */
283
+ vec3 circleOnSphere(vec3 M, vec3 H, float A) {
284
+ // The rotation axis is the vector from the origin to the circle's center point M on the sphere.
285
+ // This axis vector needs to be normalized for the rotation formula.
286
+ vec3 rotationAxis = normalize(M);
287
+
288
+ // Rotate the starting point H around the rotation axis by angle A.
289
+ vec3 rotatedPoint = rotateVectorAroundAxis(H, rotationAxis, A);
290
+
291
+ // Optional but recommended: Re-normalize the result to ensure it stays exactly on the sphere's surface,
292
+ // counteracting potential floating-point inaccuracies, especially if the original sphere radius was 1.
293
+ // If the sphere has a different radius R, you might want to normalize and multiply by R:
294
+ // float radius = length(M); // Assuming M is exactly on the surface
295
+ // return normalize(rotatedPoint) * radius;
296
+ // If it's a unit sphere:
297
+ // return normalize(rotatedPoint);
298
+
299
+ // For simplicity, returning the direct result of rotation. Assume M and H were perfectly on the sphere.
300
+ return rotatedPoint;
301
+ }`;
302
+ const circleLimpFromLongLatRadCenterMercatorCompass_accurate = `
303
+ vec2 circleLimpFromLongLatRadCenterMercatorCompass_accurate(vec2 center, float radius, float angle){
304
+ float y = -sin(angle) * radius + center.y;
305
+ float x = cos(angle) * radius + center.x;
306
+ return vec2(x, y);
307
+ } `;
43
308
  //TODO make it work...
44
- var circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate = exports.PI + "\nvec2 circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(vec2 mercator_center, float radius, float angle) {\n vec2 center = vec2(mercator_center.x /6378137.0 , asin(tanh(mercator_center.y / 6378137.0 )));\n float ang = angle + PI / 2.0; // Shift angle to align with +x axis\n float r = radius / R;\n float cos_r = cos(r);\n float sin_r = sin(r);\n\n float sin_lat = sin(center.y) * cos_r + cos(center.y) * sin_r * cos(ang);\n float lat = asin(sin_lat);\n\n float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);\n float longi = center.x + delta_long;\n // float y = mix(-80.5, 80.5, abs(center.y + PI / 2.0));\n vec2 limp = vec2(\n R * longi,\n R * log(tan(PI / 4.0 + lat / 2.0))\n );\n vec2 center_mercator = vec2(\n R * center.x,\n R * log(tan(PI/4.0+ center.y / 2.0))\n );\n return mercator_center - center_mercator + limp;\n}";
45
- exports.circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate = circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate;
309
+ const circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate = PI + `
310
+ vec2 circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(vec2 mercator_center, float radius, float angle) {
311
+ vec2 center = vec2(mercator_center.x /6378137.0 , asin(tanh(mercator_center.y / 6378137.0 )));
312
+ float ang = angle + PI / 2.0; // Shift angle to align with +x axis
313
+ float r = radius / R;
314
+ float cos_r = cos(r);
315
+ float sin_r = sin(r);
316
+
317
+ float sin_lat = sin(center.y) * cos_r + cos(center.y) * sin_r * cos(ang);
318
+ float lat = asin(sin_lat);
319
+
320
+ float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
321
+ float longi = center.x + delta_long;
322
+ // float y = mix(-80.5, 80.5, abs(center.y + PI / 2.0));
323
+ vec2 limp = vec2(
324
+ R * longi,
325
+ R * log(tan(PI / 4.0 + lat / 2.0))
326
+ );
327
+ vec2 center_mercator = vec2(
328
+ R * center.x,
329
+ R * log(tan(PI/4.0+ center.y / 2.0))
330
+ );
331
+ return mercator_center - center_mercator + limp;
332
+ }`;
333
+ export { slerp, circleLimpFromLongLatRadCenterCartesian3D_accurate, circleLimpFromLongLatRadCenterMercatorCompass_accurate, circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate, circleOnSphere, };
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./geometrytransformations"), exports);
18
- __exportStar(require("./nodata"), exports);
1
+ export * from './geometrytransformations';
2
+ export * from './nodata';
@@ -1,5 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vertexIDtoTextureCoordinate = void 0;
4
- var vertexIDtoTextureCoordinate = "\nvec2 vertexIDtoTextureCoordinate(float id, vec2 textureDimentions) {\n float x = mod(id, textureDimentions.x);\n float y = floor(id / textureDimentions.x);\n return vec2( x / textureDimentions.x, y / textureDimentions.y);\n}\n";
5
- exports.vertexIDtoTextureCoordinate = vertexIDtoTextureCoordinate;
1
+ const vertexIDtoTextureCoordinate = `
2
+ vec2 vertexIDtoTextureCoordinate(float id, vec2 textureDimentions) {
3
+ float x = mod(id, textureDimentions.x);
4
+ float y = floor(id / textureDimentions.x);
5
+ return vec2( x / textureDimentions.x, y / textureDimentions.y);
6
+ }
7
+ `;
8
+ export { vertexIDtoTextureCoordinate };