@pirireis/webglobeplugins 0.16.7 → 0.17.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 (152) hide show
  1. package/Math/angle-calculation.js +1 -0
  2. package/Math/contour/quadtreecontours.js +300 -0
  3. package/Math/finite-line-2d.js +58 -0
  4. package/Math/tessellation/hybrid-triangle-tessellation-meta.js +123 -0
  5. package/Math/tessellation/tile-merger.js +56 -0
  6. package/Math/tessellation/triangle-tessellation-meta.js +178 -32
  7. package/Math/tessellation/triangle-tessellation.js +5 -1
  8. package/compass-rose/compass-text-writer.js +39 -33
  9. package/constants.js +3 -0
  10. package/{util/heatwavedatamanager → heatwave}/datamanager.js +1 -1
  11. package/heatwave/{plugins/heatwaveglobeshell.js → heatwave.js} +8 -6
  12. package/heatwave/index.js +5 -3
  13. package/heatwave/{isobar/plugin.js → isobar.js} +6 -5
  14. package/{util/heatwavedatamanager → heatwave}/texture-point-sampler.js +24 -3
  15. package/package.json +4 -2
  16. package/programs/arrowfield/{object.js → arrow-field.js} +1 -1
  17. package/programs/arrowfield/logic.js +1 -1
  18. package/programs/data2legend/density-to-legend.js +24 -29
  19. package/programs/data2legend/point-to-density-texture.js +14 -17
  20. package/programs/float2legendwithratio/logic.js +2 -2
  21. package/programs/float2legendwithratio/object.js +1 -1
  22. package/programs/helpers/{blender/program.js → blender.js} +1 -1
  23. package/programs/helpers/{fadeaway/logic.js → fadeaway.js} +11 -2
  24. package/programs/index.js +20 -9
  25. package/programs/line-on-globe/circle-accurate-3d.js +12 -14
  26. package/programs/line-on-globe/circle-accurate-flat.js +0 -1
  27. package/programs/line-on-globe/degree-padding-around-circle-3d.js +13 -15
  28. package/programs/line-on-globe/lines-color-instanced-flat.js +15 -18
  29. package/programs/line-on-globe/naive-accurate-flexible.js +0 -1
  30. package/programs/picking/pickable-polygon-renderer.js +1 -1
  31. package/programs/picking/pickable-renderer.js +2 -2
  32. package/programs/point-on-globe/element-globe-surface-glow.js +2 -2
  33. package/programs/point-on-globe/element-point-glow.js +1 -1
  34. package/programs/point-on-globe/square-pixel-point.js +1 -1
  35. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +32 -6
  36. package/programs/polygon-on-globe/texture-dem-triangles.js +32 -5
  37. package/programs/rings/partial-ring/piece-of-pie.js +26 -29
  38. package/programs/totems/camerauniformblock.js +31 -42
  39. package/programs/two-d/pixel-padding-for-compass.js +14 -24
  40. package/programs/vectorfields/logics/drawrectangleparticles.js +1 -2
  41. package/programs/vectorfields/logics/pixelbased.js +1 -2
  42. package/programs/vectorfields/pingpongbuffermanager.js +1 -1
  43. package/range-tools-on-terrain/bearing-line/adapters.js +1 -1
  44. package/range-tools-on-terrain/circle-line-chain/adapters.js +0 -5
  45. package/range-tools-on-terrain/circle-line-chain/plugin.js +1 -1
  46. package/range-tools-on-terrain/range-ring/plugin.js +4 -6
  47. package/semiplugins/lightweight/line-plugin.js +0 -1
  48. package/semiplugins/shape-on-terrain/arc-plugin.js +0 -2
  49. package/semiplugins/shape-on-terrain/circle-plugin.js +2 -2
  50. package/semiplugins/shape-on-terrain/padding-1-degree.js +1 -1
  51. package/semiplugins/shell/bbox-renderer/index.js +2 -0
  52. package/{programs/globeshell/wiggle → semiplugins/shell/bbox-renderer}/logic.js +101 -102
  53. package/{programs/globeshell/wiggle → semiplugins/shell/bbox-renderer}/object.js +6 -7
  54. package/semiplugins/utility/container-plugin.js +94 -0
  55. package/semiplugins/utility/object-pass-container-plugin.js +80 -0
  56. package/{point-heat-map → tracks/point-heat-map}/adaptors/timetracksplugin-format-to-this.js +1 -1
  57. package/{point-heat-map → tracks/point-heat-map}/plugin-webworker.js +3 -3
  58. package/{point-heat-map → tracks/point-heat-map}/point-to-heat-map-flow.js +11 -14
  59. package/{point-tracks → tracks/point-tracks}/plugin.js +5 -5
  60. package/{timetracks → tracks/timetracks}/adaptors-line-strip.js +1 -1
  61. package/{timetracks → tracks/timetracks}/program-line-strip.js +49 -49
  62. package/{timetracks → tracks/timetracks}/programpoint-line-strip.js +16 -13
  63. package/types.js +6 -0
  64. package/util/account/bufferoffsetmanager.js +1 -1
  65. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +9 -95
  66. package/util/gl-util/uniform-block/manager.js +0 -1
  67. package/util/gl-util/uniform-block/types.js +0 -7
  68. package/util/index.js +10 -13
  69. package/util/picking/fence.js +16 -18
  70. package/util/picking/picker-displayer.js +4 -6
  71. package/util/programs/{shapesonglobe.js → draw-from-pixel-coords.js} +4 -7
  72. package/util/programs/draw-texture-on-canvas.js +1 -1
  73. package/util/programs/texturetoglobe.js +3 -3
  74. package/util/webglobe/rasteroverlay.js +1 -0
  75. package/vectorfield/arrowfield/index.js +3 -0
  76. package/{arrowfield → vectorfield/arrowfield}/plugin.js +2 -2
  77. package/{waveparticles → vectorfield/waveparticles}/plugin.js +12 -12
  78. package/{wind → vectorfield/wind}/index.js +1 -1
  79. package/{wind → vectorfield/wind}/plugin.js +32 -32
  80. package/write-text/attached-text-writer.js +9 -1
  81. package/write-text/context-text3.js +0 -1
  82. package/write-text/objectarraylabels/index.js +2 -0
  83. package/Math/tessellation/tessellation-algorithm.js +0 -67
  84. package/arrowfield/index.js +0 -3
  85. package/bearing-line/index.js +0 -2
  86. package/bearing-line/plugin.js +0 -444
  87. package/circle-line-chain/chain-list-map.js +0 -201
  88. package/circle-line-chain/plugin.js +0 -411
  89. package/circle-line-chain/util.js +0 -1
  90. package/compassrose/compassrose.js +0 -293
  91. package/compassrose/index.js +0 -2
  92. package/index.js +0 -12
  93. package/partialrings/buffer-manager.js +0 -75
  94. package/partialrings/index.js +0 -2
  95. package/partialrings/plugin.js +0 -128
  96. package/partialrings/program.js +0 -279
  97. package/programs/arrowfield/index.js +0 -2
  98. package/programs/globe-util/is-globe-moved.js +0 -19
  99. package/programs/globeshell/index.js +0 -2
  100. package/programs/globeshell/wiggle/index.js +0 -2
  101. package/programs/helpers/blender/index.js +0 -1
  102. package/programs/helpers/fadeaway/index.js +0 -2
  103. package/programs/helpers/fadeaway/object.js +0 -14
  104. package/programs/helpers/index.js +0 -2
  105. package/programs/rings/distancering/circleflatprogram.js +0 -116
  106. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +0 -326
  107. package/programs/rings/distancering/circlepaddysharedbuffer.js +0 -368
  108. package/programs/rings/distancering/index.js +0 -6
  109. package/programs/rings/distancering/paddyflatprogram.js +0 -127
  110. package/programs/rings/distancering/paddyflatprogram2d.js +0 -129
  111. package/programs/rings/distancering/paddyflatprogram3d.js +0 -128
  112. package/programs/two-d/pixel-circle.js +0 -1
  113. package/programs/vectorfields/index.js +0 -3
  114. package/rangerings/enum.js +0 -2
  115. package/rangerings/index.js +0 -5
  116. package/rangerings/plugin.js +0 -543
  117. package/rangerings/rangeringangletext.js +0 -326
  118. package/rangerings/ring-account.js +0 -112
  119. package/timetracks/index.js +0 -1
  120. package/util/build-strategy/general-strategy.js +0 -62
  121. package/util/gl-util/uniform-block/shader.js +0 -1
  122. package/util/heatwavedatamanager/index.js +0 -2
  123. package/util/heatwavedatamanager/pointcoordsmeta.js +0 -22
  124. package/util/jshelpers/data-filler.js +0 -17
  125. package/util/jshelpers/equality.js +0 -18
  126. package/util/jshelpers/index.js +0 -2
  127. package/util/jshelpers/timefilters.js +0 -30
  128. package/util/programs/index.js +0 -1
  129. package/util/surface-line-data/arc-bboxes.js +0 -25
  130. package/util/surface-line-data/arcs-to-cuts.js +0 -50
  131. package/util/surface-line-data/cut-arc.js +0 -1
  132. package/util/surface-line-data/flow.js +0 -28
  133. package/util/surface-line-data/rbush-manager.js +0 -1
  134. package/util/surface-line-data/types.js +0 -1
  135. package/util/surface-line-data/web-worker.js +0 -1
  136. package/write-text/context-text3old.js +0 -152
  137. package/write-text/index.js +0 -1
  138. package/write-text/writer-plugin.js +0 -8
  139. /package/{heatwave/isobar/quadtreecontours.js → Math/contour/quadtreecontours1.js} +0 -0
  140. /package/pin/{pin-object-array.js → pin-object-array1.js} +0 -0
  141. /package/pin/{pin-point-totem.js → pin-point-totem1.js} +0 -0
  142. /package/{circle-line-chain/init.js → programs/polygon-on-globe/partial-tesselation.js} +0 -0
  143. /package/{point-heat-map → tracks/point-heat-map}/index.js +0 -0
  144. /package/{point-tracks → tracks/point-tracks}/key-methods.js +0 -0
  145. /package/{timetracks → tracks/timetracks}/plugin-line-strip.js +0 -0
  146. /package/{arrowfield → vectorfield/arrowfield}/adaptor.js +0 -0
  147. /package/{waveparticles → vectorfield/waveparticles}/adaptor.js +0 -0
  148. /package/{waveparticles → vectorfield/waveparticles}/index.js +0 -0
  149. /package/{wind → vectorfield/wind}/imagetovectorfieldandmagnitude.js +0 -0
  150. /package/{wind → vectorfield/wind}/vectorfieldimage.js +0 -0
  151. /package/write-text/{context-text.js → context-textDELETE.js} +0 -0
  152. /package/{heatwave/isobar → write-text/objectarraylabels}/objectarraylabels.js +0 -0
@@ -1,3 +1,4 @@
1
+ const Radians = Math.PI / 180;
1
2
  function bearingRealAngle(long, lat, endLong, endLat) {
2
3
  const rLong = Radians * long;
3
4
  const rLat = Radians * lat;
@@ -0,0 +1,300 @@
1
+ // © 2019 3D Robotics. License: Apache-2.0
2
+ const OUTSIDE = 0;
3
+ const ABOVE = 1;
4
+ const BELOW = 2;
5
+ const WITHIN = 3;
6
+ // Build mipmap layer N from layer N+1
7
+ function mipmapReduce({ min, max, width, height, scale }) {
8
+ const outWidth = Math.ceil(width / 2);
9
+ const outHeight = Math.ceil(height / 2);
10
+ function reduceWith(data, reduce) {
11
+ const out = new Float32Array(outWidth * outHeight);
12
+ let x;
13
+ let y;
14
+ for (y = 0; y < Math.floor(height / 2); y++) {
15
+ for (x = 0; x < Math.floor(width / 2); x++) {
16
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)], data[(y * 2 + 1) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 1)]);
17
+ }
18
+ if (x < outWidth) {
19
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 0)]);
20
+ }
21
+ }
22
+ if (y < outHeight) {
23
+ for (x = 0; x < Math.floor(width / 2); x++) {
24
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)]);
25
+ }
26
+ }
27
+ //@ts-ignore
28
+ if (x < outWidth && y < outHeight) {
29
+ //@ts-ignore
30
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)]);
31
+ }
32
+ return out;
33
+ }
34
+ function minFinite(...args) {
35
+ let r = Infinity;
36
+ for (let i = 0; i < args.length; i++) {
37
+ const v = args[i];
38
+ if (v < r)
39
+ r = v;
40
+ }
41
+ return r;
42
+ }
43
+ function maxFinite(...args) {
44
+ let r = -Infinity;
45
+ for (let i = 0; i < args.length; i++) {
46
+ const v = args[i];
47
+ if (v > r)
48
+ r = v;
49
+ }
50
+ return r;
51
+ }
52
+ return {
53
+ min: reduceWith(min, minFinite),
54
+ max: reduceWith(max, maxFinite),
55
+ width: outWidth,
56
+ height: outHeight,
57
+ scale: scale * 2,
58
+ };
59
+ }
60
+ class ContourMipmap {
61
+ levels;
62
+ constructor(raster, width, height) {
63
+ // Bottom mipmap layer is just the raster: at each pixel the minimum and maximum are the same
64
+ this.levels = [{ min: raster, max: raster, width, height, scale: 1 }];
65
+ while (this.levels[0].width > 1 || this.levels[0].height > 1) {
66
+ this.levels.unshift(mipmapReduce(this.levels[0]));
67
+ }
68
+ }
69
+ // Get the minimum elevation in the mipmap
70
+ min() { return this.levels[0].min[0]; }
71
+ // Get the maximum elevation in the mipmap
72
+ max() { return this.levels[0].max[0]; }
73
+ // Get an array of contour levels for a specified contour interval
74
+ intervals(interval) {
75
+ if (interval <= 0)
76
+ throw new Error('Contour interval must be positive');
77
+ const min = this.min();
78
+ const max = this.max();
79
+ const levels = [];
80
+ let level = Math.ceil(min / interval) * interval;
81
+ while (level < max) {
82
+ levels.push(level);
83
+ level += interval;
84
+ }
85
+ return levels;
86
+ }
87
+ // Walk the quadtree for a specified contour level, and pass quadtree nodes
88
+ // and contour line segments to the callbacks. This is used for visualizing
89
+ // the quadtree; in most cases you should use .contour() instead, which
90
+ // assembles the line segments into lines and rings.
91
+ evaluateContour(contourLevel, { maxMipmapLevel }, addLine, addNode) {
92
+ maxMipmapLevel = maxMipmapLevel || this.levels.length - 1;
93
+ // Test the mipmap at the given coordinate and level, returning whether the contour line is ABOVE, BELOW, or WITHIN this mipmap cell
94
+ // If the mipmap is out of bounds or NaN at that point, OUTSIDE is returned.
95
+ const evaluate = (l, x, y) => {
96
+ const ml = this.levels[l];
97
+ const i = ml.width * y + x;
98
+ if (x >= ml.width || y >= ml.height || !Number.isFinite(ml.min[i]) || !Number.isFinite(ml.max[i]))
99
+ return OUTSIDE;
100
+ if (ml.min[i] >= contourLevel)
101
+ return ABOVE;
102
+ if (ml.max[i] < contourLevel)
103
+ return BELOW;
104
+ // If we've reached the maximum mipmap level, arbitrarily decide that cells that contain
105
+ // the contour elevation go inside the contour line.
106
+ if (l >= maxMipmapLevel)
107
+ return ABOVE;
108
+ return WITHIN;
109
+ };
110
+ // Add any vertical contour lines that exist between passed mipmap cell and
111
+ // its horizontal neighbor to the right. If the line exists at this mipmap
112
+ // level, it is added directly, otherwise split the edge and recurse at a
113
+ // more detailed mipmap level.
114
+ const edgeH = (l, x, y) => {
115
+ const e1 = evaluate(l, x, y);
116
+ const e2 = evaluate(l, x + 1, y);
117
+ if (e1 === ABOVE && e2 === BELOW) {
118
+ addLine(l, x + 1, y + 1, x + 1, y);
119
+ }
120
+ else if (e2 === ABOVE && e1 === BELOW) {
121
+ // reverse order of coordinates compared to case above so that lines
122
+ // go counterclockwise around the region above the contour value
123
+ addLine(l, x + 1, y, x + 1, y + 1);
124
+ }
125
+ else if (e1 === WITHIN || e2 === WITHIN) {
126
+ edgeH(l + 1, x * 2 + 1, y * 2 + 0);
127
+ edgeH(l + 1, x * 2 + 1, y * 2 + 1);
128
+ }
129
+ };
130
+ // Like edgeH, but for horizontal contour lines between the passed cell
131
+ // and its vertical neighbor below.
132
+ const edgeV = (l, x, y) => {
133
+ const e1 = evaluate(l, x, y);
134
+ const e2 = evaluate(l, x, y + 1);
135
+ if (e1 === ABOVE && e2 === BELOW) {
136
+ addLine(l, x, y + 1, x + 1, y + 1);
137
+ }
138
+ else if (e2 === ABOVE && e1 === BELOW) {
139
+ addLine(l, x + 1, y + 1, x, y + 1);
140
+ }
141
+ else if (e1 === WITHIN || e2 === WITHIN) {
142
+ edgeV(l + 1, x * 2 + 0, y * 2 + 1);
143
+ edgeV(l + 1, x * 2 + 1, y * 2 + 1);
144
+ }
145
+ };
146
+ // Add all contour lines within a mipmap cell.
147
+ // It recurses into the four quadrants of the cell, and also uses edgeH and
148
+ // edgeV to add the contour lines that exist between quadrants.
149
+ const node = (l, x, y) => {
150
+ const e = evaluate(l, x, y);
151
+ if (e === WITHIN) {
152
+ node(l + 1, x * 2 + 0, y * 2 + 0);
153
+ node(l + 1, x * 2 + 1, y * 2 + 0);
154
+ node(l + 1, x * 2 + 0, y * 2 + 1);
155
+ node(l + 1, x * 2 + 1, y * 2 + 1);
156
+ edgeH(l + 1, x * 2 + 0, y * 2 + 0);
157
+ edgeV(l + 1, x * 2 + 0, y * 2 + 0);
158
+ edgeH(l + 1, x * 2 + 0, y * 2 + 1);
159
+ edgeV(l + 1, x * 2 + 1, y * 2 + 0);
160
+ }
161
+ else {
162
+ if (addNode)
163
+ addNode(l, x, y, e);
164
+ }
165
+ };
166
+ node(0, 0, 0);
167
+ }
168
+ // Generate a contour line for a specified value
169
+ //
170
+ // level: Value in the input array at which to draw a contour line
171
+ // opts: {
172
+ // maxMipmapLevel: Maximum recursion depth in the mipmap. As if you rescaled
173
+ // the input to a maximum dimension of 2^n pixels.
174
+ // (default unlimited)
175
+ // minPoints: Lines and rings with fewer points are removed. (default 0)
176
+ // smoothKernelWidth: Width of the rectangular filter for smoothing (default 2)
177
+ // smoothCycles: Number of iterations of smoothing (default 2)
178
+ // }
179
+ //
180
+ // Returns an array of lines, where each line is an array of [x, y] pairs.
181
+ contour(level, { maxMipmapLevel, smoothKernelWidth = 2, smoothCycles = 2, minPoints = 0 } = {}) {
182
+ // Use the quadtree algorithm to generate line segments that make up the contour
183
+ const segments = [];
184
+ this.evaluateContour(level, { maxMipmapLevel }, (l, x1, y1, x2, y2) => {
185
+ const scale = this.levels[l].scale;
186
+ const start = [scale * x1, scale * y1];
187
+ const end = [scale * x2, scale * y2];
188
+ segments.push({ start, end });
189
+ });
190
+ segments.sort((a, b) => key(a.start) - key(b.start));
191
+ // .. and then join them together into rings
192
+ // An arbitrary function to use a 2D point as a Map key
193
+ function key(a) { return a[0] + a[1] * 65536; }
194
+ const fragmentStart = new Map();
195
+ const fragmentEnd = new Map();
196
+ const rings = [];
197
+ segments.forEach(({ start, end }) => {
198
+ const a = fragmentEnd.get(key(start));
199
+ const b = fragmentStart.get(key(end));
200
+ if (a && b) {
201
+ fragmentEnd.delete(key(start));
202
+ fragmentStart.delete(key(end));
203
+ if (a === b) {
204
+ // Close a ring
205
+ a.push(end);
206
+ rings.push(a);
207
+ }
208
+ else {
209
+ // Join two lines together
210
+ const c = a.concat(b);
211
+ fragmentStart.set(key(c[0]), c);
212
+ fragmentEnd.set(key(c[c.length - 1]), c);
213
+ }
214
+ }
215
+ else if (a) {
216
+ // Extend an existing line from the end
217
+ fragmentEnd.delete(key(start));
218
+ a.push(end);
219
+ fragmentEnd.set(key(end), a);
220
+ }
221
+ else if (b) {
222
+ // Extend an existing line from the start
223
+ fragmentStart.delete(key(end));
224
+ b.unshift(start);
225
+ fragmentStart.set(key(start), b);
226
+ }
227
+ else {
228
+ // New line doesn't connect to any existing line
229
+ const c = [start, end];
230
+ fragmentStart.set(key(start), c);
231
+ fragmentEnd.set(key(end), c);
232
+ }
233
+ if (fragmentStart.size !== fragmentEnd.size) {
234
+ console.error(`Contour remaining fragment size mismatch ${fragmentStart.size} ${fragmentEnd.size}`);
235
+ }
236
+ });
237
+ const smoothOpts = {
238
+ kernelWidth: smoothKernelWidth,
239
+ cycles: smoothCycles,
240
+ };
241
+ // Closed rings and any unclosed line strings
242
+ return [...rings, ...fragmentStart.values()]
243
+ .filter(l => l.length >= minPoints && l.length >= smoothKernelWidth * 2)
244
+ .map(l => smooth(l, smoothOpts));
245
+ }
246
+ }
247
+ // Smooth a line by repeatedly applying a rectangular filter to approximate
248
+ // a gaussian filter. It detects closed loops and preserves them.
249
+ // The line is passed as an array of `[x, y]` pairs.
250
+ //
251
+ // kernelWidth: Width of the rectangular filter kernel
252
+ // cycles: Number of times to apply the kernel
253
+ function smooth(line, { kernelWidth = 2, cycles = 2 }) {
254
+ const isLoop = line[0][0] === line[line.length - 1][0] && line[0][1] === line[line.length - 1][1];
255
+ let pointAt;
256
+ if (isLoop) {
257
+ pointAt = (i) => line[(i + line.length) % line.length];
258
+ }
259
+ else {
260
+ pointAt = (i) => line[Math.min(Math.max(i, 0), line.length - 1)];
261
+ }
262
+ const sc = 1.0 / (kernelWidth * 2);
263
+ for (let cycle = 0; cycle < cycles; cycle++) {
264
+ let px = 0;
265
+ let py = 0;
266
+ if (isLoop) {
267
+ for (let i = line.length - kernelWidth; i < line.length; i++) {
268
+ px += line[i][0];
269
+ py += line[i][1];
270
+ }
271
+ }
272
+ else {
273
+ px = line[0][0] * kernelWidth;
274
+ py = line[0][1] * kernelWidth;
275
+ }
276
+ for (let i = 0; i < kernelWidth; i++) {
277
+ px += line[i][0];
278
+ py += line[i][1];
279
+ }
280
+ const res = line.slice();
281
+ for (let i = 0; i < line.length; i++) {
282
+ res[i] = [px * sc, py * sc];
283
+ px += pointAt(i + kernelWidth)[0] - pointAt(i - kernelWidth)[0];
284
+ py += pointAt(i + kernelWidth)[1] - pointAt(i - kernelWidth)[1];
285
+ }
286
+ if (isLoop) {
287
+ // Keep the loop closed
288
+ res[res.length - 1] = res[0].slice();
289
+ }
290
+ line = res;
291
+ }
292
+ return line;
293
+ }
294
+ function scaleParameters(minLongitude, minLatitude, maxLongitude, maxLatitude, width, height) {
295
+ const scaleX = (maxLongitude - minLongitude) / width;
296
+ const scaleY = (maxLatitude - minLatitude) / height;
297
+ return { scaleX, scaleY };
298
+ }
299
+ export default ContourMipmap;
300
+ export { scaleParameters };
@@ -0,0 +1,58 @@
1
+ function junctionPoint(out, inLine, origin, slope) {
2
+ const x0 = inLine[0];
3
+ const y0 = inLine[1];
4
+ const x1 = inLine[0];
5
+ const y1 = inLine[1];
6
+ const m1 = (y1 - y0) / (x1 - x0); // slope of line
7
+ const b1 = y0 - m1 * x0; // y-intercept of line
8
+ const m2 = slope;
9
+ const b2 = origin[1] - m2 * origin[0]; // y-intercept of line
10
+ if (m1 === m2) {
11
+ return 0; // parallel lines
12
+ }
13
+ const x = (b2 - b1) / (m1 - m2);
14
+ const y = m1 * x + b1;
15
+ // check if point is within line segment
16
+ if (x < Math.min(x0, x1) || x > Math.max(x0, x1) ||
17
+ y < Math.min(y0, y1) || y > Math.max(y0, y1)) {
18
+ return 0;
19
+ }
20
+ out[0] = x;
21
+ out[1] = y;
22
+ return 1;
23
+ }
24
+ export function junctionVerticalOrHorizontalLines(out, inLine1, value, isVertical) {
25
+ const x0 = inLine1[0];
26
+ const y0 = inLine1[1];
27
+ const x1 = inLine1[0];
28
+ const y1 = inLine1[1];
29
+ if (isVertical) {
30
+ // vertical line x = value
31
+ const m1 = (y1 - y0) / (x1 - x0);
32
+ const b1 = y0 - m1 * x0;
33
+ const y = m1 * value + b1;
34
+ // check if point is within line segment
35
+ if (y < Math.min(y0, y1) || y > Math.max(y0, y1)) {
36
+ return 0;
37
+ }
38
+ out[0] = value;
39
+ out[1] = y;
40
+ return 1;
41
+ }
42
+ else {
43
+ // horizontal line y = value
44
+ const m1 = (y1 - y0) / (x1 - x0);
45
+ const b1 = y0 - m1 * x0;
46
+ if (m1 === 0) {
47
+ return 0; // parallel lines
48
+ }
49
+ const x = (value - b1) / m1;
50
+ // check if point is within line segment
51
+ if (x < Math.min(x0, x1) || x > Math.max(x0, x1)) {
52
+ return 0;
53
+ }
54
+ out[0] = x;
55
+ out[1] = value;
56
+ return 1;
57
+ }
58
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @author Toprak Ozturk
3
+ */
4
+ import { equals, fromLongLatToUnitVector, fromUnitVectorToLongLat } from "../vec3";
5
+ import { pointsOnArc } from "../juction/arc-plane";
6
+ import { junctionVerticalOrHorizontalLines } from "../finite-line-2d";
7
+ // TODO:get rid of embedded lists. always flat list
8
+ const TILE_DEM_VERTEX_COUNT = 5; // 5x5 grid for DEM
9
+ const TILE_DEM_STEPCOUNT = TILE_DEM_VERTEX_COUNT - 1; // 4 inner divisions in each dimension
10
+ var EdgeType;
11
+ (function (EdgeType) {
12
+ EdgeType[EdgeType["ARC"] = 0] = "ARC";
13
+ EdgeType[EdgeType["LINEAR"] = 1] = "LINEAR";
14
+ })(EdgeType || (EdgeType = {}));
15
+ const _tempVec2 = /*@__PURE__*/ [0, 0];
16
+ const _plane = /*@__PURE__*/ { normal: [0, 0, 0], distance: 0 };
17
+ const _resultPoints = /*@__PURE__*/ [[0, 0, 0], [0, 0, 0]];
18
+ /**
19
+ *
20
+ * @param triangleMeta
21
+ * @param zoom
22
+ * @param angle
23
+ * @param dimension false for longitude (meridian) true for latitude (parallel)
24
+ */
25
+ function getPoints(triangleMeta, angle, dimension) {
26
+ // console.log("getPoints called with angle:", angle * 180 / Math.PI, "dimension:", dimension ? 'latitude' : 'longitude');
27
+ // find which arcs are cut by plane
28
+ const radians = angle;
29
+ if (dimension) {
30
+ _plane.normal[0] = 0;
31
+ _plane.normal[1] = 0;
32
+ _plane.normal[2] = 1;
33
+ _plane.distance = Math.sin(radians);
34
+ }
35
+ else {
36
+ _plane.normal[0] = Math.sin(radians);
37
+ _plane.normal[1] = -Math.cos(radians);
38
+ _plane.normal[2] = 0;
39
+ _plane.distance = 0;
40
+ }
41
+ let result = [];
42
+ // Add debugging
43
+ let resultsFromDistinctEdges = 0;
44
+ for (let i = 0; i < 3; i++) {
45
+ const edgeType = triangleMeta.edgeTypes[i];
46
+ const edge = triangleMeta.edges[i];
47
+ const coordIndex = dimension ? 1 : 0;
48
+ const minCoord = edge.bbox.min[coordIndex];
49
+ const maxCoord = edge.bbox.max[coordIndex];
50
+ if (minCoord > angle || maxCoord < angle) {
51
+ continue; // edge is out of range
52
+ }
53
+ let count = 0;
54
+ if (edgeType === EdgeType.ARC) {
55
+ count = pointsOnArc(edge, _plane, _resultPoints);
56
+ if (count === 1) {
57
+ fromUnitVectorToLongLat(_tempVec2, _resultPoints[0]);
58
+ result.push([[..._resultPoints[0]], [..._tempVec2]]);
59
+ }
60
+ else if (count === 2) {
61
+ // throw new Error('Unexpected 2 cut points on arc, should be max 1'); // TODO DELETE this line later
62
+ fromUnitVectorToLongLat(_tempVec2, _resultPoints[0]);
63
+ result.push([[..._resultPoints[0]], [..._tempVec2]]);
64
+ fromUnitVectorToLongLat(_tempVec2, _resultPoints[1]);
65
+ result.push([[..._resultPoints[1]], [..._tempVec2]]); // TODO: this is a fix for a bug, need to investigate later
66
+ }
67
+ }
68
+ else {
69
+ // linear line
70
+ count = junctionVerticalOrHorizontalLines(_tempVec2, edge.line, angle, dimension);
71
+ if (count === 1) {
72
+ fromLongLatToUnitVector(_resultPoints[0], _tempVec2);
73
+ result.push([[..._resultPoints[0]], [..._tempVec2]]);
74
+ }
75
+ }
76
+ resultsFromDistinctEdges += 1;
77
+ }
78
+ if (resultsFromDistinctEdges === 3) {
79
+ result = filterDuplicate(result);
80
+ }
81
+ if (result.length !== 2 && result.length !== 4) {
82
+ // TODO: THERE is a case where 4 points are found.
83
+ // this happens when two arcs has limit and share space in Z dimension
84
+ console.log("ERROR");
85
+ const text = 'Angle:' + angle + ' dimension:' + (dimension ? 'latitude' : 'longitude') + "\n" +
86
+ 'Result points count:' + result.length + "\n" +
87
+ "bbox:" + triangleMeta.bbox.min[0] * 180 / Math.PI + ", " + triangleMeta.bbox.min[1] * 180 / Math.PI + ", " + triangleMeta.bbox.max[0] * 180 / Math.PI + ", " + triangleMeta.bbox.max[1] * 180 / Math.PI + "\n";
88
+ for (let res of result) {
89
+ const ll = res[1];
90
+ console.log("Point: " + ll[0] * 180 / Math.PI + ", " + ll[1] * 180 / Math.PI + "\n");
91
+ }
92
+ throw new Error(`Unexpected cut count for tile cut, got: ${result.length}, angle: ${angle * 180 / Math.PI}, dimension: ${dimension ? 'latitude' : 'longitude'} \n` + text);
93
+ }
94
+ // TODO: i want to see it delete later
95
+ if (result.length === 4) {
96
+ console.warn("Warning: 4 cut points found on triangle for angle:", angle * 180 / Math.PI, "dimension:", dimension ? 'latitude' : 'longitude', "points:", result);
97
+ }
98
+ result.sort((a, b) => {
99
+ if (dimension) {
100
+ return a[1][0] - b[1][0]; // sort by y for longitude cuts
101
+ }
102
+ else {
103
+ return a[1][1] - b[1][1]; // sort by x for latitude cuts
104
+ }
105
+ });
106
+ return result;
107
+ }
108
+ function filterDuplicate(points) {
109
+ const result = [points[0]];
110
+ let dublicate = false;
111
+ for (let i = 1; i < points.length; i++) {
112
+ for (let j = 0; j < result.length; j++) {
113
+ if (equals(points[i][0], result[j][0])) {
114
+ dublicate = true;
115
+ break;
116
+ }
117
+ }
118
+ if (!dublicate) {
119
+ result.push(points[i]);
120
+ }
121
+ }
122
+ return result;
123
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ function _sortXY(a, b) {
3
+ if (a.y === b.y) {
4
+ return a.x - b.x;
5
+ }
6
+ return a.y - b.y;
7
+ }
8
+ function groupByZoomLevel(tiles) {
9
+ const map = new Map();
10
+ for (const tile of tiles) {
11
+ if (!map.has(tile.z)) {
12
+ map.set(tile.z, []);
13
+ }
14
+ map.get(tile.z).push(tile);
15
+ }
16
+ map.forEach((tileList, z) => {
17
+ tileList.sort(_sortXY);
18
+ });
19
+ return map;
20
+ }
21
+ function _insertDEM(sourceDEM, sourceWidth, sourceHeight, targetDEM, targetWidth, targetHeight, offsetX, offsetY) {
22
+ for (let row = 0; row < sourceHeight; row++) {
23
+ for (let col = 0; col < sourceWidth; col++) {
24
+ const sourceIndex = row * sourceWidth + col;
25
+ const targetIndex = (row + offsetY) * targetWidth + (col + offsetX);
26
+ targetDEM[targetIndex] = sourceDEM[sourceIndex];
27
+ }
28
+ }
29
+ }
30
+ function mergeTiles(tiles, demWidth, demHeight) {
31
+ let minX = Number.MAX_VALUE;
32
+ let maxX = Number.MIN_VALUE;
33
+ let minY = Number.MAX_VALUE;
34
+ let maxY = Number.MIN_VALUE;
35
+ for (let tile of tiles) {
36
+ if (tile.x < minX) {
37
+ minX = tile.x;
38
+ }
39
+ if (tile.x > maxX) {
40
+ maxX = tile.x;
41
+ }
42
+ if (tile.y < minY) {
43
+ minY = tile.y;
44
+ }
45
+ if (tile.y > maxY) {
46
+ maxY = tile.y;
47
+ }
48
+ }
49
+ const xCount = maxX - minX + 1;
50
+ const yCount = maxY - minY + 1;
51
+ const mergedDEM = new Float32Array(xCount * demWidth * yCount * demHeight).fill(0);
52
+ for (let tile of tiles) {
53
+ _insertDEM(tile.DEM, demWidth, demHeight, mergedDEM, xCount * demWidth, yCount * demHeight, (tile.x - minX) * demWidth, (tile.y - minY) * demHeight);
54
+ }
55
+ return mergedDEM;
56
+ }