@pirireis/webglobeplugins 1.0.2 → 1.0.3
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.
- package/Math/{angle-calculation.ts → angle-calculation.js} +14 -18
- package/Math/{arc-cdf-points.ts → arc-cdf-points.js} +272 -329
- package/Math/{arc-generate-points-exponantial.ts → arc-generate-points-exponantial.js} +254 -299
- package/Math/{arc.ts → arc.js} +292 -421
- package/Math/bounds/line-bbox.js +186 -225
- package/Math/{circle-cdf-points.ts → circle-cdf-points.js} +78 -143
- package/Math/{circle.ts → circle.js} +33 -49
- package/Math/{constants.ts → constants.js} +4 -12
- package/Math/contour/{quadtreecontours.ts → quadtreecontours.js} +300 -371
- package/Math/contour/quadtreecontours1.js +298 -336
- package/Math/{finite-line-2d.ts → finite-line-2d.js} +58 -68
- package/Math/{haversine.ts → haversine.js} +22 -33
- package/Math/index.js +1 -0
- package/Math/juction/{arc-plane.ts → arc-plane.js} +143 -203
- package/Math/juction/{line-sphere.ts → line-sphere.js} +22 -32
- package/Math/juction/{plane-plane.ts → plane-plane.js} +53 -62
- package/Math/{line.ts → line.js} +52 -84
- package/Math/matrix4.js +1 -0
- package/Math/{methods.ts → methods.js} +126 -182
- package/Math/{plane.ts → plane.js} +56 -92
- package/Math/{quaternion.ts → quaternion.js} +106 -128
- package/Math/templete-shapes/{grid-visually-equal.ts → grid-visually-equal.js} +65 -118
- package/Math/tessellation/constants.js +1 -0
- package/Math/tessellation/{methods.ts → methods.js} +49 -79
- package/Math/tessellation/{nearest-value-padding.ts → nearest-value-padding.js} +112 -147
- package/Math/tessellation/{spherical-triangle-area.ts → spherical-triangle-area.js} +99 -127
- package/Math/tessellation/{tile-merger.ts → tile-merger.js} +429 -578
- package/Math/tessellation/{triangle-tessellation.ts → triangle-tessellation.js} +386 -533
- package/Math/tessellation/types.js +1 -0
- package/Math/types.js +1 -0
- package/Math/utils.js +2 -3
- package/Math/{vec3.ts → vec3.js} +155 -227
- package/Math/{xyz-tile.ts → xyz-tile.js} +18 -26
- package/algorithms/search-binary.js +16 -14
- package/altitude-locator/adaptors.js +1 -0
- package/altitude-locator/keymethod.js +1 -0
- package/altitude-locator/plugin.js +344 -445
- package/altitude-locator/types.js +21 -26
- package/compass-rose/compass-rose-padding-flat.js +230 -274
- package/compass-rose/{compass-text-writer.ts → compass-text-writer.js} +155 -210
- package/compass-rose/index.js +3 -3
- package/{constants.ts → constants.js} +6 -8
- package/heatwave/datamanager.js +149 -168
- package/heatwave/heatwave.js +206 -261
- package/heatwave/index.js +5 -5
- package/heatwave/isobar.js +303 -340
- package/heatwave/{texture-point-sampler.ts → texture-point-sampler.js} +187 -220
- package/investigation-tools/draw/tiles/adapters.js +67 -0
- package/investigation-tools/draw/tiles/{tiles.ts → tiles.js} +128 -162
- package/jest.config.js +7 -6
- package/package.json +1 -1
- package/pin/pin-object-array1.js +300 -381
- package/pin/pin-point-totem1.js +60 -77
- package/programs/arrowfield/arrow-field.js +60 -89
- package/programs/arrowfield/logic.js +141 -173
- package/programs/data2legend/density-to-legend.js +68 -86
- package/programs/data2legend/point-to-density-texture.js +67 -84
- package/programs/float2legendwithratio/index.js +2 -3
- package/programs/float2legendwithratio/logic.js +118 -144
- package/programs/float2legendwithratio/object.js +104 -141
- package/programs/helpers/blender.js +58 -73
- package/programs/helpers/{fadeaway.ts → fadeaway.js} +60 -73
- package/programs/index.js +20 -19
- package/programs/line-on-globe/circle-accurate-3d.js +85 -112
- package/programs/line-on-globe/circle-accurate-flat.js +148 -200
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +102 -134
- package/programs/line-on-globe/index.js +1 -0
- package/programs/line-on-globe/lines-color-instanced-flat.js +80 -99
- package/programs/line-on-globe/linestrip/data.js +4 -0
- package/programs/line-on-globe/linestrip/{linestrip.ts → linestrip.js} +93 -152
- package/programs/line-on-globe/{naive-accurate-flexible.ts → naive-accurate-flexible.js} +126 -175
- package/programs/line-on-globe/util.js +5 -8
- package/programs/picking/pickable-polygon-renderer.js +98 -129
- package/programs/picking/pickable-renderer.js +98 -130
- package/programs/point-on-globe/element-globe-surface-glow.js +93 -122
- package/programs/point-on-globe/element-point-glow.js +80 -114
- package/programs/point-on-globe/square-pixel-point.js +121 -139
- package/programs/polygon-on-globe/{texture-dem-triangles.ts → texture-dem-triangles.js} +163 -207
- package/programs/{programcache.ts → programcache.js} +126 -134
- package/programs/rings/index.js +1 -1
- package/programs/rings/partial-ring/{piece-of-pie.ts → piece-of-pie.js} +152 -222
- package/programs/totems/camera-totem-attactment-interface.js +1 -0
- package/programs/totems/{camerauniformblock.ts → camerauniformblock.js} +225 -310
- package/programs/totems/{canvas-webglobe-info.ts → canvas-webglobe-info.js} +132 -147
- package/programs/totems/{dem-textures-manager.ts → dem-textures-manager.js} +257 -360
- package/programs/totems/{globe-changes.ts → globe-changes.js} +59 -79
- package/programs/totems/gpu-selection-uniform-block.js +99 -127
- package/programs/totems/{index.ts → index.js} +2 -2
- package/programs/two-d/pixel-padding-for-compass.js +87 -101
- package/programs/util.js +14 -19
- package/programs/vectorfields/logics/{constants.ts → constants.js} +4 -5
- package/programs/vectorfields/logics/{drawrectangleparticles.ts → drawrectangleparticles.js} +80 -115
- package/programs/vectorfields/logics/index.js +2 -4
- package/programs/vectorfields/logics/particle-ubo.js +16 -0
- package/programs/vectorfields/logics/{pixelbased.ts → pixelbased.js} +86 -115
- package/programs/vectorfields/logics/ubo.js +51 -57
- package/programs/vectorfields/{pingpongbuffermanager.ts → pingpongbuffermanager.js} +99 -113
- package/range-tools-on-terrain/bearing-line/{adapters.ts → adapters.js} +114 -154
- package/range-tools-on-terrain/bearing-line/{plugin.ts → plugin.js} +457 -569
- package/range-tools-on-terrain/bearing-line/types.js +1 -0
- package/range-tools-on-terrain/circle-line-chain/{adapters.ts → adapters.js} +85 -104
- package/range-tools-on-terrain/circle-line-chain/{chain-list-map.ts → chain-list-map.js} +382 -446
- package/range-tools-on-terrain/circle-line-chain/{plugin.ts → plugin.js} +464 -607
- package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
- package/range-tools-on-terrain/range-ring/{adapters.ts → adapters.js} +93 -114
- package/range-tools-on-terrain/range-ring/{enum.ts → enum.js} +2 -2
- package/range-tools-on-terrain/range-ring/{plugin.ts → plugin.js} +377 -444
- package/range-tools-on-terrain/range-ring/rangeringangletext.js +331 -0
- package/range-tools-on-terrain/range-ring/types.js +9 -0
- package/semiplugins/interface.js +1 -0
- package/semiplugins/lightweight/{line-plugin.ts → line-plugin.js} +221 -342
- package/semiplugins/lightweight/{piece-of-pie-plugin.ts → piece-of-pie-plugin.js} +200 -275
- package/semiplugins/shape-on-terrain/{arc-plugin.ts → arc-plugin.js} +481 -616
- package/semiplugins/shape-on-terrain/{circle-plugin.ts → circle-plugin.js} +444 -588
- package/semiplugins/shape-on-terrain/{padding-1-degree.ts → padding-1-degree.js} +539 -713
- package/semiplugins/shape-on-terrain/terrain-polygon/{adapters.ts → adapters.js} +55 -69
- package/semiplugins/shape-on-terrain/terrain-polygon/data/{cache.ts → cache.js} +102 -149
- package/semiplugins/shape-on-terrain/terrain-polygon/data/{index-polygon-map.ts → index-polygon-map.js} +45 -58
- package/semiplugins/shape-on-terrain/terrain-polygon/data/{manager.ts → manager.js} +4 -4
- package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -196
- package/semiplugins/shape-on-terrain/terrain-polygon/data/{polygon-to-triangles.ts → polygon-to-triangles.js} +100 -144
- package/semiplugins/shape-on-terrain/terrain-polygon/data/{random.ts → random.js} +121 -165
- package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/{worker-contact.ts → worker-contact.js} +63 -81
- package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -146
- package/semiplugins/shape-on-terrain/terrain-polygon/{terrain-polygon.ts → terrain-polygon.js} +219 -265
- package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
- package/semiplugins/shell/bbox-renderer/index.js +2 -0
- package/semiplugins/shell/bbox-renderer/{logic.ts → logic.js} +209 -273
- package/semiplugins/shell/bbox-renderer/object.js +75 -0
- package/semiplugins/type.js +1 -0
- package/semiplugins/utility/{container-plugin.ts → container-plugin.js} +94 -126
- package/semiplugins/utility/{object-pass-container-plugin.ts → object-pass-container-plugin.js} +80 -101
- package/shaders/fragment-toy/firework.js +1 -1
- package/shaders/fragment-toy/singularity.js +2 -5
- package/tracks/point-heat-map/adaptors/timetracksplugin-format-to-this.js +63 -78
- package/tracks/point-heat-map/index.js +1 -0
- package/tracks/point-heat-map/plugin-webworker.js +121 -148
- package/tracks/point-heat-map/point-to-heat-map-flow.js +121 -150
- package/tracks/point-tracks/key-methods.js +2 -3
- package/tracks/point-tracks/plugin.js +401 -487
- package/tracks/timetracks/adaptors-line-strip.js +65 -79
- package/tracks/timetracks/plugin-line-strip.js +240 -295
- package/tracks/timetracks/program-line-strip.js +411 -495
- package/tracks/timetracks/programpoint-line-strip.js +109 -137
- package/types.js +19 -0
- package/util/account/bufferoffsetmanager.js +176 -209
- package/util/account/create-buffermap-orchastration.js +39 -0
- package/util/account/index.js +3 -6
- package/util/account/single-attribute-buffer-management/{buffer-manager.ts → buffer-manager.js} +119 -151
- package/util/account/single-attribute-buffer-management/{buffer-orchestrator.ts → buffer-orchestrator.js} +212 -238
- package/util/account/single-attribute-buffer-management/{buffer-orchestrator1.ts → buffer-orchestrator1.js} +159 -184
- package/util/account/single-attribute-buffer-management/{index.ts → index.js} +4 -11
- package/util/account/single-attribute-buffer-management/{object-store.ts → object-store.js} +55 -76
- package/util/account/single-attribute-buffer-management/types.js +1 -0
- package/util/account/util.js +18 -22
- package/util/algorithms/index.js +1 -0
- package/util/algorithms/search-binary.js +25 -26
- package/util/build-strategy/{static-dynamic.ts → static-dynamic.js} +41 -50
- package/util/check/index.js +1 -0
- package/util/check/typecheck.js +66 -0
- package/util/{frame-counter-trigger.ts → frame-counter-trigger.js} +84 -99
- package/util/geometry/{index.ts → index.js} +121 -155
- package/util/gl-util/buffer/{attribute-loader.ts → attribute-loader.js} +62 -84
- package/util/gl-util/buffer/{index.ts → index.js} +3 -6
- package/util/gl-util/draw-options/{methods.ts → methods.js} +32 -47
- package/util/gl-util/uniform-block/{manager.ts → manager.js} +200 -232
- package/util/{globe-default-gl-states.ts → globe-default-gl-states.js} +4 -5
- package/util/{helper-methods.ts → helper-methods.js} +8 -9
- package/util/index.js +10 -9
- package/util/interpolation/index.js +1 -0
- package/util/interpolation/timetrack/index.js +2 -9
- package/util/interpolation/timetrack/timetrack-interpolator.js +79 -94
- package/util/interpolation/timetrack/web-worker.js +46 -51
- package/util/picking/{fence.ts → fence.js} +43 -47
- package/util/picking/{picker-displayer.ts → picker-displayer.js} +176 -226
- package/util/programs/draw-from-pixel-coords.js +164 -201
- package/util/programs/{draw-texture-on-canvas.ts → draw-texture-on-canvas.js} +69 -91
- package/util/programs/supersampletotextures.js +97 -130
- package/util/programs/texturetoglobe.js +128 -153
- package/util/shaderfunctions/{geometrytransformations.ts → geometrytransformations.js} +44 -106
- package/util/shaderfunctions/index.js +2 -2
- package/util/shaderfunctions/nodata.js +2 -4
- package/util/shaderfunctions/noisefunctions.js +7 -10
- package/util/{webglobjectbuilders.ts → webglobjectbuilders.js} +358 -446
- package/vectorfield/arrowfield/adaptor.js +11 -11
- package/vectorfield/arrowfield/index.js +3 -3
- package/vectorfield/arrowfield/plugin.js +83 -128
- package/vectorfield/waveparticles/adaptor.js +15 -16
- package/vectorfield/waveparticles/index.js +3 -3
- package/vectorfield/waveparticles/{plugin.ts → plugin.js} +415 -506
- package/vectorfield/wind/adapters/{image-to-fields.ts → image-to-fields.js} +61 -74
- package/vectorfield/wind/adapters/types.js +1 -0
- package/vectorfield/wind/{imagetovectorfieldandmagnitude.ts → imagetovectorfieldandmagnitude.js} +53 -78
- package/vectorfield/wind/index.js +5 -5
- package/vectorfield/wind/{plugin-persistant copy.ts → plugin-persistant copy.js } +364 -461
- package/vectorfield/wind/{plugin-persistant.ts → plugin-persistant.js} +375 -483
- package/vectorfield/wind/plugin.js +685 -883
- package/vectorfield/wind/vectorfieldimage.js +23 -27
- package/write-text/{context-text-bulk.ts → context-text-bulk.js} +200 -285
- package/write-text/context-text3.js +167 -0
- package/write-text/{context-text4.ts → context-text4.js} +146 -231
- package/write-text/context-textDELETE.js +94 -125
- package/write-text/objectarraylabels/{index.ts → index.js} +2 -2
- package/write-text/objectarraylabels/objectarraylabels.js +200 -247
- package/Math/matrix4.ts +0 -0
- package/Math/mesh/mapbox-delaunay.d.ts +0 -74
- package/Math/roadmap.md +0 -10
- package/Math/tessellation/constants.ts +0 -1
- package/Math/tessellation/roadmap.md +0 -48
- package/Math/tessellation/types.ts +0 -1
- package/Math/types.ts +0 -68
- package/investigation-tools/draw/tiles/adapters.ts +0 -133
- package/programs/line-on-globe/linestrip/data.ts +0 -29
- package/programs/polygon-on-globe/roadmap.md +0 -8
- package/programs/totems/camera-totem-attactment-interface.ts +0 -4
- package/programs/vectorfields/logics/particle-ubo.ts +0 -23
- package/publish.bat +0 -62
- package/range-tools-on-terrain/bearing-line/types.ts +0 -65
- package/range-tools-on-terrain/circle-line-chain/types.ts +0 -43
- package/range-tools-on-terrain/range-ring/rangeringangletext.ts +0 -396
- package/range-tools-on-terrain/range-ring/types.ts +0 -30
- package/semiplugins/interface.ts +0 -14
- package/semiplugins/shape-on-terrain/goal.md +0 -12
- package/semiplugins/shape-on-terrain/terrain-polygon/data/cache-shortcuts.md +0 -20
- package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.ts +0 -209
- package/semiplugins/shape-on-terrain/terrain-polygon/data/readme.md +0 -5
- package/semiplugins/shape-on-terrain/terrain-polygon/data/types.ts +0 -37
- package/semiplugins/shape-on-terrain/terrain-polygon/notes.md +0 -90
- package/semiplugins/shape-on-terrain/terrain-polygon/types.ts +0 -69
- package/semiplugins/shell/bbox-renderer/index.ts +0 -2
- package/semiplugins/shell/bbox-renderer/object.ts +0 -129
- package/semiplugins/type.ts +0 -8
- package/terrain-plugin.mmd +0 -83
- package/tests/Math/arc-sampling-test.js +0 -367
- package/tests/Math/arc-sampling-test.ts +0 -429
- package/tests/Math/arc.test.ts +0 -77
- package/tests/Math/junction/arc-limit.test.ts +0 -7
- package/tests/Math/junction/arc-plane-points.test.ts +0 -196
- package/tests/Math/junction/arc-plane.test.ts +0 -172
- package/tests/Math/junction/line-sphere.test.ts +0 -127
- package/tests/Math/junction/plane-plane.test.ts +0 -91
- package/tests/Math/plane-test.ts +0 -17
- package/tests/Math/plane.test.ts +0 -43
- package/tests/Math/vec3.test.ts +0 -33
- package/tracks/point-heat-map/readme.md +0 -15
- package/tracks/timetracks/readme.md +0 -1
- package/tsconfig.json +0 -22
- package/types/@pirireis/webglobe.d.ts +0 -102
- package/types/delaunator.d.ts +0 -40
- package/types/earcut.d.ts +0 -11
- package/types/rbush.d.ts +0 -57
- package/types.ts +0 -319
- package/util/account/create-buffermap-orchastration.ts +0 -85
- package/util/account/single-attribute-buffer-management/types.ts +0 -43
- package/util/check/typecheck.ts +0 -74
- package/vectorfield/wind/adapters/types.ts +0 -12
- package/write-text/context-text3.ts +0 -252
- package/write-text/objectarraylabels/objectarraylabels.d.ts +0 -72
|
@@ -1,578 +1,429 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const meshOffsetY = j * (tileDimensionLength - 1);
|
|
431
|
-
|
|
432
|
-
if (tile) {
|
|
433
|
-
// 1. Direct Tile Found
|
|
434
|
-
nearestValuePadding.insert(tile.x, tile.y); // Using original coordinates for padding logic
|
|
435
|
-
moveMeshToMergedMesh(
|
|
436
|
-
mergedMesh, mergedMeshDimLength,
|
|
437
|
-
tile.mesh, tileDimensionLength,
|
|
438
|
-
meshOffsetX, meshOffsetY
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
// Update BBox Limits
|
|
442
|
-
// We simply expand the LL/UR.
|
|
443
|
-
// Post-processing will fix the inverted X for antimeridian.
|
|
444
|
-
if (tile.bbox.ll.x < bboxLimit.ll.x) bboxLimit.ll.x = tile.bbox.ll.x;
|
|
445
|
-
if (tile.bbox.ll.y < bboxLimit.ll.y) bboxLimit.ll.y = tile.bbox.ll.y;
|
|
446
|
-
if (tile.bbox.ur.x > bboxLimit.ur.x) bboxLimit.ur.x = tile.bbox.ur.x;
|
|
447
|
-
if (tile.bbox.ur.y > bboxLimit.ur.y) bboxLimit.ur.y = tile.bbox.ur.y;
|
|
448
|
-
|
|
449
|
-
// Track clusters for antimeridian split
|
|
450
|
-
// High X values (East Cluster) -> Left side of visual boundary
|
|
451
|
-
// Low X values (West Cluster) -> Right side of visual boundary
|
|
452
|
-
if (limits.antimeridian) {
|
|
453
|
-
if (tileX >= limits.minX) {
|
|
454
|
-
if (tile.bbox.ll.x < eastClusterMinX) eastClusterMinX = tile.bbox.ll.x;
|
|
455
|
-
} else {
|
|
456
|
-
if (tile.bbox.ur.x > westClusterMaxX) westClusterMaxX = tile.bbox.ur.x;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
} else {
|
|
461
|
-
// 2. Parent Tile Fallback
|
|
462
|
-
const parentTileCoord = calculateParentTile(tileX, tileY, zoom);
|
|
463
|
-
const parentKey = keyMethod(parentTileCoord.x, parentTileCoord.y, parentTileCoord.level);
|
|
464
|
-
const parentTile = tilesMetaData.tileMap.get(parentKey);
|
|
465
|
-
|
|
466
|
-
if (parentTile) {
|
|
467
|
-
const populatedMesh = populateTileIntoHigherZoomLevel(
|
|
468
|
-
parentTile.mesh, tileDimensionLength,
|
|
469
|
-
tileDimensionLength * 2 - 1
|
|
470
|
-
);
|
|
471
|
-
|
|
472
|
-
// Adjust offset for parent logic
|
|
473
|
-
// If current tile is odd (right/bottom), the parent mesh drawing needs to shift back
|
|
474
|
-
// because 'populatedMesh' covers 2x2.
|
|
475
|
-
const parentDrawOffsetX = meshOffsetX - (tileX % 2) * (tileDimensionLength - 1);
|
|
476
|
-
const parentDrawOffsetY = meshOffsetY - (tileY % 2) * (tileDimensionLength - 1);
|
|
477
|
-
|
|
478
|
-
moveMeshToMergedMesh(
|
|
479
|
-
mergedMesh, mergedMeshDimLength,
|
|
480
|
-
populatedMesh, tileDimensionLength * 2 - 1,
|
|
481
|
-
parentDrawOffsetX,
|
|
482
|
-
parentDrawOffsetY
|
|
483
|
-
);
|
|
484
|
-
|
|
485
|
-
// Padding logic for parents
|
|
486
|
-
const xP = parentTile.x * 2;
|
|
487
|
-
const yP = parentTile.y * 2;
|
|
488
|
-
for (let dx = 0; dx < 2; dx++) {
|
|
489
|
-
for (let dy = 0; dy < 2; dy++) {
|
|
490
|
-
nearestValuePadding.insert(xP + dx, yP + dy);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
// 3. Children Tile Fallback
|
|
495
|
-
const childrenTiles: (Float32Array[] | undefined)[] = [];
|
|
496
|
-
let anyChildren = 0;
|
|
497
|
-
for (let dx = 0; dx < 2; dx++) {
|
|
498
|
-
for (let dy = 0; dy < 2; dy++) {
|
|
499
|
-
const childX = tileX * 2 + dx;
|
|
500
|
-
const childY = tileY * 2 + dy;
|
|
501
|
-
const childKey = keyMethod(childX, childY, zoom + 1);
|
|
502
|
-
const childTile = tilesMetaData.tileMap.get(childKey);
|
|
503
|
-
if (childTile) {
|
|
504
|
-
anyChildren++;
|
|
505
|
-
childrenTiles.push(childTile.mesh);
|
|
506
|
-
} else {
|
|
507
|
-
childrenTiles.push(undefined);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (anyChildren > 0) {
|
|
513
|
-
nearestValuePadding.insert(tileX, tileY);
|
|
514
|
-
fillFromChildren(
|
|
515
|
-
mergedMesh, mergedMeshDimLength,
|
|
516
|
-
childrenTiles, tileDimensionLength,
|
|
517
|
-
meshOffsetX, meshOffsetY
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// Post-Processing BBox for Antimeridian
|
|
526
|
-
if (limits.antimeridian) {
|
|
527
|
-
// Task: bbox.ll should contain lower-left of East Cluster, bbox.ur should contain upper-right of West Cluster
|
|
528
|
-
// This creates the condition ur.x < ll.x (e.g. 170 to -170)
|
|
529
|
-
|
|
530
|
-
// Only update if we actually found tiles in those clusters
|
|
531
|
-
if (eastClusterMinX !== Infinity) bboxLimit.ll.x = eastClusterMinX;
|
|
532
|
-
if (westClusterMaxX !== -Infinity) bboxLimit.ur.x = westClusterMaxX;
|
|
533
|
-
// console.log("Antimeridian BBox adjusted:", bboxLimit);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// We pad the merged mesh based on the VALID range we iterated.
|
|
537
|
-
// Since we iterate 0..mergeCount, the indices are implicitly 0..mergeCount
|
|
538
|
-
// However, the clamp function usually expects absolute coordinates.
|
|
539
|
-
// Given the new "Grid" approach, the mesh is always locally 0 to mergeCount in valid data.
|
|
540
|
-
// We pass the grid-relative limits to clamp.
|
|
541
|
-
nearestValuePadding.clamp(mergedMesh, 0, 0, mergeCount, mergeCount);
|
|
542
|
-
nearestValuePadding.clear();
|
|
543
|
-
|
|
544
|
-
// Calculate Cover Ratio
|
|
545
|
-
// How much of the mesh grid (mergeCount) is covered by actual data range?
|
|
546
|
-
const currentWidth = limits.antimeridian ? rangeX : (limits.maxX - limits.minX + 1);
|
|
547
|
-
const currentHeight = limits.maxY - limits.minY + 1;
|
|
548
|
-
|
|
549
|
-
const usedWidth = Math.min(mergeCount, currentWidth);
|
|
550
|
-
const usedHeight = Math.min(mergeCount, currentHeight);
|
|
551
|
-
|
|
552
|
-
const xRatio = calculateMergedMeshDimLength(usedWidth, tileDimensionLength) / mergedMeshDimLength;
|
|
553
|
-
const yRatio = calculateMergedMeshDimLength(usedHeight, tileDimensionLength) / mergedMeshDimLength;
|
|
554
|
-
|
|
555
|
-
result.push({ mesh: mergedMesh, bbox: bboxLimit, zoom: zoom, coverRatio: { x: xRatio, y: yRatio } });
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return result;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
export function mergeMeshes(
|
|
563
|
-
|
|
564
|
-
tiles: DrawnTileInfo[],
|
|
565
|
-
mergeCount = 12,
|
|
566
|
-
tileDimensionLength = 5,
|
|
567
|
-
processLimit = 6,
|
|
568
|
-
globe: Globe
|
|
569
|
-
): MergedTilesInfo[] {
|
|
570
|
-
// filter out tiles with NaN values
|
|
571
|
-
// return returnTop6tiles(tiles);
|
|
572
|
-
|
|
573
|
-
const tilesMetaData = createMapAndMetaData(tiles, globe);
|
|
574
|
-
const mergedTiles = mergeTiles(tilesMetaData, mergeCount, tileDimensionLength, processLimit);
|
|
575
|
-
return mergedTiles;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
|
|
1
|
+
import { calculateMergedMeshDimLength } from "./methods";
|
|
2
|
+
import { NearestValuePadding } from "./nearest-value-padding";
|
|
3
|
+
function keyMethod(x, y, level) {
|
|
4
|
+
return `${level}_${x}_${y}`;
|
|
5
|
+
}
|
|
6
|
+
function calculateParentTile(x, y, level) {
|
|
7
|
+
return {
|
|
8
|
+
x: Math.floor(x / 2),
|
|
9
|
+
y: Math.floor(y / 2),
|
|
10
|
+
level: level - 1
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createMapAndMetaData(tiles, globe) {
|
|
14
|
+
const tileMap = new Map();
|
|
15
|
+
let maxLevel = -Infinity;
|
|
16
|
+
let minLevel = Infinity;
|
|
17
|
+
// Intermediate storage to analyze distributions per zoom level
|
|
18
|
+
const zoomData = new Map();
|
|
19
|
+
// 1. First Pass: Populate Map and Collect Coordinates
|
|
20
|
+
for (const tile of tiles) {
|
|
21
|
+
const key = keyMethod(tile.x, tile.y, tile.level);
|
|
22
|
+
tileMap.set(key, tile);
|
|
23
|
+
// Update Level Range
|
|
24
|
+
if (tile.level > maxLevel)
|
|
25
|
+
maxLevel = tile.level;
|
|
26
|
+
if (tile.level < minLevel)
|
|
27
|
+
minLevel = tile.level;
|
|
28
|
+
// Collect Data
|
|
29
|
+
if (!zoomData.has(tile.level)) {
|
|
30
|
+
zoomData.set(tile.level, { xValues: [], yValues: [] });
|
|
31
|
+
}
|
|
32
|
+
const data = zoomData.get(tile.level);
|
|
33
|
+
data.xValues.push(tile.x);
|
|
34
|
+
data.yValues.push(tile.y);
|
|
35
|
+
}
|
|
36
|
+
const tileLimitsByZoom = new Map();
|
|
37
|
+
// 2. Second Pass: Analyze Data per Zoom Level
|
|
38
|
+
zoomData.forEach((data, level) => {
|
|
39
|
+
// --- Calculate Gravity Centers (Mode) ---
|
|
40
|
+
// --- Calculate Min/Max and Antimeridian ---
|
|
41
|
+
// Sort X values to detect gaps
|
|
42
|
+
const sortedX = [...new Set(data.xValues)].sort((a, b) => a - b);
|
|
43
|
+
const minY = Math.min(...data.yValues);
|
|
44
|
+
const maxY = Math.max(...data.yValues);
|
|
45
|
+
let minX = sortedX[0];
|
|
46
|
+
let maxX = sortedX[sortedX.length - 1];
|
|
47
|
+
let isAntimeridian = false;
|
|
48
|
+
// We only check for wrapping if we have tiles near both edges (0 and Max)
|
|
49
|
+
// A simple heuristic: find the largest gap between sorted indices.
|
|
50
|
+
let maxGap = 0;
|
|
51
|
+
let gapIndex = -1;
|
|
52
|
+
for (let i = 0; i < sortedX.length - 1; i++) {
|
|
53
|
+
const gap = sortedX[i + 1] - sortedX[i];
|
|
54
|
+
if (gap > maxGap) {
|
|
55
|
+
maxGap = gap;
|
|
56
|
+
gapIndex = i;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Also check the wrap-around gap (distance from last tile to world end + first tile)
|
|
60
|
+
// Though strictly for clustering split, we usually look for the internal gap.
|
|
61
|
+
// If the largest internal gap is significantly large (e.g., > worldWidth / 2),
|
|
62
|
+
// we treat the smaller numbers as the "East of view" (Right side)
|
|
63
|
+
// and large numbers as "West of view" (Left side) relative to the dateline.
|
|
64
|
+
// let centerX = getGravityCenter(data.xValues);
|
|
65
|
+
// const centerY = getGravityCenter(data.yValues);
|
|
66
|
+
const { x: centerX, y: centerY } = getCenterFromCamera(globe, level);
|
|
67
|
+
if (maxGap > 5 && maxX === Math.pow(2, level) - 1 && minX === 0) {
|
|
68
|
+
isAntimeridian = true;
|
|
69
|
+
// Cluster 1 (Low X): sortedX[0] ... sortedX[gapIndex] -> "West Cluster" (The Americas/Left side of map 0..x)
|
|
70
|
+
// Cluster 2 (High X): sortedX[gapIndex+1] ... end -> "East Cluster" (Asia/Right side of map x..max)
|
|
71
|
+
// Per requirements:
|
|
72
|
+
// "max value now represents max of west cluster" -> Max of the Low X numbers
|
|
73
|
+
maxX = sortedX[gapIndex];
|
|
74
|
+
// "min values represents min of east cluster" -> Min of the High X numbers
|
|
75
|
+
minX = sortedX[gapIndex + 1];
|
|
76
|
+
}
|
|
77
|
+
tileLimitsByZoom.set(level, {
|
|
78
|
+
minX,
|
|
79
|
+
maxX,
|
|
80
|
+
minY,
|
|
81
|
+
maxY,
|
|
82
|
+
antimeridian: isAntimeridian,
|
|
83
|
+
centerX,
|
|
84
|
+
centerY
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
tileMap,
|
|
89
|
+
maxLevel,
|
|
90
|
+
minLevel,
|
|
91
|
+
tileLimitsByZoom
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Helper to find the most frequent value (Gravity Center)
|
|
95
|
+
function getMode(arr) {
|
|
96
|
+
if (arr.length === 0)
|
|
97
|
+
return 0;
|
|
98
|
+
const map = new Map();
|
|
99
|
+
let maxCount = 0;
|
|
100
|
+
let mode = arr[0];
|
|
101
|
+
for (const num of arr) {
|
|
102
|
+
const count = (map.get(num) || 0) + 1;
|
|
103
|
+
map.set(num, count);
|
|
104
|
+
if (count > maxCount) {
|
|
105
|
+
maxCount = count;
|
|
106
|
+
mode = num;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return mode;
|
|
110
|
+
}
|
|
111
|
+
function getGravityCenter(arr) {
|
|
112
|
+
if (arr.length === 0)
|
|
113
|
+
return 0;
|
|
114
|
+
const sum = arr.reduce((acc, val) => acc + val, 0);
|
|
115
|
+
return Math.round(sum / arr.length);
|
|
116
|
+
}
|
|
117
|
+
function getCenterFromCamera(globe, zoom) {
|
|
118
|
+
const camLongLat = globe.FCamera.FCamLongLat;
|
|
119
|
+
const n = Math.pow(2, zoom);
|
|
120
|
+
const x = Math.floor((camLongLat.x / (2 * Math.PI) + 0.5) * n);
|
|
121
|
+
const y = Math.floor((camLongLat.y / Math.PI + 0.5) * n);
|
|
122
|
+
return { x, y };
|
|
123
|
+
}
|
|
124
|
+
function populateTileIntoHigherZoomLevel(tileMesh, tileDimensionLength, targetDimensionLength) {
|
|
125
|
+
const newMesh = Array.from({ length: targetDimensionLength }, () => new Float32Array(targetDimensionLength));
|
|
126
|
+
// use linear interpolation to populate
|
|
127
|
+
for (let row = 0; row < targetDimensionLength; row++) {
|
|
128
|
+
for (let col = 0; col < targetDimensionLength; col++) {
|
|
129
|
+
const sourceRow = row / (targetDimensionLength - 1) * (tileDimensionLength - 1);
|
|
130
|
+
const sourceCol = col / (targetDimensionLength - 1) * (tileDimensionLength - 1);
|
|
131
|
+
const rowLow = Math.floor(sourceRow);
|
|
132
|
+
const rowHigh = Math.min(Math.ceil(sourceRow), tileDimensionLength - 1);
|
|
133
|
+
const colLow = Math.floor(sourceCol);
|
|
134
|
+
const colHigh = Math.min(Math.ceil(sourceCol), tileDimensionLength - 1);
|
|
135
|
+
const topLeft = tileMesh[rowLow][colLow];
|
|
136
|
+
const topRight = tileMesh[rowLow][colHigh];
|
|
137
|
+
const bottomLeft = tileMesh[rowHigh][colLow];
|
|
138
|
+
const bottomRight = tileMesh[rowHigh][colHigh];
|
|
139
|
+
const top = topLeft + (topRight - topLeft) * (sourceCol - colLow);
|
|
140
|
+
const bottom = bottomLeft + (bottomRight - bottomLeft) * (sourceCol - colLow);
|
|
141
|
+
newMesh[row][col] = top + (bottom - top) * (sourceRow - rowLow);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return newMesh;
|
|
145
|
+
}
|
|
146
|
+
function fillFromChildren(targetMesh, targetDimensionLength, childrenMeshes, sourceDimensionLength, startX, startY) {
|
|
147
|
+
const halfDim = (sourceDimensionLength - 1) / 2;
|
|
148
|
+
// Child 0: Top Left
|
|
149
|
+
if (childrenMeshes[0]) {
|
|
150
|
+
const child = childrenMeshes[0];
|
|
151
|
+
for (let r = 0; r <= halfDim; r++) {
|
|
152
|
+
// Read from top of child (source convention is bottom-up, so top is index Length-1)
|
|
153
|
+
// We skip every second row: (L-1), (L-3), ...
|
|
154
|
+
const childRowIndex = (sourceDimensionLength - 1) - (r * 2);
|
|
155
|
+
const rowData = child[childRowIndex];
|
|
156
|
+
for (let c = 0; c <= halfDim; c++) {
|
|
157
|
+
// Skip every second column
|
|
158
|
+
const val = rowData[c * 2];
|
|
159
|
+
const targetIdx = (startY + r) * targetDimensionLength + (startX + c);
|
|
160
|
+
targetMesh[targetIdx] = val;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Child 1: Top Right
|
|
165
|
+
// In mergeTiles loop (dx outer, dy inner), index 2 corresponds to dx=1, dy=0 (Top Right)
|
|
166
|
+
if (childrenMeshes[2]) {
|
|
167
|
+
const child = childrenMeshes[2];
|
|
168
|
+
for (let r = 0; r <= halfDim; r++) {
|
|
169
|
+
const childRowIndex = (sourceDimensionLength - 1) - (r * 2);
|
|
170
|
+
const rowData = child[childRowIndex];
|
|
171
|
+
for (let c = 0; c <= halfDim; c++) {
|
|
172
|
+
const val = rowData[c * 2];
|
|
173
|
+
const targetIdx = (startY + r) * targetDimensionLength + (startX + halfDim + c);
|
|
174
|
+
if (isNaN(targetMesh[targetIdx])) {
|
|
175
|
+
targetMesh[targetIdx] = val;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Child 2: Bottom Left
|
|
181
|
+
// In mergeTiles loop, index 1 corresponds to dx=0, dy=1 (Bottom Left)
|
|
182
|
+
if (childrenMeshes[1]) {
|
|
183
|
+
const child = childrenMeshes[1];
|
|
184
|
+
for (let r = 0; r <= halfDim; r++) {
|
|
185
|
+
const childRowIndex = (sourceDimensionLength - 1) - (r * 2);
|
|
186
|
+
const rowData = child[childRowIndex];
|
|
187
|
+
for (let c = 0; c <= halfDim; c++) {
|
|
188
|
+
const val = rowData[c * 2];
|
|
189
|
+
const targetIdx = (startY + halfDim + r) * targetDimensionLength + (startX + c);
|
|
190
|
+
if (isNaN(targetMesh[targetIdx])) {
|
|
191
|
+
targetMesh[targetIdx] = val;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Child 3: Bottom Right
|
|
197
|
+
if (childrenMeshes[3]) {
|
|
198
|
+
const child = childrenMeshes[3];
|
|
199
|
+
for (let r = 0; r <= halfDim; r++) {
|
|
200
|
+
const childRowIndex = (sourceDimensionLength - 1) - (r * 2);
|
|
201
|
+
const rowData = child[childRowIndex];
|
|
202
|
+
for (let c = 0; c <= halfDim; c++) {
|
|
203
|
+
const val = rowData[c * 2];
|
|
204
|
+
const targetIdx = (startY + halfDim + r) * targetDimensionLength + (startX + halfDim + c);
|
|
205
|
+
if (isNaN(targetMesh[targetIdx])) {
|
|
206
|
+
targetMesh[targetIdx] = val;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// This function is correct, assuming its inputs are prepared properly.
|
|
213
|
+
// This function is correct, assuming its inputs are prepared properly.
|
|
214
|
+
function moveMeshToMergedMesh(targetMesh, targetDimensionLength, sourceMesh, sourceDimensionLength, startX, startY) {
|
|
215
|
+
// sourceMesh[0][0] is south west corner
|
|
216
|
+
// targetMesh[0][0] is top left corner
|
|
217
|
+
let targetIndex = startY * targetDimensionLength + startX;
|
|
218
|
+
for (let y = 0; y < sourceDimensionLength; y++) {
|
|
219
|
+
// Read from bottom to top (source mesh convention)
|
|
220
|
+
const vertical = sourceMesh[sourceDimensionLength - y - 1];
|
|
221
|
+
for (let x = 0; x < sourceDimensionLength; x++) {
|
|
222
|
+
const value = vertical[x];
|
|
223
|
+
// const currentValue = targetMesh[targetIndex];
|
|
224
|
+
// TODO: investigate why overlapping values are not the same. cancel parent filling
|
|
225
|
+
// if (!isNaN(value) && value !== 0 && currentValue !== 0) {
|
|
226
|
+
// if (currentValue !== value) {
|
|
227
|
+
// console.warn(`Overlapping values are not the same: currentValue=${currentValue}, newValue=${value}`);
|
|
228
|
+
// }
|
|
229
|
+
// }
|
|
230
|
+
if (isNaN(targetMesh[targetIndex])) {
|
|
231
|
+
targetMesh[targetIndex] = value;
|
|
232
|
+
}
|
|
233
|
+
targetIndex++;
|
|
234
|
+
}
|
|
235
|
+
targetIndex += targetDimensionLength - sourceDimensionLength;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function limitCheck(limit, limitRange = 12) {
|
|
239
|
+
// TODO: far tiles from camera should be pruned to fit in the limit range
|
|
240
|
+
const rowRange = limit.maxX - limit.minX + 1;
|
|
241
|
+
const colRange = limit.maxY - limit.minY + 1;
|
|
242
|
+
if (rowRange > limitRange || colRange > limitRange) {
|
|
243
|
+
console.warn(`Tile limit range exceeded: Row Range = ${rowRange}, Col Range = ${colRange}, Limit Range = ${limitRange}`);
|
|
244
|
+
throw new Error("Tile limit range exceeded");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function mergeTiles(tilesMetaData, mergeCount = 8, tileDimensionLength = 5, processLimit = 6) {
|
|
248
|
+
const mergedMeshDimLength = calculateMergedMeshDimLength(mergeCount, tileDimensionLength);
|
|
249
|
+
const nearestValuePadding = new NearestValuePadding(tileDimensionLength, mergeCount);
|
|
250
|
+
// Helper to check if a number is between range (inclusive)
|
|
251
|
+
const result = [];
|
|
252
|
+
for (let zoom = tilesMetaData.maxLevel; zoom >= tilesMetaData.minLevel; zoom--) {
|
|
253
|
+
if (tilesMetaData.maxLevel - zoom >= processLimit) {
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
const limits = tilesMetaData.tileLimitsByZoom.get(zoom);
|
|
257
|
+
if (!limits)
|
|
258
|
+
continue;
|
|
259
|
+
const mergedMesh = new Float32Array(mergedMeshDimLength * mergedMeshDimLength).fill(NaN);
|
|
260
|
+
// Initialize BBox.
|
|
261
|
+
// We track East (high X) and West (low X) clusters separately for Antimeridian cases.
|
|
262
|
+
const bboxLimit = {
|
|
263
|
+
ur: { x: -Infinity, y: -Infinity },
|
|
264
|
+
ll: { x: Infinity, y: Infinity }
|
|
265
|
+
};
|
|
266
|
+
// Specific BBox trackers for antimeridian split
|
|
267
|
+
let eastClusterMinX = Infinity; // For the left side of the view (e.g. 170)
|
|
268
|
+
let westClusterMaxX = -Infinity; // For the right side of the view (e.g. -170)
|
|
269
|
+
// limitCheck(limits, 20); // Assumed helper<
|
|
270
|
+
const worldWidth = Math.pow(2, zoom);
|
|
271
|
+
// --- Task 1: Calculate Grid Origin (Centering) ---
|
|
272
|
+
// We determine where the top-left of our mergeCount x mergeCount grid starts in tile coordinates.
|
|
273
|
+
let originX = limits.minX;
|
|
274
|
+
let originY = limits.minY;
|
|
275
|
+
const rangeX = limits.antimeridian
|
|
276
|
+
? (worldWidth - limits.minX) + limits.maxX + 1
|
|
277
|
+
: limits.maxX - limits.minX + 1;
|
|
278
|
+
const rangeY = limits.maxY - limits.minY + 1;
|
|
279
|
+
// If the data is wider than the mesh, center it using centerX
|
|
280
|
+
if (rangeX > mergeCount && limits.centerX !== undefined) {
|
|
281
|
+
originX = Math.floor(limits.centerX - (mergeCount / 2));
|
|
282
|
+
}
|
|
283
|
+
// If the data is taller than the mesh, center it using centerY
|
|
284
|
+
if (rangeY > mergeCount && limits.centerY !== undefined) {
|
|
285
|
+
originY = Math.floor(limits.centerY - (mergeCount / 2));
|
|
286
|
+
}
|
|
287
|
+
// --- Task 2: Iterate Grid Slots ---
|
|
288
|
+
// Instead of iterating tile coordinates, we iterate the target grid slots (0..mergeCount)
|
|
289
|
+
// and calculate which tile belongs there.
|
|
290
|
+
for (let i = 0; i < mergeCount; i++) {
|
|
291
|
+
for (let j = 0; j < mergeCount; j++) {
|
|
292
|
+
// Calculate actual Tile Coordinates
|
|
293
|
+
// Handle X Wrapping for Antimeridian
|
|
294
|
+
let tileX = (originX + i);
|
|
295
|
+
// JS modulo of negative numbers behaves oddly, ensure positive wrap
|
|
296
|
+
tileX = ((tileX % worldWidth) + worldWidth) % worldWidth;
|
|
297
|
+
const tileY = originY + j;
|
|
298
|
+
// --- Validity Check ---
|
|
299
|
+
// Check if this specific tileX/tileY is actually part of the visible map data
|
|
300
|
+
let isValidX = false;
|
|
301
|
+
if (limits.antimeridian) {
|
|
302
|
+
isValidX = tileX >= limits.minX || tileX <= limits.maxX;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
isValidX = tileX >= limits.minX && tileX <= limits.maxX;
|
|
306
|
+
}
|
|
307
|
+
const isValidY = tileY >= limits.minY && tileY <= limits.maxY;
|
|
308
|
+
if (!isValidX || !isValidY)
|
|
309
|
+
continue;
|
|
310
|
+
const key = keyMethod(tileX, tileY, zoom);
|
|
311
|
+
const tile = tilesMetaData.tileMap.get(key);
|
|
312
|
+
// Calculate mesh offset (target position in pixels/floats)
|
|
313
|
+
const meshOffsetX = i * (tileDimensionLength - 1);
|
|
314
|
+
const meshOffsetY = j * (tileDimensionLength - 1);
|
|
315
|
+
if (tile) {
|
|
316
|
+
// 1. Direct Tile Found
|
|
317
|
+
nearestValuePadding.insert(tile.x, tile.y); // Using original coordinates for padding logic
|
|
318
|
+
moveMeshToMergedMesh(mergedMesh, mergedMeshDimLength, tile.mesh, tileDimensionLength, meshOffsetX, meshOffsetY);
|
|
319
|
+
// Update BBox Limits
|
|
320
|
+
// We simply expand the LL/UR.
|
|
321
|
+
// Post-processing will fix the inverted X for antimeridian.
|
|
322
|
+
if (tile.bbox.ll.x < bboxLimit.ll.x)
|
|
323
|
+
bboxLimit.ll.x = tile.bbox.ll.x;
|
|
324
|
+
if (tile.bbox.ll.y < bboxLimit.ll.y)
|
|
325
|
+
bboxLimit.ll.y = tile.bbox.ll.y;
|
|
326
|
+
if (tile.bbox.ur.x > bboxLimit.ur.x)
|
|
327
|
+
bboxLimit.ur.x = tile.bbox.ur.x;
|
|
328
|
+
if (tile.bbox.ur.y > bboxLimit.ur.y)
|
|
329
|
+
bboxLimit.ur.y = tile.bbox.ur.y;
|
|
330
|
+
// Track clusters for antimeridian split
|
|
331
|
+
// High X values (East Cluster) -> Left side of visual boundary
|
|
332
|
+
// Low X values (West Cluster) -> Right side of visual boundary
|
|
333
|
+
if (limits.antimeridian) {
|
|
334
|
+
if (tileX >= limits.minX) {
|
|
335
|
+
if (tile.bbox.ll.x < eastClusterMinX)
|
|
336
|
+
eastClusterMinX = tile.bbox.ll.x;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
if (tile.bbox.ur.x > westClusterMaxX)
|
|
340
|
+
westClusterMaxX = tile.bbox.ur.x;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// 2. Parent Tile Fallback
|
|
346
|
+
const parentTileCoord = calculateParentTile(tileX, tileY, zoom);
|
|
347
|
+
const parentKey = keyMethod(parentTileCoord.x, parentTileCoord.y, parentTileCoord.level);
|
|
348
|
+
const parentTile = tilesMetaData.tileMap.get(parentKey);
|
|
349
|
+
if (parentTile) {
|
|
350
|
+
const populatedMesh = populateTileIntoHigherZoomLevel(parentTile.mesh, tileDimensionLength, tileDimensionLength * 2 - 1);
|
|
351
|
+
// Adjust offset for parent logic
|
|
352
|
+
// If current tile is odd (right/bottom), the parent mesh drawing needs to shift back
|
|
353
|
+
// because 'populatedMesh' covers 2x2.
|
|
354
|
+
const parentDrawOffsetX = meshOffsetX - (tileX % 2) * (tileDimensionLength - 1);
|
|
355
|
+
const parentDrawOffsetY = meshOffsetY - (tileY % 2) * (tileDimensionLength - 1);
|
|
356
|
+
moveMeshToMergedMesh(mergedMesh, mergedMeshDimLength, populatedMesh, tileDimensionLength * 2 - 1, parentDrawOffsetX, parentDrawOffsetY);
|
|
357
|
+
// Padding logic for parents
|
|
358
|
+
const xP = parentTile.x * 2;
|
|
359
|
+
const yP = parentTile.y * 2;
|
|
360
|
+
for (let dx = 0; dx < 2; dx++) {
|
|
361
|
+
for (let dy = 0; dy < 2; dy++) {
|
|
362
|
+
nearestValuePadding.insert(xP + dx, yP + dy);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
// 3. Children Tile Fallback
|
|
368
|
+
const childrenTiles = [];
|
|
369
|
+
let anyChildren = 0;
|
|
370
|
+
for (let dx = 0; dx < 2; dx++) {
|
|
371
|
+
for (let dy = 0; dy < 2; dy++) {
|
|
372
|
+
const childX = tileX * 2 + dx;
|
|
373
|
+
const childY = tileY * 2 + dy;
|
|
374
|
+
const childKey = keyMethod(childX, childY, zoom + 1);
|
|
375
|
+
const childTile = tilesMetaData.tileMap.get(childKey);
|
|
376
|
+
if (childTile) {
|
|
377
|
+
anyChildren++;
|
|
378
|
+
childrenTiles.push(childTile.mesh);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
childrenTiles.push(undefined);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (anyChildren > 0) {
|
|
386
|
+
nearestValuePadding.insert(tileX, tileY);
|
|
387
|
+
fillFromChildren(mergedMesh, mergedMeshDimLength, childrenTiles, tileDimensionLength, meshOffsetX, meshOffsetY);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Post-Processing BBox for Antimeridian
|
|
394
|
+
if (limits.antimeridian) {
|
|
395
|
+
// Task: bbox.ll should contain lower-left of East Cluster, bbox.ur should contain upper-right of West Cluster
|
|
396
|
+
// This creates the condition ur.x < ll.x (e.g. 170 to -170)
|
|
397
|
+
// Only update if we actually found tiles in those clusters
|
|
398
|
+
if (eastClusterMinX !== Infinity)
|
|
399
|
+
bboxLimit.ll.x = eastClusterMinX;
|
|
400
|
+
if (westClusterMaxX !== -Infinity)
|
|
401
|
+
bboxLimit.ur.x = westClusterMaxX;
|
|
402
|
+
// console.log("Antimeridian BBox adjusted:", bboxLimit);
|
|
403
|
+
}
|
|
404
|
+
// We pad the merged mesh based on the VALID range we iterated.
|
|
405
|
+
// Since we iterate 0..mergeCount, the indices are implicitly 0..mergeCount
|
|
406
|
+
// However, the clamp function usually expects absolute coordinates.
|
|
407
|
+
// Given the new "Grid" approach, the mesh is always locally 0 to mergeCount in valid data.
|
|
408
|
+
// We pass the grid-relative limits to clamp.
|
|
409
|
+
nearestValuePadding.clamp(mergedMesh, 0, 0, mergeCount, mergeCount);
|
|
410
|
+
nearestValuePadding.clear();
|
|
411
|
+
// Calculate Cover Ratio
|
|
412
|
+
// How much of the mesh grid (mergeCount) is covered by actual data range?
|
|
413
|
+
const currentWidth = limits.antimeridian ? rangeX : (limits.maxX - limits.minX + 1);
|
|
414
|
+
const currentHeight = limits.maxY - limits.minY + 1;
|
|
415
|
+
const usedWidth = Math.min(mergeCount, currentWidth);
|
|
416
|
+
const usedHeight = Math.min(mergeCount, currentHeight);
|
|
417
|
+
const xRatio = calculateMergedMeshDimLength(usedWidth, tileDimensionLength) / mergedMeshDimLength;
|
|
418
|
+
const yRatio = calculateMergedMeshDimLength(usedHeight, tileDimensionLength) / mergedMeshDimLength;
|
|
419
|
+
result.push({ mesh: mergedMesh, bbox: bboxLimit, zoom: zoom, coverRatio: { x: xRatio, y: yRatio } });
|
|
420
|
+
}
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
423
|
+
export function mergeMeshes(tiles, mergeCount = 12, tileDimensionLength = 5, processLimit = 6, globe) {
|
|
424
|
+
// filter out tiles with NaN values
|
|
425
|
+
// return returnTop6tiles(tiles);
|
|
426
|
+
const tilesMetaData = createMapAndMetaData(tiles, globe);
|
|
427
|
+
const mergedTiles = mergeTiles(tilesMetaData, mergeCount, tileDimensionLength, processLimit);
|
|
428
|
+
return mergedTiles;
|
|
429
|
+
}
|