@pirireis/webglobeplugins 0.9.9 → 0.9.10

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 (211) hide show
  1. package/Math/angle-calculation.js +15 -0
  2. package/Math/arc.js +65 -0
  3. package/Math/bounds/line-bbox.js +188 -0
  4. package/Math/constants.js +9 -0
  5. package/Math/frustum/camera.js +24 -0
  6. package/Math/frustum/from-globeinfo.js +48 -0
  7. package/Math/frustum/types.js +2 -0
  8. package/Math/globe-util/horizon-plane.js +112 -0
  9. package/Math/index.js +1 -0
  10. package/Math/juction/arc-plane.js +83 -0
  11. package/Math/juction/line-sphere.js +25 -0
  12. package/Math/juction/plane-plane.js +58 -0
  13. package/Math/line.js +56 -0
  14. package/Math/matrix4.js +1 -0
  15. package/Math/methods.js +201 -0
  16. package/Math/plane.js +60 -0
  17. package/Math/quaternion.js +104 -0
  18. package/Math/types.js +2 -0
  19. package/Math/utils.js +4 -0
  20. package/Math/vec3.js +126 -0
  21. package/algorithms/search-binary.js +19 -0
  22. package/altitude-locator/adaptors.js +1 -0
  23. package/altitude-locator/draw-subset-obj.js +18 -0
  24. package/altitude-locator/keymethod.js +1 -0
  25. package/altitude-locator/plugin.js +341 -0
  26. package/altitude-locator/types.js +23 -0
  27. package/arrowfield/adaptor.js +14 -0
  28. package/arrowfield/index.js +10 -0
  29. package/arrowfield/plugin.js +86 -0
  30. package/bearing-line/index.js +8 -0
  31. package/bearing-line/plugin.js +449 -0
  32. package/circle-line-chain/chain-list-map.js +205 -0
  33. package/circle-line-chain/init.js +1 -0
  34. package/circle-line-chain/plugin.js +424 -0
  35. package/circle-line-chain/util.js +5 -0
  36. package/compass-rose/compass-rose-padding-flat.js +225 -0
  37. package/compass-rose/compass-text-writer.js +153 -0
  38. package/compass-rose/index.js +7 -0
  39. package/compassrose/compassrose.js +296 -0
  40. package/compassrose/index.js +8 -0
  41. package/globe-types.js +1 -0
  42. package/heatwave/index.js +10 -0
  43. package/heatwave/isobar/objectarraylabels.js +202 -0
  44. package/heatwave/isobar/plugin.js +343 -0
  45. package/heatwave/isobar/quadtreecontours.js +300 -0
  46. package/heatwave/plugins/heatwaveglobeshell.js +206 -0
  47. package/jest.config.js +7 -0
  48. package/package.json +4 -4
  49. package/partialrings/buffer-manager.js +81 -0
  50. package/partialrings/index.js +41 -0
  51. package/partialrings/plugin.js +135 -0
  52. package/partialrings/program.js +286 -0
  53. package/pin/pin-object-array.js +305 -0
  54. package/pin/pin-point-totem.js +60 -0
  55. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
  56. package/point-heat-map/index.js +1 -0
  57. package/point-heat-map/plugin-webworker.js +126 -0
  58. package/point-heat-map/point-to-heat-map-flow.js +127 -0
  59. package/point-tracks/key-methods.js +5 -0
  60. package/point-tracks/plugin.js +338 -0
  61. package/programs/arrowfield/index.js +7 -0
  62. package/programs/arrowfield/logic.js +257 -0
  63. package/programs/arrowfield/object.js +66 -0
  64. package/programs/data2legend/density-to-legend.js +101 -0
  65. package/programs/data2legend/point-to-density-texture.js +100 -0
  66. package/programs/float2legendwithratio/index.js +8 -0
  67. package/programs/float2legendwithratio/logic.js +171 -0
  68. package/programs/float2legendwithratio/object.js +110 -0
  69. package/programs/globe-util/is-globe-moved.js +21 -0
  70. package/programs/globeshell/index.js +8 -0
  71. package/programs/globeshell/noise/noises.js +1 -0
  72. package/programs/globeshell/wiggle/index.js +8 -0
  73. package/programs/globeshell/wiggle/logic.js +345 -0
  74. package/programs/globeshell/wiggle/object.js +72 -0
  75. package/programs/helpers/blender/index.js +1 -0
  76. package/programs/helpers/blender/program.js +79 -0
  77. package/programs/helpers/fadeaway/index.js +7 -0
  78. package/programs/helpers/fadeaway/logic.js +72 -0
  79. package/programs/helpers/fadeaway/object.js +20 -0
  80. package/programs/helpers/index.js +8 -0
  81. package/programs/index.js +58 -0
  82. package/programs/interface.js +1 -0
  83. package/programs/line-on-globe/angled-line.js +176 -0
  84. package/programs/line-on-globe/circle-accurate-3d.js +141 -0
  85. package/programs/line-on-globe/circle-accurate-flat.js +216 -0
  86. package/programs/line-on-globe/circle-accurate.js +178 -0
  87. package/programs/line-on-globe/circle.js +167 -0
  88. package/programs/line-on-globe/degree-padding-around-circle-3d.js +159 -0
  89. package/programs/line-on-globe/index.js +1 -0
  90. package/programs/line-on-globe/lines-color-instanced-flat.js +136 -0
  91. package/programs/line-on-globe/linestrip.js +171 -0
  92. package/programs/line-on-globe/naive-accurate-flexible.js +195 -0
  93. package/programs/line-on-globe/to-the-surface.js +111 -0
  94. package/programs/line-on-globe/util.js +8 -0
  95. package/programs/picking/pickable-renderer.js +188 -0
  96. package/programs/point-on-globe/element-globe-surface-glow.js +142 -0
  97. package/programs/point-on-globe/element-point-glow.js +153 -0
  98. package/programs/point-on-globe/square-pixel-point.js +174 -0
  99. package/programs/programcache.js +131 -0
  100. package/programs/rings/distancering/circleflatprogram.js +156 -0
  101. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +369 -0
  102. package/programs/rings/distancering/circlepaddysharedbuffer.js +357 -0
  103. package/programs/rings/distancering/index.js +14 -0
  104. package/programs/rings/distancering/paddyflatprogram.js +172 -0
  105. package/programs/rings/distancering/paddyflatprogram2d.js +174 -0
  106. package/programs/rings/distancering/paddyflatprogram3d.js +172 -0
  107. package/programs/rings/distancering/shader.js +1 -0
  108. package/programs/rings/index.js +17 -0
  109. package/programs/rings/partial-ring/piece-of-pie.js +275 -0
  110. package/programs/totems/camerauniformblock.js +160 -0
  111. package/programs/totems/canvas-webglobe-info.js +110 -0
  112. package/programs/totems/gpu-selection-uniform-block.js +108 -0
  113. package/programs/totems/index.js +40 -0
  114. package/programs/two-d/pixel-circle.js +1 -0
  115. package/programs/two-d/pixel-padding-for-compass.js +162 -0
  116. package/programs/util.js +17 -0
  117. package/programs/vectorfields/index.js +23 -0
  118. package/programs/vectorfields/logics/drawrectangleparticles.js +107 -0
  119. package/programs/vectorfields/logics/index.js +12 -0
  120. package/programs/vectorfields/logics/pixelbased.js +142 -0
  121. package/programs/vectorfields/logics/ubo.js +63 -0
  122. package/programs/vectorfields/pingpongbuffermanager.js +76 -0
  123. package/rangerings/enum.js +5 -0
  124. package/rangerings/index.js +15 -0
  125. package/rangerings/plugin.js +560 -0
  126. package/rangerings/rangeringangletext.js +329 -0
  127. package/rangerings/ring-account.js +117 -0
  128. package/shaders/fragment-toy/firework.js +58 -0
  129. package/shaders/fragment-toy/singularity.js +59 -0
  130. package/shape-on-terrain/arc/naive/plugin.js +252 -0
  131. package/timetracks/adaptors-line-strip.js +71 -0
  132. package/timetracks/adaptors.js +122 -0
  133. package/timetracks/index.js +19 -0
  134. package/timetracks/plugin-line-strip.js +250 -0
  135. package/timetracks/plugin.js +258 -0
  136. package/timetracks/program-line-strip.js +611 -0
  137. package/timetracks/program.js +772 -0
  138. package/timetracks/programpoint-line-strip.js +154 -0
  139. package/timetracks/programpoint.js +147 -0
  140. package/types.js +15 -0
  141. package/util/account/bufferoffsetmanager.js +179 -0
  142. package/util/account/index.js +23 -0
  143. package/util/account/single-attribute-buffer-management/buffer-manager.js +108 -0
  144. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +150 -0
  145. package/util/account/single-attribute-buffer-management/index.js +9 -0
  146. package/util/account/single-attribute-buffer-management/object-store.js +51 -0
  147. package/util/account/single-attribute-buffer-management/types.js +2 -0
  148. package/util/account/util.js +22 -0
  149. package/util/algorithms/index.js +1 -0
  150. package/util/algorithms/search-binary.js +28 -0
  151. package/util/check/get.js +18 -0
  152. package/util/check/index.js +1 -0
  153. package/util/check/typecheck.js +49 -0
  154. package/util/geometry/index.js +51 -0
  155. package/util/gl-util/buffer/attribute-loader.js +69 -0
  156. package/util/gl-util/buffer/index.js +6 -0
  157. package/util/gl-util/buffer/types.js +1 -0
  158. package/util/gl-util/draw-options/methods.js +38 -0
  159. package/util/gl-util/draw-options/types.js +15 -0
  160. package/util/gl-util/uniform-block/manager.js +156 -0
  161. package/util/gl-util/uniform-block/shader.js +1 -0
  162. package/util/gl-util/uniform-block/types.js +8 -0
  163. package/util/heatwavedatamanager/datamanager.js +152 -0
  164. package/util/heatwavedatamanager/index.js +10 -0
  165. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -0
  166. package/util/heatwavedatamanager/pointcoordsmeta.js +20 -0
  167. package/util/index.js +57 -0
  168. package/util/interpolation/index.js +1 -0
  169. package/util/interpolation/timetrack/index.js +5 -0
  170. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -0
  171. package/util/interpolation/timetrack/web-worker-str.js +183 -0
  172. package/util/interpolation/timetrack/web-worker.js +48 -0
  173. package/util/jshelpers/data-filler.js +20 -0
  174. package/util/jshelpers/equality.js +20 -0
  175. package/util/jshelpers/index.js +37 -0
  176. package/util/jshelpers/timefilters.js +32 -0
  177. package/util/picking/fence.js +46 -0
  178. package/util/picking/picker-displayer.js +139 -0
  179. package/util/programs/draw-texture-on-canvas.js +89 -0
  180. package/util/programs/index.js +17 -0
  181. package/util/programs/shapesonglobe.js +214 -0
  182. package/util/programs/supersampletotextures.js +113 -0
  183. package/util/programs/texturetoglobe.js +182 -0
  184. package/util/shaderfunctions/geometrytransformations.js +340 -0
  185. package/util/shaderfunctions/index.js +18 -0
  186. package/util/shaderfunctions/nodata.js +11 -0
  187. package/util/shaderfunctions/noisefunctions.js +43 -0
  188. package/util/surface-line-data/arc-bboxes.js +25 -0
  189. package/util/surface-line-data/arcs-to-cuts.js +50 -0
  190. package/util/surface-line-data/cut-arc.js +1 -0
  191. package/util/surface-line-data/flow.js +28 -0
  192. package/util/surface-line-data/rbush-manager.js +1 -0
  193. package/util/surface-line-data/types.js +1 -0
  194. package/util/surface-line-data/web-worker.js +1 -0
  195. package/util/webglobe/gldefaultstates.js +7 -0
  196. package/util/webglobe/index.js +18 -0
  197. package/util/webglobe/rasteroverlay.js +78 -0
  198. package/util/webglobjectbuilders.js +388 -0
  199. package/util/webglobjectbuilders1.js +237 -0
  200. package/waveparticles/adaptor.js +17 -0
  201. package/waveparticles/index.js +10 -0
  202. package/waveparticles/plugin.js +266 -0
  203. package/wind/imagetovectorfieldandmagnitude.js +35 -0
  204. package/wind/index.js +14 -0
  205. package/wind/plugin.js +926 -0
  206. package/wind/vectorfieldimage.js +25 -0
  207. package/write-text/attached-text-writer.js +91 -0
  208. package/write-text/context-text.js +98 -0
  209. package/write-text/context-text3.js +155 -0
  210. package/write-text/index.js +5 -0
  211. package/write-text/writer-plugin.js +8 -0
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UniformBlockManager = void 0;
4
+ require("./types");
5
+ const typeSizes = {
6
+ 'float': 4,
7
+ 'vec2': 8,
8
+ 'vec3': 16, // vec3 takes up same space as vec4 due to alignment
9
+ 'vec4': 16,
10
+ 'mat2': 32, // 2 vec4s (16 * 2)
11
+ 'mat3': 48, // 3 vec4s (16 * 3)
12
+ 'mat4': 64, // 4 vec4s (16 * 4)
13
+ 'int': 4,
14
+ 'ivec2': 8,
15
+ 'ivec3': 16,
16
+ 'ivec4': 16,
17
+ 'bool': 4
18
+ };
19
+ const typeAlignments = {
20
+ 'float': 4,
21
+ 'vec2': 8,
22
+ 'vec3': 16,
23
+ 'vec4': 16,
24
+ 'mat2': 16, // aligns to vec4 boundary
25
+ 'mat3': 16, // aligns to vec4 boundary
26
+ 'mat4': 16, // aligns to vec4 boundary
27
+ 'int': 4,
28
+ 'ivec2': 8,
29
+ 'ivec3': 16,
30
+ 'ivec4': 16,
31
+ 'bool': 4
32
+ };
33
+ const typeArrayConstructors = {
34
+ 'float': Float32Array,
35
+ 'vec2': Float32Array,
36
+ 'vec3': Float32Array,
37
+ 'vec4': Float32Array,
38
+ 'mat2': Float32Array,
39
+ 'mat3': Float32Array,
40
+ 'mat4': Float32Array,
41
+ 'int': Int32Array,
42
+ 'ivec2': Int32Array,
43
+ 'ivec3': Int32Array,
44
+ 'ivec4': Int32Array,
45
+ 'bool': Float32Array
46
+ };
47
+ class UniformBlockManager {
48
+ constructor(blockName, blockMembers, bindingPoint, prefix = "") {
49
+ this.blockName = blockName;
50
+ this.blockMembers = blockMembers;
51
+ this.bindingPoint = bindingPoint;
52
+ this.prefix = prefix;
53
+ this.offsetMap = this.__create_LayoutSTD140_OffsetMap();
54
+ this.size = this.__calculateSize();
55
+ }
56
+ glslCode() {
57
+ let code = `layout(std140) uniform ${this.blockName} {`;
58
+ for (const member of this.blockMembers) {
59
+ const { name, type } = member;
60
+ code += `${type} ${this.prefix}${name};`;
61
+ }
62
+ if (this.prefix) {
63
+ code += `} ${this.prefix};`;
64
+ }
65
+ else {
66
+ code += `};`;
67
+ }
68
+ return code;
69
+ }
70
+ createUBO(gl, bufferWriteType = "STATIC_DRAW") {
71
+ const ubo = gl.createBuffer();
72
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
73
+ // @ts-ignore
74
+ gl.bufferData(gl.UNIFORM_BUFFER, this.size, gl[bufferWriteType]);
75
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
76
+ for (const member of this.blockMembers) {
77
+ const { name, type, value = null } = member;
78
+ ;
79
+ const offset = this.offsetMap.get(name);
80
+ const data = (value === null) ? new typeArrayConstructors[type](typeSizes[type] / 4).fill(NaN) : value;
81
+ gl.bufferSubData(gl.UNIFORM_BUFFER, offset, data);
82
+ }
83
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
84
+ return {
85
+ ubo,
86
+ update: (nameValueMap) => this.updateUBO(gl, ubo, nameValueMap),
87
+ bind: () => this.bind(gl, ubo),
88
+ unbind: () => this.unbind(gl),
89
+ free: () => gl.deleteBuffer(ubo),
90
+ };
91
+ }
92
+ updateUBO(gl, ubo, nameValueMap) {
93
+ gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
94
+ for (const [name, value] of nameValueMap.entries()) {
95
+ const offset = this.offsetMap.get(name);
96
+ if (offset === undefined) {
97
+ throw new Error(`Uniform block member ${name} not found in offset map.`);
98
+ }
99
+ // @ts-ignore
100
+ const type = this.blockMembers.find(member => member.name === name).type;
101
+ let data;
102
+ if (Array.isArray(value)) {
103
+ data = new typeArrayConstructors[type](value);
104
+ }
105
+ else if (typeof value === 'number') {
106
+ data = new typeArrayConstructors[type]([value]);
107
+ }
108
+ else if (value instanceof ArrayBuffer) {
109
+ data = new typeArrayConstructors[type](value);
110
+ }
111
+ else if (ArrayBuffer.isView(value) && !(value instanceof DataView))
112
+ data = (typeof value === 'number') ? new typeArrayConstructors[type]([value]) : new typeArrayConstructors[type](value);
113
+ else {
114
+ throw new Error(`Unsupported value type for ${name}: ${typeof value}`);
115
+ }
116
+ console.log("Data to be uploaded:", data);
117
+ gl.bufferSubData(gl.UNIFORM_BUFFER, offset, data);
118
+ }
119
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
120
+ }
121
+ // call this after linking the program
122
+ assignBindingPoint(gl, program) {
123
+ const blockIndex = gl.getUniformBlockIndex(program, this.blockName);
124
+ gl.uniformBlockBinding(program, blockIndex, this.bindingPoint);
125
+ }
126
+ // call this before drawing
127
+ bind(gl, ubo) {
128
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this.bindingPoint, ubo);
129
+ }
130
+ // call this right after drawing
131
+ unbind(gl) {
132
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this.bindingPoint, null);
133
+ }
134
+ // implicit methods
135
+ __create_LayoutSTD140_OffsetMap() {
136
+ let offset = 0;
137
+ const offsetMap = new Map();
138
+ for (const member of this.blockMembers) {
139
+ const { name, type } = member;
140
+ const size = typeSizes[type];
141
+ const alignment = typeAlignments[type];
142
+ const padding = (alignment - (offset % alignment)) % alignment;
143
+ offset += padding;
144
+ offsetMap.set(name, offset);
145
+ offset += size;
146
+ }
147
+ return offsetMap;
148
+ }
149
+ // __create_LayoutSTD140_OffsetMap() should be called before this
150
+ __calculateSize() {
151
+ const lastOffset = Array.from(this.offsetMap.values()).pop() || 0;
152
+ const lastItemAlignment = typeAlignments[this.blockMembers[this.blockMembers.length - 1].type];
153
+ return lastOffset + lastItemAlignment;
154
+ }
155
+ }
156
+ exports.UniformBlockManager = UniformBlockManager;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * @typedef {string} UniformBlockName
4
+ *
5
+ * @typedef {string} GLSLType | mat4, mat3, vec4, vec3, vec2, float, int, bool
6
+ * @typedef {{name: string, type: GLSLType, value: null|Float32Array}} UniformBlockMember
7
+ *
8
+ */
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ /**
3
+ * todo:
4
+ * data must be processed before being set to the cache
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ class DataManager {
8
+ /**
9
+ *
10
+ * @param {Array<number>} timeEpocs | array of time epocs
11
+ * @param {Function} fetchMethod | fetchMethod(time) => Promise<data>
12
+ * @param {boolean} autoDownload | auto download data or not
13
+ */
14
+ constructor(timeEpocs, fetchMethod, { autoDownload = true } = {}) {
15
+ this._timeEpocs = timeEpocs.sort((a, b) => a - b);
16
+ this._datas = [];
17
+ this._datas.length = timeEpocs.length;
18
+ // in construction
19
+ this._dataPromises = [];
20
+ this._dataPromises.length = timeEpocs.length;
21
+ this._fetchMethod = fetchMethod;
22
+ this._callbackmethods = [];
23
+ this._callbackmethodOwners = [];
24
+ this._lastTime = -1;
25
+ this._lastIndex = -1;
26
+ this.autoDownload(autoDownload);
27
+ }
28
+ autoDownload(bool, time) {
29
+ if (!bool) {
30
+ this._autoDownload = false;
31
+ return;
32
+ }
33
+ let index = this._lastIndex === -1 ? 0 : this._lastIndex;
34
+ if (time !== undefined) {
35
+ if (time < this._timeEpocs[0] || time > this._timeEpocs[this._timeEpocs.length - 1]) {
36
+ this._autoDownload = bool;
37
+ return;
38
+ }
39
+ index = this._findIndex(time);
40
+ }
41
+ if (this._downloadStartIndex === index && this._autoDownload === bool)
42
+ return;
43
+ this._downloadStartIndex = index;
44
+ this._autoDownload = bool;
45
+ const recursion = (startId, currentDownloadId) => {
46
+ if (startId !== this._downloadStartIndex)
47
+ return;
48
+ if (currentDownloadId < this._timeEpocs.length && this._autoDownload) {
49
+ this._getData(currentDownloadId).then(() => {
50
+ recursion(startId, currentDownloadId + 1);
51
+ });
52
+ }
53
+ };
54
+ recursion(index, index);
55
+ // save index as start index
56
+ //start recursive download
57
+ // use started id as a flag to stop the download
58
+ }
59
+ /**
60
+ * @param {number} time
61
+ * It looks like async function is not needed here. changes just overwrites the previous changes.
62
+ */
63
+ updateTime(time) {
64
+ if (time < this._timeEpocs[0] || time > this._timeEpocs[this._timeEpocs.length - 1]) {
65
+ this._dontRender();
66
+ return;
67
+ }
68
+ this._lastTime = time;
69
+ const index = this._findIndex(time);
70
+ const ratio = this._getRatio(time, index);
71
+ Promise.all([this._getData(index - 1), this._getData(index)]).then((datas) => {
72
+ if (this._lastTime === time) {
73
+ this._lastIndex = index;
74
+ this._ratio = ratio;
75
+ this._pushCallback(ratio, datas);
76
+ }
77
+ });
78
+ }
79
+ register(key, callback) {
80
+ if (this._callbackmethodOwners.indexOf(key) !== -1) {
81
+ console.warn("key already registered, old one is unregistered");
82
+ this.unregister(key);
83
+ }
84
+ this._callbackmethods.push(callback);
85
+ this._callbackmethodOwners.push(key);
86
+ if (this._lastIndex !== -1)
87
+ callback(this._ratio, this._datas[this._lastIndex - 1], this._datas[this._lastIndex]);
88
+ }
89
+ /**
90
+ * @param {*} key | id of the owner of the callback
91
+ */
92
+ unregister(key) {
93
+ let index = this._callbackmethodOwners.indexOf(key);
94
+ if (index !== -1) {
95
+ this._callbackmethods.splice(index, 1);
96
+ this._callbackmethodOwners.splice(index, 1);
97
+ }
98
+ if (this._callbackmethods.length === 0) {
99
+ this.free();
100
+ }
101
+ }
102
+ free() {
103
+ this._callbackmethods = [];
104
+ this._callbackmethodOwners = [];
105
+ this._autoDownload = false;
106
+ }
107
+ _findIndex(time) {
108
+ const { _timeEpocs } = this;
109
+ let index = this._lastIndex === -1 ? 1 : this._lastIndex;
110
+ if (this)
111
+ if (time < _timeEpocs[index - 1]) {
112
+ while (index > 1 && time < _timeEpocs[index - 1]) {
113
+ index--;
114
+ }
115
+ }
116
+ else if (time > _timeEpocs[index]) {
117
+ while (index < _timeEpocs.length - 1 && time > _timeEpocs[index]) {
118
+ index++;
119
+ }
120
+ }
121
+ return index;
122
+ }
123
+ _getRatio(time, index) {
124
+ return (time - this._timeEpocs[index - 1]) / (this._timeEpocs[index] - this._timeEpocs[index - 1]);
125
+ }
126
+ _pushCallback(ratio, datas) {
127
+ for (let i = 0; i < this._callbackmethods.length; i++) {
128
+ this._callbackmethods[i](ratio, ...datas);
129
+ }
130
+ }
131
+ async _getData(index) {
132
+ if (index < 0 || index >= this._timeEpocs.length) {
133
+ throw new Error("Index out of range");
134
+ }
135
+ if (!this._datas[index]) {
136
+ if (!this._dataPromises[index])
137
+ this._dataPromises[index] = this._fetchMethod(this._timeEpocs[index]).then((data) => {
138
+ this._datas[index] = data;
139
+ }, (error) => {
140
+ console.error("error", error);
141
+ }).finally(() => {
142
+ this._dataPromises[index] = null;
143
+ });
144
+ }
145
+ await this._dataPromises[index];
146
+ return this._datas[index];
147
+ }
148
+ _dontRender() {
149
+ this._pushCallback(0, [null, null]);
150
+ }
151
+ }
152
+ exports.default = DataManager;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PointCoordinatesDataCalculator = exports.HeatWaveDataManager = void 0;
7
+ const pointcoordinatesdatacalculator_1 = __importDefault(require("./pointcoordinatesdatacalculator"));
8
+ exports.PointCoordinatesDataCalculator = pointcoordinatesdatacalculator_1.default;
9
+ const datamanager_1 = __importDefault(require("./datamanager"));
10
+ exports.HeatWaveDataManager = datamanager_1.default;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const pointcoordsmeta_1 = __importDefault(require("./pointcoordsmeta"));
7
+ const pointObject = (long, lat, posIndex, callback) => {
8
+ return { long, lat, posIndex, callback };
9
+ };
10
+ class PointCoordinatesDataCalculator {
11
+ constructor(bbox, width, height) {
12
+ this._pointObjects = {};
13
+ this._ratio = 0.0;
14
+ this._bbox = bbox;
15
+ this._width = width;
16
+ this._height = height;
17
+ this._metaCalculater = new pointcoordsmeta_1.default(bbox, width, height);
18
+ this._texture0 = null;
19
+ this._texture1 = null;
20
+ }
21
+ /**
22
+ *
23
+ * @param {*} key
24
+ * @param {*} lat
25
+ * @param {*} long
26
+ * @param {*} callback | callback(data0, data1, interpolated)
27
+ */
28
+ registerPoint(key, long, lat, callback) {
29
+ if (key in this._pointObjects) {
30
+ console.warn("key already registered, old one is unregistered");
31
+ this.unregisterPoint(key);
32
+ }
33
+ if (!this._isInBBox(long, lat))
34
+ return false;
35
+ const meta = this._metaCalculater.getFlooredMeta(long, lat);
36
+ this._pointObjects[key] = pointObject(long, lat, meta.index, callback);
37
+ if (this._texture0 && this._texture1) {
38
+ const { data0, data1, interpolated } = this._findAPoint(meta.index);
39
+ callback(data0, data1, interpolated);
40
+ }
41
+ return true;
42
+ }
43
+ _isInBBox(long, lat) {
44
+ return lat >= this._bbox[1] && lat <= this._bbox[3] && long >= this._bbox[0] && long <= this._bbox[2];
45
+ }
46
+ unregisterPoint(key) {
47
+ if (!(key in this._pointObjects))
48
+ return false;
49
+ delete this._pointObjects[key];
50
+ return true;
51
+ }
52
+ updatePoint(key, long, lat) {
53
+ if (!(key in this._pointObjects))
54
+ return false;
55
+ if (!this._isInBBox(long, lat))
56
+ return false;
57
+ this._pointObjects[key].long = long;
58
+ this._pointObjects[key].lat = lat;
59
+ const meta = this._metaCalculater.getFlooredMeta(long, lat);
60
+ this._pointObjects[key].posIndex = meta.index;
61
+ const { data0, data1, interpolated } = this._findAPoint(meta.index);
62
+ this._pointObjects[key].callback(data0, data1, interpolated);
63
+ return true;
64
+ }
65
+ /**
66
+ * @param {Number} ratio 0-1
67
+ * @param {} textureData0
68
+ * @param {*} textureData1
69
+ */
70
+ updateData(ratio, textureData0 = null, textureData1 = null) {
71
+ if (!textureData0 && !textureData1) {
72
+ this._pushPointCallBackEmpty();
73
+ return;
74
+ }
75
+ if (textureData0 && textureData1) {
76
+ this._texture0 = textureData0;
77
+ this._texture1 = textureData1;
78
+ }
79
+ this._ratio = ratio;
80
+ this._pushPointCallbackAll();
81
+ }
82
+ _findAPoint(posIndex) {
83
+ const data0 = this._texture0[posIndex];
84
+ const data1 = this._texture1[posIndex];
85
+ const interpolated = data0 * (1 - this._ratio) + data1 * this._ratio;
86
+ return { data0, data1, interpolated };
87
+ }
88
+ _pushPointCallbackAll() {
89
+ for (const key in this._pointObjects) {
90
+ const { posIndex, callback } = this._pointObjects[key];
91
+ const { data0, data1, interpolated } = this._findAPoint(posIndex);
92
+ callback(data0, data1, interpolated);
93
+ }
94
+ }
95
+ _pushPointCallBackEmpty() {
96
+ for (const key in this._pointObjects) {
97
+ const { callback } = this._pointObjects[key];
98
+ callback(null, null, null);
99
+ }
100
+ }
101
+ flush() {
102
+ this._pointObjects = {};
103
+ }
104
+ }
105
+ exports.default = PointCoordinatesDataCalculator;
106
+ // function test() {
107
+ // const cp = window.plugin.getPointCoordinatesDataCalculator();
108
+ // const bbox = [-15, 25, 70, 60];
109
+ // cp.registerPoint("left up", -15, 60, (data0, data1, interpolated) => {
110
+ // console.log("left up", data0, data1, interpolated);
111
+ // });
112
+ // cp.registerPoint("right up", 70, 60, (data0, data1, interpolated) => {
113
+ // console.log("right up", data0, data1, interpolated);
114
+ // });
115
+ // cp.registerPoint("left down", -15, 25, (data0, data1, interpolated) => {
116
+ // console.log("right down", data0, data1, interpolated);
117
+ // });
118
+ // cp.registerPoint("right down", 70, 25, (data0, data1, interpolated) => {
119
+ // console.log("right down", data0, data1, interpolated);
120
+ // });
121
+ // return cp;
122
+ // }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PointCoordsMeta {
4
+ constructor(bbox, width, height) {
5
+ this._bbox = bbox;
6
+ this._width = width;
7
+ this._height = height;
8
+ this._xRatio = this._width / (this._bbox[2] - this._bbox[0]);
9
+ this._yRatio = this._height / (this._bbox[3] - this._bbox[1]);
10
+ }
11
+ getFlooredMeta(long, lat) {
12
+ let x = (long - this._bbox[0]) * this._xRatio;
13
+ let y = (this._bbox[3] - lat) * this._yRatio;
14
+ x = x > 0 ? x - 1 : 0;
15
+ y = y > 0 ? y - 1 : 0;
16
+ const index = Math.floor(y) * this._width + Math.floor(x);
17
+ return { index };
18
+ }
19
+ }
20
+ exports.default = PointCoordsMeta;
package/util/index.js ADDED
@@ -0,0 +1,57 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.heatwavedatamanager = exports.programs = exports.webglobe = exports.geometry = exports.shaderfunctions = exports.webglobjectbuilders = void 0;
40
+ const webglobjectbuilders = __importStar(require("./webglobjectbuilders"));
41
+ exports.webglobjectbuilders = webglobjectbuilders;
42
+ const shaderfunctions = __importStar(require("./shaderfunctions"));
43
+ exports.shaderfunctions = shaderfunctions;
44
+ const geometry = __importStar(require("./geometry"));
45
+ exports.geometry = geometry;
46
+ const webglobe = __importStar(require("./webglobe"));
47
+ exports.webglobe = webglobe;
48
+ const programs = __importStar(require("./programs"));
49
+ exports.programs = programs;
50
+ const heatwavedatamanager = __importStar(require("./heatwavedatamanager"));
51
+ exports.heatwavedatamanager = heatwavedatamanager;
52
+ __exportStar(require("./webglobe"), exports);
53
+ __exportStar(require("./webglobjectbuilders"), exports);
54
+ __exportStar(require("./shaderfunctions"), exports);
55
+ __exportStar(require("./geometry"), exports);
56
+ __exportStar(require("./programs"), exports);
57
+ __exportStar(require("./heatwavedatamanager"), exports);
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWorker = void 0;
4
+ const createWorker = () => new Worker(new URL('./web-worker.js', import.meta.url), { type: 'module' });
5
+ exports.createWorker = createWorker;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GEOMETRY = exports.TimeTrackInterpolator = void 0;
4
+ const search_binary_1 = require("../../algorithms/search-binary");
5
+ const methods_1 = require("../../../Math/methods");
6
+ /**
7
+ * @typedef {Array<number>} vec3 [x, y, z]
8
+ * @typedef {Array<number>} vec2 [x, y]
9
+ * @typedef {Array<number>} vec4 [x, y, z, w]
10
+ * @typedef {number} fraction a number between 0 and 1
11
+ * @typedef {Array<number>} wgs84 [long, lat]
12
+ */
13
+ const GEOMETRY = Object.freeze({
14
+ CARTESIAN3D: 0,
15
+ MERCATOR: 1,
16
+ });
17
+ exports.GEOMETRY = GEOMETRY;
18
+ class TimeTrackInterpolator {
19
+ /**
20
+ * @typedef Timetrack
21
+ * @property {Array<vec4>}} coordinates [x,y,z, length]
22
+ * @property {Array<Number>} times
23
+ * @param {Array<Timetrack>} timeTracks
24
+ */
25
+ constructor({ timeTracks, bbox = null, geometry = GEOMETRY.CARTESIAN3D } = {}) {
26
+ this.timeTracks = null;
27
+ this.timeTracksStartTimes = null;
28
+ this.geometry = geometry;
29
+ if (timeTracks)
30
+ this.setTimetracks(timeTracks);
31
+ if (bbox)
32
+ this.setBbox(bbox);
33
+ }
34
+ setGeometry(geometry) {
35
+ if (geometry !== GEOMETRY.CARTESIAN3D && geometry !== GEOMETRY.MERCATOR) {
36
+ throw new Error('Invalid geometry');
37
+ }
38
+ this.geometry = geometry;
39
+ }
40
+ setTimetracks(timeTracks) {
41
+ this.timeTracks = timeTracks;
42
+ }
43
+ interpolate(time) {
44
+ const { timeTracks, geometry } = this;
45
+ if (!timeTracks) {
46
+ return null;
47
+ }
48
+ const resultArray = [];
49
+ const info = {
50
+ outOfRange: 0,
51
+ processed: 0,
52
+ };
53
+ for (let i = 0; i < timeTracks.length; i++) {
54
+ const { times, coordinates } = timeTracks[i];
55
+ if (times[times.length - 1] < time)
56
+ continue;
57
+ info.processed++;
58
+ const timeIndex = (0, search_binary_1.findFirstIndexInRange)(times, time);
59
+ if (timeIndex === null) {
60
+ info.outOfRange++;
61
+ continue;
62
+ }
63
+ const timeFraction = (time - times[timeIndex]) / (times[timeIndex + 1] - times[timeIndex]);
64
+ const interpolated = (geometry === GEOMETRY.CARTESIAN3D) ?
65
+ (0, methods_1.sphericalLinearInterpolation_Cartesian3d)(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction) :
66
+ (0, methods_1.sphericalLinearInterpolation_Mercator)(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction);
67
+ resultArray.push(...interpolated);
68
+ }
69
+ return new Float32Array(resultArray);
70
+ }
71
+ // implicit methods
72
+ _orderTimeTracks() {
73
+ this.timeTracks.sort((a, b) => a.times[0] - b.times[0]);
74
+ }
75
+ _setStartTimes() {
76
+ this.timeTracksStartTimes = this.timeTracks.map(tt => tt.times[0]);
77
+ }
78
+ }
79
+ exports.TimeTrackInterpolator = TimeTrackInterpolator;