@pirireis/webglobeplugins 0.16.4 → 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 (168) hide show
  1. package/Math/angle-calculation.js +1 -0
  2. package/Math/arc.js +92 -2
  3. package/Math/circle-cdf-points.js +2 -2
  4. package/Math/circle.js +2 -2
  5. package/Math/contour/quadtreecontours.js +300 -0
  6. package/Math/finite-line-2d.js +58 -0
  7. package/Math/juction/arc-plane.js +67 -12
  8. package/Math/juction/line-sphere.js +6 -6
  9. package/Math/juction/plane-plane.js +4 -6
  10. package/Math/methods.js +5 -5
  11. package/Math/templete-shapes/grid-visually-equal.js +0 -1
  12. package/Math/tessellation/earcut/adapters.js +37 -0
  13. package/Math/tessellation/hybrid-triangle-tessellation-meta.js +123 -0
  14. package/Math/tessellation/methods.js +46 -0
  15. package/Math/tessellation/shred-input.js +18 -0
  16. package/Math/tessellation/tile-merger.js +56 -0
  17. package/Math/tessellation/tiler.js +50 -0
  18. package/Math/tessellation/triangle-tessellation-meta.js +516 -0
  19. package/Math/tessellation/triangle-tessellation.js +14 -0
  20. package/Math/tessellation/zoom-catch.js +1 -0
  21. package/Math/vec3.js +26 -1
  22. package/compass-rose/compass-text-writer.js +39 -33
  23. package/constants.js +3 -0
  24. package/{util/heatwavedatamanager → heatwave}/datamanager.js +1 -1
  25. package/heatwave/{plugins/heatwaveglobeshell.js → heatwave.js} +8 -6
  26. package/heatwave/index.js +5 -3
  27. package/heatwave/{isobar/plugin.js → isobar.js} +6 -5
  28. package/{util/heatwavedatamanager → heatwave}/texture-point-sampler.js +24 -3
  29. package/package.json +7 -3
  30. package/programs/arrowfield/{object.js → arrow-field.js} +1 -1
  31. package/programs/arrowfield/logic.js +1 -1
  32. package/programs/data2legend/density-to-legend.js +24 -29
  33. package/programs/data2legend/point-to-density-texture.js +14 -17
  34. package/programs/float2legendwithratio/logic.js +2 -2
  35. package/programs/float2legendwithratio/object.js +1 -1
  36. package/programs/helpers/{blender/program.js → blender.js} +1 -1
  37. package/programs/helpers/{fadeaway/logic.js → fadeaway.js} +11 -2
  38. package/programs/index.js +20 -9
  39. package/programs/line-on-globe/circle-accurate-3d.js +12 -14
  40. package/programs/line-on-globe/circle-accurate-flat.js +0 -1
  41. package/programs/line-on-globe/degree-padding-around-circle-3d.js +13 -15
  42. package/programs/line-on-globe/lines-color-instanced-flat.js +15 -18
  43. package/programs/line-on-globe/naive-accurate-flexible.js +0 -1
  44. package/programs/picking/pickable-polygon-renderer.js +1 -1
  45. package/programs/picking/pickable-renderer.js +2 -2
  46. package/programs/point-on-globe/element-globe-surface-glow.js +2 -2
  47. package/programs/point-on-globe/element-point-glow.js +1 -1
  48. package/programs/point-on-globe/square-pixel-point.js +1 -1
  49. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +204 -0
  50. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin.js +31 -10
  51. package/programs/polygon-on-globe/texture-dem-triangles.js +81 -12
  52. package/programs/rings/partial-ring/piece-of-pie.js +26 -29
  53. package/programs/totems/camerauniformblock.js +34 -45
  54. package/programs/two-d/pixel-padding-for-compass.js +14 -24
  55. package/programs/vectorfields/logics/drawrectangleparticles.js +1 -2
  56. package/programs/vectorfields/logics/pixelbased.js +1 -2
  57. package/programs/vectorfields/pingpongbuffermanager.js +1 -1
  58. package/range-tools-on-terrain/bearing-line/adapters.js +1 -1
  59. package/range-tools-on-terrain/circle-line-chain/adapters.js +0 -5
  60. package/range-tools-on-terrain/circle-line-chain/plugin.js +1 -1
  61. package/range-tools-on-terrain/range-ring/plugin.js +4 -6
  62. package/semiplugins/lightweight/line-plugin.js +0 -1
  63. package/semiplugins/shape-on-terrain/arc-plugin.js +5 -7
  64. package/semiplugins/shape-on-terrain/circle-plugin.js +2 -2
  65. package/semiplugins/shape-on-terrain/padding-1-degree.js +1 -2
  66. package/semiplugins/shell/bbox-renderer/index.js +2 -0
  67. package/{programs/globeshell/wiggle → semiplugins/shell/bbox-renderer}/logic.js +101 -102
  68. package/{programs/globeshell/wiggle → semiplugins/shell/bbox-renderer}/object.js +6 -7
  69. package/semiplugins/utility/container-plugin.js +94 -0
  70. package/semiplugins/utility/object-pass-container-plugin.js +80 -0
  71. package/{point-heat-map → tracks/point-heat-map}/adaptors/timetracksplugin-format-to-this.js +1 -1
  72. package/{point-heat-map → tracks/point-heat-map}/plugin-webworker.js +3 -3
  73. package/{point-heat-map → tracks/point-heat-map}/point-to-heat-map-flow.js +11 -14
  74. package/{point-tracks → tracks/point-tracks}/plugin.js +5 -5
  75. package/{timetracks → tracks/timetracks}/adaptors-line-strip.js +1 -1
  76. package/{timetracks → tracks/timetracks}/program-line-strip.js +49 -49
  77. package/{timetracks → tracks/timetracks}/programpoint-line-strip.js +16 -13
  78. package/types.js +6 -0
  79. package/util/account/bufferoffsetmanager.js +1 -1
  80. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +9 -95
  81. package/util/gl-util/uniform-block/manager.js +4 -5
  82. package/util/gl-util/uniform-block/types.js +0 -7
  83. package/util/index.js +10 -13
  84. package/util/picking/fence.js +16 -18
  85. package/util/picking/picker-displayer.js +4 -6
  86. package/util/programs/{shapesonglobe.js → draw-from-pixel-coords.js} +4 -7
  87. package/util/programs/draw-texture-on-canvas.js +1 -1
  88. package/util/programs/texturetoglobe.js +3 -3
  89. package/util/shaderfunctions/geometrytransformations.js +6 -0
  90. package/util/webglobe/rasteroverlay.js +1 -0
  91. package/vectorfield/arrowfield/index.js +3 -0
  92. package/{arrowfield → vectorfield/arrowfield}/plugin.js +2 -2
  93. package/{waveparticles → vectorfield/waveparticles}/plugin.js +12 -12
  94. package/{wind → vectorfield/wind}/index.js +1 -1
  95. package/{wind → vectorfield/wind}/plugin.js +32 -32
  96. package/write-text/attached-text-writer.js +9 -1
  97. package/write-text/context-text3.js +0 -1
  98. package/write-text/objectarraylabels/index.js +2 -0
  99. package/Math/mesh/mapbox-delaunay.js +0 -544
  100. package/arrowfield/index.js +0 -3
  101. package/bearing-line/index.js +0 -2
  102. package/bearing-line/plugin.js +0 -444
  103. package/circle-line-chain/chain-list-map.js +0 -201
  104. package/circle-line-chain/plugin.js +0 -411
  105. package/circle-line-chain/util.js +0 -1
  106. package/compassrose/compassrose.js +0 -293
  107. package/compassrose/index.js +0 -2
  108. package/index.js +0 -12
  109. package/partialrings/buffer-manager.js +0 -75
  110. package/partialrings/index.js +0 -2
  111. package/partialrings/plugin.js +0 -128
  112. package/partialrings/program.js +0 -279
  113. package/programs/arrowfield/index.js +0 -2
  114. package/programs/globe-util/is-globe-moved.js +0 -19
  115. package/programs/globeshell/index.js +0 -2
  116. package/programs/globeshell/wiggle/index.js +0 -2
  117. package/programs/helpers/blender/index.js +0 -1
  118. package/programs/helpers/fadeaway/index.js +0 -2
  119. package/programs/helpers/fadeaway/object.js +0 -14
  120. package/programs/helpers/index.js +0 -2
  121. package/programs/rings/distancering/circleflatprogram.js +0 -116
  122. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +0 -326
  123. package/programs/rings/distancering/circlepaddysharedbuffer.js +0 -368
  124. package/programs/rings/distancering/index.js +0 -6
  125. package/programs/rings/distancering/paddyflatprogram.js +0 -127
  126. package/programs/rings/distancering/paddyflatprogram2d.js +0 -129
  127. package/programs/rings/distancering/paddyflatprogram3d.js +0 -128
  128. package/programs/two-d/pixel-circle.js +0 -1
  129. package/programs/vectorfields/index.js +0 -3
  130. package/rangerings/enum.js +0 -2
  131. package/rangerings/index.js +0 -5
  132. package/rangerings/plugin.js +0 -543
  133. package/rangerings/rangeringangletext.js +0 -326
  134. package/rangerings/ring-account.js +0 -112
  135. package/timetracks/index.js +0 -1
  136. package/util/build-strategy/general-strategy.js +0 -62
  137. package/util/gl-util/uniform-block/shader.js +0 -1
  138. package/util/heatwavedatamanager/index.js +0 -2
  139. package/util/heatwavedatamanager/pointcoordsmeta.js +0 -22
  140. package/util/jshelpers/data-filler.js +0 -17
  141. package/util/jshelpers/equality.js +0 -18
  142. package/util/jshelpers/index.js +0 -2
  143. package/util/jshelpers/timefilters.js +0 -30
  144. package/util/programs/index.js +0 -1
  145. package/util/surface-line-data/arc-bboxes.js +0 -25
  146. package/util/surface-line-data/arcs-to-cuts.js +0 -50
  147. package/util/surface-line-data/cut-arc.js +0 -1
  148. package/util/surface-line-data/flow.js +0 -28
  149. package/util/surface-line-data/rbush-manager.js +0 -1
  150. package/util/surface-line-data/web-worker.js +0 -1
  151. package/write-text/context-text3old.js +0 -152
  152. package/write-text/index.js +0 -1
  153. package/write-text/writer-plugin.js +0 -8
  154. /package/{heatwave/isobar/quadtreecontours.js → Math/contour/quadtreecontours1.js} +0 -0
  155. /package/{util/surface-line-data → Math/tessellation}/types.js +0 -0
  156. /package/pin/{pin-object-array.js → pin-object-array1.js} +0 -0
  157. /package/pin/{pin-point-totem.js → pin-point-totem1.js} +0 -0
  158. /package/{circle-line-chain/init.js → programs/polygon-on-globe/partial-tesselation.js} +0 -0
  159. /package/{point-heat-map → tracks/point-heat-map}/index.js +0 -0
  160. /package/{point-tracks → tracks/point-tracks}/key-methods.js +0 -0
  161. /package/{timetracks → tracks/timetracks}/plugin-line-strip.js +0 -0
  162. /package/{arrowfield → vectorfield/arrowfield}/adaptor.js +0 -0
  163. /package/{waveparticles → vectorfield/waveparticles}/adaptor.js +0 -0
  164. /package/{waveparticles → vectorfield/waveparticles}/index.js +0 -0
  165. /package/{wind → vectorfield/wind}/imagetovectorfieldandmagnitude.js +0 -0
  166. /package/{wind → vectorfield/wind}/vectorfieldimage.js +0 -0
  167. /package/write-text/{context-text.js → context-textDELETE.js} +0 -0
  168. /package/{heatwave/isobar → write-text/objectarraylabels}/objectarraylabels.js +0 -0
@@ -0,0 +1,516 @@
1
+ /**
2
+ * @author Toprak Ozturk
3
+ */
4
+ import { create as createArc, calculateZLimitPoint } from "../arc";
5
+ import { createUnitVectorFromLongLat, equals, length, vec3ToLongLatRadians } from "../vec3";
6
+ import { TILE_COUNTS } from "./zoom-catch";
7
+ import { pointsOnArc } from "../juction/arc-plane";
8
+ import { latToTileY, tileYtoLat } from "./methods";
9
+ import { isOnTileEdge } from "./methods";
10
+ import Delaunator from "delaunator";
11
+ // TODO:get rid of embedded lists. always flat list
12
+ const TILE_DEM_VERTEX_COUNT = 5; // 5x5 grid for DEM
13
+ const TILE_DEM_STEPCOUNT = TILE_DEM_VERTEX_COUNT - 1; // 4 inner divisions in each dimension
14
+ const _plane = /*@__PURE__*/ { normal: [0, 0, 0], distance: 0 };
15
+ const _resultPoints = /*@__PURE__*/ [[0, 0, 0], [0, 0, 0]];
16
+ function createShellPoints(triangleMeta) {
17
+ const arcs = triangleMeta.arcs;
18
+ const points = [
19
+ arcs[0].p0LongLat,
20
+ arcs[1].p0LongLat,
21
+ arcs[2].p0LongLat
22
+ ];
23
+ for (let i = 0; i < 3; i++) {
24
+ if (arcs[i].exceededLimit) {
25
+ if (arcs[i].exceededLimit !== undefined) {
26
+ const longLat = vec3ToLongLatRadians(arcs[i].exceededLimit);
27
+ points.push(longLat);
28
+ }
29
+ }
30
+ }
31
+ const center = [
32
+ points.reduce((sum, p) => sum + p[0], 0) / points.length,
33
+ points.reduce((sum, p) => sum + p[1], 0) / points.length
34
+ ];
35
+ const shellPoints = [];
36
+ for (let i = 0; i < points.length; i++) {
37
+ const p = points[i];
38
+ const x = (p[0] - center[0]) / 10;
39
+ const y = (p[1] - center[1]) / 10;
40
+ shellPoints.push([p[0] + x, p[1] + y]);
41
+ }
42
+ return shellPoints;
43
+ }
44
+ function createBBox(p1, p2, limitVec) {
45
+ if (limitVec) {
46
+ const limitLongLat = vec3ToLongLatRadians(limitVec);
47
+ console.log('Limit point found at:', limitLongLat, 'for p1:', p1, 'p2:', p2);
48
+ return {
49
+ min: [Math.min(p1[0], p2[0], limitLongLat[0]), Math.min(p1[1], p2[1], limitLongLat[1])],
50
+ max: [Math.max(p1[0], p2[0], limitLongLat[0]), Math.max(p1[1], p2[1], limitLongLat[1])],
51
+ };
52
+ }
53
+ return {
54
+ min: [Math.min(p1[0], p2[0]), Math.min(p1[1], p2[1])],
55
+ max: [Math.max(p1[0], p2[0]), Math.max(p1[1], p2[1])],
56
+ };
57
+ }
58
+ export function createTriangleTessellationMeta(p1, p2, p3) {
59
+ const p1v3 = createUnitVectorFromLongLat(p1);
60
+ const p2v3 = createUnitVectorFromLongLat(p2);
61
+ const p3v3 = createUnitVectorFromLongLat(p3);
62
+ const arc1 = createArc(p1v3, p2v3);
63
+ const arc2 = createArc(p2v3, p3v3);
64
+ const arc3 = createArc(p3v3, p1v3);
65
+ const limitVec = [0, 0, 0];
66
+ if (calculateZLimitPoint(arc1, limitVec)) {
67
+ arc1.exceededLimit = [limitVec[0], limitVec[1], limitVec[2]];
68
+ const longlat_ = vec3ToLongLatRadians(arc1.exceededLimit);
69
+ console.log('Arc 1 exceeded limit at:', longlat_.map(v => (v * 180 / Math.PI).toFixed(2)), 'rad:', arc1.exceededLimit);
70
+ }
71
+ arc1.bbox = createBBox(p1, p2, arc1.exceededLimit);
72
+ arc1.p0LongLat = p1;
73
+ arc1.p1LongLat = p2;
74
+ if (calculateZLimitPoint(arc2, limitVec)) {
75
+ arc2.exceededLimit = [limitVec[0], limitVec[1], limitVec[2]];
76
+ }
77
+ arc2.bbox = createBBox(p2, p3, arc2.exceededLimit);
78
+ arc2.p0LongLat = p2;
79
+ arc2.p1LongLat = p3;
80
+ if (calculateZLimitPoint(arc3, limitVec)) {
81
+ arc3.exceededLimit = [limitVec[0], limitVec[1], limitVec[2]];
82
+ }
83
+ arc3.bbox = createBBox(p3, p1, arc3.exceededLimit);
84
+ arc3.p0LongLat = p3;
85
+ arc3.p1LongLat = p1;
86
+ const bbox = {
87
+ min: [
88
+ Math.min(arc1.bbox.min[0], arc2.bbox.min[0], arc3.bbox.min[0]),
89
+ Math.min(arc1.bbox.min[1], arc2.bbox.min[1], arc3.bbox.min[1])
90
+ ],
91
+ max: [
92
+ Math.max(arc1.bbox.max[0], arc2.bbox.max[0], arc3.bbox.max[0]),
93
+ Math.max(arc1.bbox.max[1], arc2.bbox.max[1], arc3.bbox.max[1])
94
+ ],
95
+ };
96
+ const meta = {
97
+ arcs: [arc1, arc2, arc3],
98
+ bbox
99
+ };
100
+ showMeta(meta);
101
+ meta.shellPoints = createShellPoints(meta);
102
+ return meta;
103
+ }
104
+ function showMeta(triangleMeta) {
105
+ for (let i = 0; i < 3; i++) {
106
+ const arc = triangleMeta.arcs[i];
107
+ console.log(`Arc ${i} from ${showLongLatRadian(arc.p0LongLat)} to ${showLongLatRadian(arc.p1LongLat)}, bbox: min(${showLongLatRadian(arc.bbox.min)}) max(${showLongLatRadian(arc.bbox.max)})`);
108
+ if (arc.exceededLimit) {
109
+ console.log(`Exceeded limit at ${showLongLatRadian(vec3ToLongLatRadians(arc.exceededLimit))}`);
110
+ }
111
+ }
112
+ console.log(`Triangle BBOX: min(${showLongLatRadian(triangleMeta.bbox.min)}) max(${showLongLatRadian(triangleMeta.bbox.max)})`);
113
+ }
114
+ /**
115
+ *
116
+ * @param triangleMeta
117
+ * @param zoom
118
+ * @param angle
119
+ * @param dimension false for longitude (meridian) true for latitude (parallel)
120
+ */
121
+ export function getPoints(triangleMeta, angle, dimension) {
122
+ // console.log("getPoints called with angle:", angle * 180 / Math.PI, "dimension:", dimension ? 'latitude' : 'longitude');
123
+ // find which arcs are cut by plane
124
+ const radians = angle;
125
+ if (dimension) {
126
+ _plane.normal[0] = 0;
127
+ _plane.normal[1] = 0;
128
+ _plane.normal[2] = 1;
129
+ _plane.distance = Math.sin(radians);
130
+ }
131
+ else {
132
+ _plane.normal[0] = Math.sin(radians);
133
+ _plane.normal[1] = -Math.cos(radians);
134
+ _plane.normal[2] = 0;
135
+ _plane.distance = 0;
136
+ }
137
+ let result = [];
138
+ // Add debugging
139
+ let resultsFromDistinctArcs = 0;
140
+ for (let i = 0; i < 3; i++) {
141
+ const arc = triangleMeta.arcs[i];
142
+ const coordIndex = dimension ? 1 : 0;
143
+ const minCoord = arc.bbox.min[coordIndex];
144
+ const maxCoord = arc.bbox.max[coordIndex];
145
+ if (minCoord > angle || maxCoord < angle) {
146
+ continue; // arc is out of range
147
+ }
148
+ const count = pointsOnArc(arc, _plane, _resultPoints);
149
+ if (count === 1) {
150
+ result.push([[..._resultPoints[0]], vec3ToLongLatRadians(_resultPoints[0])]);
151
+ }
152
+ else if (count === 2) {
153
+ // throw new Error('Unexpected 2 cut points on arc, should be max 1'); // TODO DELETE this line later
154
+ result.push([[..._resultPoints[0]], vec3ToLongLatRadians(_resultPoints[0])]);
155
+ result.push([[..._resultPoints[1]], vec3ToLongLatRadians(_resultPoints[1])]); // TODO: this is a fix for a bug, need to investigate later
156
+ }
157
+ resultsFromDistinctArcs += 1;
158
+ }
159
+ if (resultsFromDistinctArcs === 3) {
160
+ result = filterDuplicate(result);
161
+ }
162
+ if (result.length !== 2 && result.length !== 4) {
163
+ // TODO: THERE is a case where 4 points are found.
164
+ // this happens when two arcs has limit and share space in Z dimension
165
+ console.log("ERROR");
166
+ const text = 'Angle:' + angle + ' dimension:' + (dimension ? 'latitude' : 'longitude') + "\n" +
167
+ 'Result points count:' + result.length + "\n" +
168
+ "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";
169
+ showMeta(triangleMeta);
170
+ for (let res of result) {
171
+ const ll = res[1];
172
+ console.log("Point: " + ll[0] * 180 / Math.PI + ", " + ll[1] * 180 / Math.PI + "\n");
173
+ }
174
+ throw new Error(`Unexpected cut count for tile cut, got: ${result.length}, angle: ${angle * 180 / Math.PI}, dimension: ${dimension ? 'latitude' : 'longitude'} \n` + text);
175
+ }
176
+ // TODO: i want to see it delete later
177
+ if (result.length === 4) {
178
+ console.warn("Warning: 4 cut points found on triangle for angle:", angle * 180 / Math.PI, "dimension:", dimension ? 'latitude' : 'longitude', "points:", result);
179
+ }
180
+ result.sort((a, b) => {
181
+ if (dimension) {
182
+ return a[0][1] - b[0][1]; // sort by y for longitude cuts
183
+ }
184
+ else {
185
+ return a[1][0] - b[1][0]; // sort by x for latitude cuts
186
+ }
187
+ });
188
+ return result;
189
+ }
190
+ function getEdgePoints(triangleMeta) {
191
+ const points = [
192
+ triangleMeta.arcs[0].p0,
193
+ triangleMeta.arcs[1].p0,
194
+ triangleMeta.arcs[2].p0,
195
+ ];
196
+ for (let i = 0; i < 3; i++) {
197
+ if (triangleMeta.arcs[i].exceededLimit) {
198
+ points.push(triangleMeta.arcs[i].exceededLimit);
199
+ }
200
+ }
201
+ return points;
202
+ }
203
+ // TODO: EDGES NEED ! LEVEL MORE ZOOM LEVEL OF RESOLUTION as THEY CAN BE NEIGHBOURS OF HIGHER ZOOM LEVEL TILES....
204
+ // simple strategy: get max zoom level of neighbour, add edge cuts based on that zoom level, do not fill inner points.
205
+ // partialTessellation cure this problem automatically
206
+ export function getAllPoints(triangleMeta, zoom, innerCuts = TILE_DEM_STEPCOUNT) {
207
+ // TODO: lonLengthRadian and latInnerStep might be change. Dynamic zoom level will show if needed
208
+ const points = [];
209
+ const longLatPoints = [];
210
+ // CALCULATE INFORMATION NEEDED FOR CUTTING
211
+ const tileCount = TILE_COUNTS[zoom];
212
+ const lonLengthRadian = 2 * Math.PI / tileCount / innerCuts; // inner step
213
+ const startMeridianRadian = triangleMeta.bbox.min[0];
214
+ const endMeridianRadian = triangleMeta.bbox.max[0];
215
+ const startParallelRadian = triangleMeta.bbox.min[1];
216
+ const endParallelRadian = triangleMeta.bbox.max[1];
217
+ // GET EDGE POINTS
218
+ const edgePoints = getEdgePoints(triangleMeta);
219
+ const shellPoints = triangleMeta.shellPoints;
220
+ for (let i = 0; i < edgePoints.length; i++) {
221
+ const longLat = vec3ToLongLatRadians(edgePoints[i]);
222
+ longLatPoints.push(...shellPoints[i]);
223
+ longLatPoints.push(...longLat);
224
+ points.push(0, 0, 0);
225
+ points.push(...edgePoints[i]);
226
+ }
227
+ // GET ALL PARRALLEL CUTS AND FILL MIDDLE POINTS
228
+ // how to calculate parallel tiles in range of bbox
229
+ const startTileY = latToTileY(startParallelRadian, zoom);
230
+ const endTileY = latToTileY(endParallelRadian, zoom);
231
+ const latInnerStep = 1 / innerCuts;
232
+ let currentY = startTileY - Math.abs(startTileY % latInnerStep);
233
+ if (currentY === startTileY)
234
+ currentY -= latInnerStep; // since start point is already added
235
+ let latCutCount = 0;
236
+ while (currentY > endTileY) {
237
+ const lat = tileYtoLat(currentY, zoom);
238
+ const concurances = getPoints(triangleMeta, lat, true);
239
+ for (let i = 0; i < concurances.length; i += 2) {
240
+ const p0 = concurances[i];
241
+ const p1 = concurances[i + 1];
242
+ points.push(...p0[0]);
243
+ longLatPoints.push(...p0[1]);
244
+ fillBetweenInParallels(lat, p0[1], p1[1], lonLengthRadian, points, longLatPoints);
245
+ points.push(...p1[0]);
246
+ longLatPoints.push(...p1[1]);
247
+ if (length(p0[0]) < 0.99 || length(p1[0]) < 0.99 || length(p0[0]) > 1.01 || length(p1[0]) > 1.01) {
248
+ console.warn("Warning: Cut point is not on unit sphere!", length(p0[0]), length(p1[0]));
249
+ }
250
+ }
251
+ currentY -= latInnerStep;
252
+ latCutCount++;
253
+ }
254
+ let currentLong = startMeridianRadian - startMeridianRadian % lonLengthRadian;
255
+ if (currentLong === startMeridianRadian)
256
+ currentLong += lonLengthRadian; // since start point is already added
257
+ while (currentLong < endMeridianRadian) {
258
+ const [p0, p1] = getPoints(triangleMeta, currentLong, false);
259
+ if (!isOnTileEdge(p0[1], zoom)) {
260
+ points.push(...p0[0]);
261
+ longLatPoints.push(...p0[1]);
262
+ }
263
+ if (!isOnTileEdge(p1[1], zoom)) {
264
+ points.push(...p1[0]);
265
+ longLatPoints.push(...p1[1]);
266
+ }
267
+ currentLong += lonLengthRadian;
268
+ }
269
+ const delaunator = new Delaunator(longLatPoints);
270
+ let indices = delaunator.triangles;
271
+ const edgeIndexes = shellPoints.map((e, index) => index * 2); // edge points are always first points in list
272
+ indices = filteroutEdgeConnections(indices, edgeIndexes);
273
+ // rotateIndices(indices);
274
+ return { vec3s: new Float32Array(points), longLats: new Float32Array(longLatPoints), indices: indices };
275
+ }
276
+ function fillBetweenInParallels(lat, p1, p2, step, fillVec3Arr, longLatPoints) {
277
+ // return;
278
+ // const start = Math.min(p1[0], p2[0]);
279
+ // const end = Math.max(p1[0], p2[0]);
280
+ const start = p1[0];
281
+ const end = p2[0];
282
+ // console.log("start:", start * 180 / Math.PI, "end:", end * 180 / Math.PI, "lat:", lat * 180 / Math.PI);
283
+ let current = start - (start % step);
284
+ while (current < end) {
285
+ const item = [current, lat];
286
+ fillVec3Arr.push(...createUnitVectorFromLongLat(item));
287
+ longLatPoints.push(...item);
288
+ current += step;
289
+ }
290
+ }
291
+ function filterDuplicate(points) {
292
+ const result = [points[0]];
293
+ let dublicate = false;
294
+ for (let i = 1; i < points.length; i++) {
295
+ for (let j = 0; j < result.length; j++) {
296
+ if (equals(points[i][0], result[j][0])) {
297
+ dublicate = true;
298
+ break;
299
+ }
300
+ }
301
+ if (!dublicate) {
302
+ result.push(points[i]);
303
+ }
304
+ }
305
+ return result;
306
+ }
307
+ function showLongLatRadian(longLat) {
308
+ return `(${(longLat[0] * 180 / Math.PI).toFixed(2)}°, ${(longLat[1] * 180 / Math.PI).toFixed(2)}°)`;
309
+ }
310
+ function rotateIndices(indices) {
311
+ const len = indices.length / 3;
312
+ let hold;
313
+ for (let i = 0; i < len; i++) {
314
+ hold = indices[i * 3];
315
+ indices[i * 3] = indices[i * 3 + 1];
316
+ indices[i * 3 + 1] = hold;
317
+ }
318
+ return indices;
319
+ }
320
+ // This method for removing external edge connections. The connections are unnecessary and cause a veil descending to the center of sphere from the edges
321
+ function filteroutEdgeConnections(indexes, filterOutIndexes) {
322
+ const length = indexes.length / 3;
323
+ const result = [];
324
+ for (let i = 0; i < length; i++) {
325
+ let pass = false;
326
+ for (let filterIndex of filterOutIndexes) {
327
+ if (indexes[i * 3] === filterIndex || indexes[i * 3 + 1] === filterIndex || indexes[i * 3 + 2] === filterIndex) {
328
+ pass = true;
329
+ break;
330
+ }
331
+ }
332
+ if (pass)
333
+ continue;
334
+ result.push(indexes[i * 3], indexes[i * 3 + 1], indexes[i * 3 + 2]);
335
+ }
336
+ return new Uint32Array(result);
337
+ }
338
+ /**
339
+ * @unlockedPerk cache
340
+ * final outpout can be saved on a hashmap since this triangles are static
341
+ */
342
+ function shredTriangleTessellationMeta(triangleMeta, zoomLevel) {
343
+ /**
344
+ * What if tile is covered by the curve of the limit of a single arc.
345
+ */
346
+ const result = [];
347
+ // cut triangleMeta into smaller triangles based on zoom level...
348
+ return result;
349
+ }
350
+ /**
351
+ * @lockedPerk cache
352
+ *
353
+ * cache can be applied at tile triangle intersection level;
354
+ *
355
+ * @unlockedPerk smoothZoomTransition
356
+ *
357
+ * @puzzle triangle should be covered without duplicate points. A tile can be covered by a bigger one.
358
+ * @solution bbox cuts:
359
+ * Ax 1 x x is higher zoom level tile, A is a tile that covers it. 1 2 3 should be asked with A zoom level.
360
+ * AA -> Problem1: 1 2 3 x will have edge points duplicated
361
+ * 2 3 p1 sol1: edges can be taged, or added separately by and algorithm that only adds edge poitns.
362
+ *
363
+ * still all triangles should have some sort of cached tessellation to fast render on rapit earth rotation
364
+ */
365
+ /**
366
+ * Creates a mesh for a spherical triangle, tessellated only within the
367
+ * regions specified by the `limits` array.
368
+ *
369
+ * @param triangleMeta The metadata for the spherical triangle.
370
+ * @param limits An array of bounding boxes and their associated zoom levels to tessellate.
371
+ * @param innerCuts The number of subdivisions within each tile (e.g., TILE_DEM_STEPCOUNT).
372
+ * @returns A set of arrays (vec3s, longLats, indices) representing the partial mesh.
373
+ */
374
+ export function partialTessellation(triangleMeta, limits, innerCuts) {
375
+ // TODO: pointMap can be local variable and cleaned after function call to avoid reinitialization overhead
376
+ const pointMap = new Map(); // Key: "lon|lat", Value: index
377
+ const allVec3s = [];
378
+ const allLongLats = [];
379
+ let pointCounter = 0;
380
+ /**
381
+ * Precision for coordinate keys in the map. 1e-12 radians is
382
+ * extremely small (sub-millimeter on Earth's surface) and avoids
383
+ * floating point inaccuracies causing duplicate points.
384
+ */
385
+ const KEY_PRECISION = 10;
386
+ /**
387
+ * Adds a point to the vertex arrays if it doesn't already exist.
388
+ * Returns the index of the point (new or existing).
389
+ */
390
+ const addPoint = (longLat, vec3) => {
391
+ const key = `${longLat[0].toPrecision(KEY_PRECISION)}|${longLat[1].toPrecision(KEY_PRECISION)}`;
392
+ let index = pointMap.get(key);
393
+ if (index !== undefined) {
394
+ return index; // Point already exists
395
+ }
396
+ // Point is new, add it
397
+ const v3 = vec3 || createUnitVectorFromLongLat(longLat);
398
+ allVec3s.push(...v3);
399
+ allLongLats.push(...longLat);
400
+ index = pointCounter++;
401
+ pointMap.set(key, index);
402
+ return index;
403
+ };
404
+ // 1. Add triangle's "shell" (for Delaunay) and "edge" (vertices/limits) points
405
+ // These points constrain the triangulation.
406
+ const shellPointIndices = [];
407
+ const edgePoints = getEdgePoints(triangleMeta);
408
+ // Assuming shellPoints and edgePoints have the same length and correspond
409
+ const shellPointCount = Math.min(triangleMeta.shellPoints.length, edgePoints.length);
410
+ for (let i = 0; i < shellPointCount; i++) {
411
+ // Add the "shell" point (for Delaunay stability)
412
+ shellPointIndices.push(addPoint(triangleMeta.shellPoints[i]));
413
+ // Add the actual "edge" point (triangle vertex or limit point)
414
+ addPoint(vec3ToLongLatRadians(edgePoints[i]), edgePoints[i]);
415
+ }
416
+ // 2. Iterate through each tile limit
417
+ for (const { bbox: tileBBox, zoom } of limits) {
418
+ // 2a. Calculate the intersection BBOX (the area we'll work on)
419
+ const workBBox = {
420
+ min: [
421
+ Math.max(triangleMeta.bbox.min[0], tileBBox.min[0]),
422
+ Math.max(triangleMeta.bbox.min[1], tileBBox.min[1])
423
+ ],
424
+ max: [
425
+ Math.min(triangleMeta.bbox.max[0], tileBBox.max[0]),
426
+ Math.min(triangleMeta.bbox.max[1], tileBBox.max[1])
427
+ ],
428
+ };
429
+ // If the intersection is invalid (no overlap), skip this tile
430
+ if (workBBox.min[0] >= workBBox.max[0] || workBBox.min[1] >= workBBox.max[1]) {
431
+ continue;
432
+ }
433
+ // 2b. Calculate grid steps for this tile's zoom
434
+ const tileCount = TILE_COUNTS[zoom];
435
+ const lonStep = (2 * Math.PI) / tileCount / innerCuts;
436
+ const latStep = 1.0 / innerCuts; // This is in tileY units
437
+ // 2c. Generate Latitude (Parallel) Points
438
+ const startTileY = latToTileY(workBBox.max[1], zoom); // max lat -> min tileY
439
+ const endTileY = latToTileY(workBBox.min[1], zoom); // min lat -> max tileY
440
+ let currentY = Math.ceil(startTileY / latStep) * latStep;
441
+ if (currentY < startTileY - 1e-9)
442
+ currentY += latStep; // Ensure we start inside or on edge
443
+ while (currentY <= endTileY + 1e-9) {
444
+ const lat = tileYtoLat(currentY, zoom);
445
+ // Skip if rounding put us slightly outside the work box
446
+ if (lat < workBBox.min[1] - 1e-9 || lat > workBBox.max[1] + 1e-9) {
447
+ currentY += latStep;
448
+ continue;
449
+ }
450
+ // Find where this latitude line intersects the triangle
451
+ const intersections = getPoints(triangleMeta, lat, true);
452
+ for (let i = 0; i < intersections.length; i += 2) {
453
+ const p0 = intersections[i]; // [Vec3, LongLatRadian]
454
+ const p1 = intersections[i + 1];
455
+ // Find the segment of this latitude line that is *inside* both
456
+ // the triangle (p0-p1) AND the tile BBOX (workBBox)
457
+ const triMinLon = Math.min(p0[1][0], p1[1][0]);
458
+ const triMaxLon = Math.max(p0[1][0], p1[1][0]);
459
+ const segMinLon = Math.max(workBBox.min[0], triMinLon);
460
+ const segMaxLon = Math.min(workBBox.max[0], triMaxLon);
461
+ // If this clipped segment is valid, generate points
462
+ if (segMinLon < segMaxLon - 1e-9) {
463
+ // Add the exact start and end points of the clipped segment
464
+ addPoint([segMinLon, lat]);
465
+ addPoint([segMaxLon, lat]);
466
+ // Add fill points *between* them
467
+ let currentLon = Math.ceil(segMinLon / lonStep) * lonStep;
468
+ if (currentLon < segMinLon - 1e-9)
469
+ currentLon += lonStep;
470
+ while (currentLon < segMaxLon - 1e-9) {
471
+ addPoint([currentLon, lat]);
472
+ currentLon += lonStep;
473
+ }
474
+ }
475
+ }
476
+ currentY += latStep;
477
+ }
478
+ // 2d. Generate Longitude (Meridian) Points
479
+ const startLon = workBBox.min[0];
480
+ const endLon = workBBox.max[0];
481
+ let currentLon = Math.ceil(startLon / lonStep) * lonStep;
482
+ if (currentLon < startLon - 1e-9)
483
+ currentLon += lonStep;
484
+ while (currentLon <= endLon + 1e-9) {
485
+ // Find where this longitude line intersects the triangle
486
+ const intersections = getPoints(triangleMeta, currentLon, false);
487
+ for (const p of intersections) {
488
+ const pLongLat = p[1];
489
+ // Check if this point is inside the *workBBox*
490
+ if (pLongLat[1] >= workBBox.min[1] - 1e-9 &&
491
+ pLongLat[1] <= workBBox.max[1] + 1e-9) {
492
+ addPoint(pLongLat, p[0]);
493
+ }
494
+ }
495
+ currentLon += lonStep;
496
+ }
497
+ } // End loop over limits
498
+ // 3. Triangulate
499
+ // We must have at least 3 points to make a triangle
500
+ if (pointCounter < 3) {
501
+ return {
502
+ vec3s: new Float32Array(),
503
+ longLats: new Float32Array(),
504
+ indices: new Uint32Array(),
505
+ };
506
+ }
507
+ const delaunator = new Delaunator(allLongLats);
508
+ let indices = delaunator.triangles;
509
+ // 4. Filter out triangles connected to the "shell" points
510
+ indices = filteroutEdgeConnections(indices, shellPointIndices);
511
+ return {
512
+ vec3s: new Float32Array(allVec3s),
513
+ longLats: new Float32Array(allLongLats),
514
+ indices: indices,
515
+ };
516
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @author Toprak Ozturk
3
+ *
4
+ */
5
+ import { createTriangleTessellationMeta, getAllPoints, partialTessellation } from "./triangle-tessellation-meta";
6
+ export function test1(zoomLevel, p1, p2, p3) {
7
+ const triangleMeta = createTriangleTessellationMeta(p1, p2, p3);
8
+ const { vec3s, longLats, indices } = getAllPoints(triangleMeta, zoomLevel);
9
+ return { vec3s, longLats, indices };
10
+ }
11
+ export function partialTest(bboxZooms, p1, p2, p3) {
12
+ const triangleMeta = createTriangleTessellationMeta(p1, p2, p3);
13
+ return partialTessellation(triangleMeta, bboxZooms, 5);
14
+ }
@@ -0,0 +1 @@
1
+ export const TILE_COUNTS = Array.from({ length: 22 }, (_, i) => Math.pow(2, i));
package/Math/vec3.js CHANGED
@@ -7,6 +7,11 @@ function set(out, x, y, z) {
7
7
  out[1] = y;
8
8
  out[2] = z;
9
9
  }
10
+ function negate(item) {
11
+ item[0] = -item[0];
12
+ item[1] = -item[1];
13
+ item[2] = -item[2];
14
+ }
10
15
  function clone(a) {
11
16
  return [a[0], a[1], a[2]];
12
17
  }
@@ -100,6 +105,14 @@ function fromLongLatToUnitVector(out, longLat) {
100
105
  out[1] = cosLat * Math.sin(longitude);
101
106
  out[2] = Math.sin(latitude);
102
107
  }
108
+ function createUnitVectorFromLongLat(longLat) {
109
+ const cosLat = Math.cos(longLat[1]);
110
+ return [
111
+ cosLat * Math.cos(longLat[0]),
112
+ cosLat * Math.sin(longLat[0]),
113
+ Math.sin(longLat[1])
114
+ ];
115
+ }
103
116
  function applyQuaternion(out, a, q) {
104
117
  const x = a[0], y = a[1], z = a[2];
105
118
  const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
@@ -123,4 +136,16 @@ function randomUnit(out) {
123
136
  function str(a) {
124
137
  return `Vec3(${a[0].toFixed(2)}, ${a[1].toFixed(2)}, ${a[2].toFixed(2)})`;
125
138
  }
126
- export { create, set, clone, copy, add, subtract, dot, cross, multiplyScalar, divideScalar, lengthSquared, length, normalize, distanceSquared, distance, equals, fromUnitVectorToLongLat, fromLongLatToUnitVector, applyQuaternion, randomUnit, str };
139
+ function vec3ToLongLatDegrees(v) {
140
+ return [
141
+ Math.atan2(v[1], v[0]) * 180 / Math.PI,
142
+ Math.asin(v[2]) * 180 / Math.PI
143
+ ];
144
+ }
145
+ function vec3ToLongLatRadians(v) {
146
+ return [
147
+ Math.atan2(v[1], v[0]),
148
+ Math.asin(v[2])
149
+ ];
150
+ }
151
+ export { create, set, clone, copy, add, subtract, negate, dot, cross, multiplyScalar, divideScalar, lengthSquared, length, normalize, distanceSquared, distance, equals, fromUnitVectorToLongLat, fromLongLatToUnitVector, applyQuaternion, randomUnit, str, createUnitVectorFromLongLat, vec3ToLongLatDegrees, vec3ToLongLatRadians };