@pirireis/webglobeplugins 0.17.0 → 1.0.2
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.js → angle-calculation.ts} +18 -14
- package/Math/{arc-cdf-points.js → arc-cdf-points.ts} +329 -272
- package/Math/{arc-generate-points-exponantial.js → arc-generate-points-exponantial.ts} +299 -254
- package/Math/{arc.js → arc.ts} +421 -292
- package/Math/bounds/line-bbox.js +225 -186
- package/Math/{circle-cdf-points.js → circle-cdf-points.ts} +143 -78
- package/Math/{circle.js → circle.ts} +49 -33
- package/Math/{constants.js → constants.ts} +12 -4
- package/Math/contour/{quadtreecontours.js → quadtreecontours.ts} +371 -300
- package/Math/contour/quadtreecontours1.js +336 -298
- package/Math/{finite-line-2d.js → finite-line-2d.ts} +68 -58
- package/Math/haversine.ts +33 -0
- package/Math/index.js +0 -1
- package/Math/juction/{arc-plane.js → arc-plane.ts} +203 -143
- package/Math/juction/{line-sphere.js → line-sphere.ts} +32 -22
- package/Math/juction/{plane-plane.js → plane-plane.ts} +62 -53
- package/Math/{line.js → line.ts} +84 -52
- package/Math/matrix4.ts +0 -0
- package/Math/mesh/mapbox-delaunay.d.ts +74 -0
- package/Math/{methods.js → methods.ts} +182 -107
- package/Math/{plane.js → plane.ts} +92 -56
- package/Math/{quaternion.js → quaternion.ts} +128 -106
- package/Math/roadmap.md +10 -0
- package/Math/templete-shapes/{grid-visually-equal.js → grid-visually-equal.ts} +118 -65
- package/Math/tessellation/constants.ts +1 -0
- package/Math/tessellation/methods.ts +79 -0
- package/Math/tessellation/nearest-value-padding.ts +147 -0
- package/Math/tessellation/roadmap.md +48 -0
- package/Math/tessellation/spherical-triangle-area.ts +127 -0
- package/Math/tessellation/tile-merger.ts +578 -0
- package/Math/tessellation/triangle-tessellation.ts +533 -0
- package/Math/tessellation/types.ts +1 -0
- package/Math/types.ts +68 -0
- package/Math/utils.js +3 -2
- package/Math/{vec3.js → vec3.ts} +227 -151
- package/Math/xyz-tile.ts +26 -0
- package/algorithms/search-binary.js +14 -16
- package/altitude-locator/adaptors.js +0 -1
- package/altitude-locator/keymethod.js +0 -1
- package/altitude-locator/plugin.js +445 -345
- package/altitude-locator/types.js +26 -21
- package/compass-rose/compass-rose-padding-flat.js +274 -230
- package/compass-rose/{compass-text-writer.js → compass-text-writer.ts} +210 -155
- package/compass-rose/index.js +3 -3
- package/{constants.js → constants.ts} +8 -6
- package/heatwave/datamanager.js +168 -149
- package/heatwave/heatwave.js +261 -206
- package/heatwave/index.js +5 -5
- package/heatwave/isobar.js +340 -303
- package/heatwave/{texture-point-sampler.js → texture-point-sampler.ts} +220 -187
- package/investigation-tools/draw/tiles/adapters.ts +133 -0
- package/investigation-tools/draw/tiles/tiles.ts +162 -0
- package/jest.config.js +6 -7
- package/package.json +1 -1
- package/pin/pin-object-array1.js +381 -300
- package/pin/pin-point-totem1.js +77 -60
- package/programs/arrowfield/arrow-field.js +89 -60
- package/programs/arrowfield/logic.js +173 -141
- package/programs/data2legend/density-to-legend.js +86 -68
- package/programs/data2legend/point-to-density-texture.js +84 -67
- package/programs/float2legendwithratio/index.js +3 -2
- package/programs/float2legendwithratio/logic.js +144 -118
- package/programs/float2legendwithratio/object.js +141 -104
- package/programs/helpers/blender.js +73 -58
- package/programs/helpers/{fadeaway.js → fadeaway.ts} +73 -55
- package/programs/index.js +19 -20
- package/programs/line-on-globe/circle-accurate-3d.js +112 -85
- package/programs/line-on-globe/circle-accurate-flat.js +200 -148
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +134 -102
- package/programs/line-on-globe/index.js +0 -1
- package/programs/line-on-globe/lines-color-instanced-flat.js +99 -80
- package/programs/line-on-globe/linestrip/data.ts +29 -0
- package/programs/line-on-globe/linestrip/{linestrip.js → linestrip.ts} +152 -93
- package/programs/line-on-globe/{naive-accurate-flexible.js → naive-accurate-flexible.ts} +175 -126
- package/programs/line-on-globe/util.js +8 -5
- package/programs/picking/pickable-polygon-renderer.js +129 -98
- package/programs/picking/pickable-renderer.js +130 -98
- package/programs/point-on-globe/element-globe-surface-glow.js +122 -93
- package/programs/point-on-globe/element-point-glow.js +114 -80
- package/programs/point-on-globe/square-pixel-point.js +139 -120
- package/programs/polygon-on-globe/roadmap.md +8 -0
- package/programs/polygon-on-globe/texture-dem-triangles.ts +290 -0
- package/programs/{programcache.js → programcache.ts} +134 -126
- package/programs/rings/index.js +1 -1
- package/programs/rings/partial-ring/{piece-of-pie.js → piece-of-pie.ts} +222 -152
- package/programs/totems/camera-totem-attactment-interface.ts +4 -0
- package/programs/totems/{camerauniformblock.js → camerauniformblock.ts} +326 -230
- package/programs/totems/{canvas-webglobe-info.js → canvas-webglobe-info.ts} +147 -132
- package/programs/totems/dem-textures-manager.ts +368 -0
- package/programs/totems/{globe-changes.js → globe-changes.ts} +79 -59
- package/programs/totems/gpu-selection-uniform-block.js +127 -99
- package/programs/totems/{index.js → index.ts} +2 -2
- package/programs/two-d/pixel-padding-for-compass.js +101 -87
- package/programs/util.js +19 -14
- package/programs/vectorfields/logics/{constants.js → constants.ts} +5 -4
- package/programs/vectorfields/logics/drawrectangleparticles.ts +182 -0
- package/programs/vectorfields/logics/index.js +4 -2
- package/programs/vectorfields/logics/particle-ubo.ts +23 -0
- package/programs/vectorfields/logics/{pixelbased.js → pixelbased.ts} +119 -84
- package/programs/vectorfields/logics/ubo.js +57 -51
- package/programs/vectorfields/{pingpongbuffermanager.js → pingpongbuffermanager.ts} +113 -73
- package/publish.bat +62 -0
- package/range-tools-on-terrain/bearing-line/{adapters.js → adapters.ts} +154 -114
- package/range-tools-on-terrain/bearing-line/{plugin.js → plugin.ts} +569 -457
- package/range-tools-on-terrain/bearing-line/types.ts +65 -0
- package/range-tools-on-terrain/circle-line-chain/{adapters.js → adapters.ts} +104 -85
- package/range-tools-on-terrain/circle-line-chain/{chain-list-map.js → chain-list-map.ts} +446 -382
- package/range-tools-on-terrain/circle-line-chain/{plugin.js → plugin.ts} +607 -464
- package/range-tools-on-terrain/circle-line-chain/types.ts +43 -0
- package/range-tools-on-terrain/range-ring/{adapters.js → adapters.ts} +114 -93
- package/range-tools-on-terrain/range-ring/{enum.js → enum.ts} +2 -2
- package/range-tools-on-terrain/range-ring/{plugin.js → plugin.ts} +444 -377
- package/range-tools-on-terrain/range-ring/rangeringangletext.ts +396 -0
- package/range-tools-on-terrain/range-ring/types.ts +30 -0
- package/semiplugins/interface.ts +14 -0
- package/semiplugins/lightweight/{line-plugin.js → line-plugin.ts} +342 -221
- package/semiplugins/lightweight/{piece-of-pie-plugin.js → piece-of-pie-plugin.ts} +275 -200
- package/semiplugins/shape-on-terrain/{arc-plugin.js → arc-plugin.ts} +616 -472
- package/semiplugins/shape-on-terrain/{circle-plugin.js → circle-plugin.ts} +588 -444
- package/semiplugins/shape-on-terrain/goal.md +12 -0
- package/semiplugins/shape-on-terrain/{padding-1-degree.js → padding-1-degree.ts} +713 -539
- package/semiplugins/shape-on-terrain/terrain-polygon/adapters.ts +69 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/cache-shortcuts.md +20 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/cache.ts +149 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/index-polygon-map.ts +58 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/manager.ts +4 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +196 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.ts +209 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/polygon-to-triangles.ts +144 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/random.ts +165 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/readme.md +5 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/types.ts +37 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/worker-contact.ts +81 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +146 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/notes.md +90 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/terrain-polygon.ts +265 -0
- package/semiplugins/shape-on-terrain/terrain-polygon/types.ts +69 -0
- package/semiplugins/shell/bbox-renderer/index.ts +2 -0
- package/semiplugins/shell/bbox-renderer/{logic.js → logic.ts} +273 -249
- package/semiplugins/shell/bbox-renderer/object.ts +129 -0
- package/semiplugins/type.ts +8 -0
- package/semiplugins/utility/{container-plugin.js → container-plugin.ts} +126 -94
- package/semiplugins/utility/{object-pass-container-plugin.js → object-pass-container-plugin.ts} +101 -80
- package/shaders/fragment-toy/firework.js +1 -1
- package/shaders/fragment-toy/singularity.js +5 -2
- package/terrain-plugin.mmd +83 -0
- package/tests/Math/arc-sampling-test.js +367 -0
- package/tests/Math/arc-sampling-test.ts +429 -0
- package/tests/Math/arc.test.ts +77 -0
- package/tests/Math/junction/arc-limit.test.ts +7 -0
- package/tests/Math/junction/arc-plane-points.test.ts +196 -0
- package/tests/Math/junction/arc-plane.test.ts +172 -0
- package/tests/Math/junction/line-sphere.test.ts +127 -0
- package/tests/Math/junction/plane-plane.test.ts +91 -0
- package/tests/Math/plane-test.ts +17 -0
- package/tests/Math/plane.test.ts +43 -0
- package/tests/Math/vec3.test.ts +33 -0
- package/tracks/point-heat-map/adaptors/timetracksplugin-format-to-this.js +78 -63
- package/tracks/point-heat-map/index.js +0 -1
- package/tracks/point-heat-map/plugin-webworker.js +148 -121
- package/tracks/point-heat-map/point-to-heat-map-flow.js +150 -121
- package/tracks/point-heat-map/readme.md +15 -0
- package/tracks/point-tracks/key-methods.js +3 -2
- package/tracks/point-tracks/plugin.js +487 -393
- package/tracks/timetracks/adaptors-line-strip.js +79 -65
- package/tracks/timetracks/plugin-line-strip.js +295 -240
- package/tracks/timetracks/program-line-strip.js +495 -411
- package/tracks/timetracks/programpoint-line-strip.js +137 -109
- package/tracks/timetracks/readme.md +1 -0
- package/tsconfig.json +22 -0
- package/types/@pirireis/webglobe.d.ts +102 -0
- package/types/delaunator.d.ts +40 -0
- package/types/earcut.d.ts +11 -0
- package/types/rbush.d.ts +57 -0
- package/types.ts +319 -0
- package/util/account/bufferoffsetmanager.js +209 -176
- package/util/account/create-buffermap-orchastration.ts +85 -0
- package/util/account/index.js +6 -3
- package/util/account/single-attribute-buffer-management/{buffer-manager.js → buffer-manager.ts} +151 -117
- package/util/account/single-attribute-buffer-management/{buffer-orchestrator.js → buffer-orchestrator.ts} +238 -212
- package/util/account/single-attribute-buffer-management/{buffer-orchestrator1.js → buffer-orchestrator1.ts} +184 -159
- package/util/account/single-attribute-buffer-management/{index.js → index.ts} +11 -4
- package/util/account/single-attribute-buffer-management/{object-store.js → object-store.ts} +76 -55
- package/util/account/single-attribute-buffer-management/types.ts +43 -0
- package/util/account/util.js +22 -18
- package/util/algorithms/index.js +0 -1
- package/util/algorithms/search-binary.js +26 -25
- package/util/build-strategy/{static-dynamic.js → static-dynamic.ts} +50 -41
- package/util/check/index.js +0 -1
- package/util/check/typecheck.ts +74 -0
- package/util/{frame-counter-trigger.js → frame-counter-trigger.ts} +99 -84
- package/util/geometry/{index.js → index.ts} +155 -121
- package/util/gl-util/buffer/{attribute-loader.js → attribute-loader.ts} +84 -62
- package/util/gl-util/buffer/{index.js → index.ts} +6 -3
- package/util/gl-util/draw-options/{methods.js → methods.ts} +47 -32
- package/util/gl-util/uniform-block/{manager.js → manager.ts} +232 -190
- package/util/{webglobe/gldefaultstates.js → globe-default-gl-states.ts} +5 -4
- package/util/helper-methods.ts +9 -0
- package/util/index.js +9 -10
- package/util/interpolation/index.js +0 -1
- package/util/interpolation/timetrack/index.js +9 -2
- package/util/interpolation/timetrack/timetrack-interpolator.js +94 -79
- package/util/interpolation/timetrack/web-worker.js +51 -46
- package/util/picking/{fence.js → fence.ts} +47 -41
- package/util/picking/picker-displayer.ts +226 -0
- package/util/programs/draw-from-pixel-coords.js +201 -164
- package/util/programs/{draw-texture-on-canvas.js → draw-texture-on-canvas.ts} +92 -67
- package/util/programs/supersampletotextures.js +130 -97
- package/util/programs/texturetoglobe.js +153 -128
- package/util/shaderfunctions/{geometrytransformations.js → geometrytransformations.ts} +169 -41
- package/util/shaderfunctions/index.js +2 -2
- package/util/shaderfunctions/nodata.js +4 -2
- package/util/shaderfunctions/noisefunctions.js +10 -7
- package/util/{webglobjectbuilders.js → webglobjectbuilders.ts} +446 -358
- package/vectorfield/arrowfield/adaptor.js +11 -11
- package/vectorfield/arrowfield/index.js +3 -3
- package/vectorfield/arrowfield/plugin.js +128 -83
- package/vectorfield/waveparticles/adaptor.js +16 -15
- package/vectorfield/waveparticles/index.js +3 -3
- package/vectorfield/waveparticles/plugin.ts +506 -0
- package/vectorfield/wind/adapters/image-to-fields.ts +74 -0
- package/vectorfield/wind/adapters/types.ts +12 -0
- package/vectorfield/wind/{imagetovectorfieldandmagnitude.js → imagetovectorfieldandmagnitude.ts} +78 -56
- package/vectorfield/wind/index.js +5 -5
- package/vectorfield/wind/plugin-persistant copy.ts +461 -0
- package/vectorfield/wind/plugin-persistant.ts +483 -0
- package/vectorfield/wind/plugin.js +883 -671
- package/vectorfield/wind/vectorfieldimage.js +27 -23
- package/write-text/{context-text-bulk.js → context-text-bulk.ts} +285 -200
- package/write-text/context-text3.ts +252 -0
- package/write-text/{context-text4.js → context-text4.ts} +231 -145
- package/write-text/context-textDELETE.js +125 -94
- package/write-text/objectarraylabels/{index.js → index.ts} +2 -2
- package/write-text/objectarraylabels/objectarraylabels.d.ts +72 -0
- package/write-text/objectarraylabels/objectarraylabels.js +247 -200
- package/Math/matrix4.js +0 -1
- package/Math/tessellation/earcut/adapters.js +0 -37
- package/Math/tessellation/hybrid-triangle-tessellation-meta.js +0 -123
- package/Math/tessellation/methods.js +0 -46
- package/Math/tessellation/shred-input.js +0 -18
- package/Math/tessellation/tile-merger.js +0 -56
- package/Math/tessellation/tiler.js +0 -50
- package/Math/tessellation/triangle-tessellation-meta.js +0 -516
- package/Math/tessellation/triangle-tessellation.js +0 -14
- package/Math/tessellation/types.js +0 -1
- package/Math/tessellation/zoom-catch.js +0 -1
- package/Math/types.js +0 -1
- package/programs/line-on-globe/linestrip/data.js +0 -4
- package/programs/polygon-on-globe/partial-tesselation.js +0 -1
- package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +0 -204
- package/programs/polygon-on-globe/texture-dem-triangle-test-plugin.js +0 -118
- package/programs/polygon-on-globe/texture-dem-triangles.js +0 -236
- package/programs/vectorfields/logics/drawrectangleparticles.js +0 -112
- package/programs/vectorfields/logics/ubo-new.js +0 -25
- package/range-tools-on-terrain/bearing-line/types.js +0 -1
- package/range-tools-on-terrain/circle-line-chain/types.js +0 -1
- package/range-tools-on-terrain/range-ring/rangeringangletext.js +0 -331
- package/range-tools-on-terrain/range-ring/types.js +0 -9
- package/semiplugins/interface.js +0 -1
- package/semiplugins/shape-on-terrain/terrain-cover/texture-dem-cover.js +0 -1
- package/semiplugins/shell/bbox-renderer/index.js +0 -2
- package/semiplugins/shell/bbox-renderer/object.js +0 -65
- package/semiplugins/type.js +0 -1
- package/types.js +0 -19
- package/util/account/create-buffermap-orchastration.js +0 -39
- package/util/account/single-attribute-buffer-management/types.js +0 -1
- package/util/check/typecheck.js +0 -66
- package/util/gl-util/uniform-block/types.js +0 -1
- package/util/picking/picker-displayer.js +0 -134
- package/util/webglobe/index.js +0 -2
- package/util/webglobe/rasteroverlay.js +0 -76
- package/vectorfield/waveparticles/plugin.js +0 -290
- package/write-text/attached-text-writer.js +0 -95
- package/write-text/context-text3.js +0 -167
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import earcut from "earcut";
|
|
2
|
-
import { createTriangleTessellationMeta } from "./triangle-tessellation-meta";
|
|
3
|
-
function shredInput(vertices, holes, zoomLevel) {
|
|
4
|
-
const result = [];
|
|
5
|
-
const triangles = earcut(vertices, holes, 2);
|
|
6
|
-
for (let i = 0; i < triangles.length; i += 3) {
|
|
7
|
-
const idx1 = triangles[i] * 2;
|
|
8
|
-
const idx2 = triangles[i + 1] * 2;
|
|
9
|
-
const idx3 = triangles[i + 2] * 2;
|
|
10
|
-
const p1 = [vertices[idx1], vertices[idx1 + 1]];
|
|
11
|
-
const p2 = [vertices[idx2], vertices[idx2 + 1]];
|
|
12
|
-
const p3 = [vertices[idx3], vertices[idx3 + 1]];
|
|
13
|
-
const triangleMeta = createTriangleTessellationMeta(p1, p2, p3);
|
|
14
|
-
result.push(triangleMeta);
|
|
15
|
-
}
|
|
16
|
-
// cut triangles into smaller pieces based on zoom level...
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// /**
|
|
3
|
-
// * Find length in x and y for a tile in given zoom level (in wgs84)
|
|
4
|
-
// * Find tile cuts for given line represented by two points
|
|
5
|
-
// * Find inner position of point in tile
|
|
6
|
-
// *
|
|
7
|
-
// */
|
|
8
|
-
// import { LongLat } from "../../types";
|
|
9
|
-
// export function tileLength(zoom: number): LongLat {
|
|
10
|
-
// const tileSize = 256; // in pixels
|
|
11
|
-
// const worldSize = tileSize * Math.pow(2, zoom);
|
|
12
|
-
// const latLength = 180 / worldSize;
|
|
13
|
-
// const lonLength = 360 / worldSize;
|
|
14
|
-
// return [lonLength, latLength];
|
|
15
|
-
// }
|
|
16
|
-
// // export function tileCuts(p1: LongLat, p2: LongLat, zoom: number): LongLat[] {
|
|
17
|
-
// // const cuts: LongLat[] = [];
|
|
18
|
-
// // const tileSize = 256;
|
|
19
|
-
// // const worldSize = tileSize * Math.pow(2, zoom);
|
|
20
|
-
// // const latLength = 180 / worldSize;
|
|
21
|
-
// // const lonLength = 360 / worldSize;
|
|
22
|
-
// // const x1 = (p1[0] + 180) / lonLength;
|
|
23
|
-
// // const y1 = (90 - p1[1]) / latLength;
|
|
24
|
-
// // const x2 = (p2[0] + 180) / lonLength;
|
|
25
|
-
// // const y2 = (90 - p2[1]) / latLength;
|
|
26
|
-
// // const dx = x2 - x1;
|
|
27
|
-
// // const dy = y2 - y1;
|
|
28
|
-
// // const steps = Math.max(Math.abs(dx), Math.abs(dy));
|
|
29
|
-
// // const xStep = dx / steps;
|
|
30
|
-
// // const yStep = dy / steps;
|
|
31
|
-
// // let x = x1;
|
|
32
|
-
// // let y = y1;
|
|
33
|
-
// // for (let i = 0; i <= steps; i++) {
|
|
34
|
-
// // const tileX = Math.floor(x);
|
|
35
|
-
// // const tileY = Math.floor(y);
|
|
36
|
-
// // const cutX = tileX * lonLength - 180;
|
|
37
|
-
// // const cutY = 90 - tileY * latLength;
|
|
38
|
-
// // const cut: LongLat = [cutX, cutY];
|
|
39
|
-
// // if (cuts.length === 0 || (cuts[cuts.length - 1][0] !== cut[0] || cuts[cuts.length - 1][1] !== cut[1])) {
|
|
40
|
-
// // cuts.push(cut);
|
|
41
|
-
// // }
|
|
42
|
-
// // x += xStep;
|
|
43
|
-
// // y += yStep;
|
|
44
|
-
// // }
|
|
45
|
-
// // return cuts;
|
|
46
|
-
// // }
|
|
47
|
-
// // function fillTriangle(p1: LongLat, p2: LongLat, p3: LongLat, zoom: number): {positions:LongLat[], indices:number[]} {
|
|
48
|
-
// // // this function fills the triangle triangle iteratively
|
|
49
|
-
// // //
|
|
50
|
-
// // }
|
|
@@ -1,516 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const TILE_COUNTS = Array.from({ length: 22 }, (_, i) => Math.pow(2, i));
|
package/Math/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|