@pirireis/webglobeplugins 0.16.4 → 0.16.7

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/arc.js CHANGED
@@ -10,6 +10,15 @@ const _originPlane = /*@__PURE__*/ planeCreate(vec3create(0, 0, 1), 0);
10
10
  // dont change distance of _originPlane
11
11
  const _rotationQuaternion = /*@__PURE__*/ quaternionCreate();
12
12
  const _longLat = /*@__PURE__*/ [0, 0];
13
+ // Normalize angles to [0, 2π)
14
+ function normalizeLon(angle) {
15
+ while (angle < 0)
16
+ angle += 2 * Math.PI;
17
+ while (angle >= 2 * Math.PI)
18
+ angle -= 2 * Math.PI;
19
+ return angle;
20
+ }
21
+ ;
13
22
  function create(p0, p1) {
14
23
  const normal = vec3create(0, 0, 0);
15
24
  cross(normal, p0, p1);
@@ -25,7 +34,6 @@ function create(p0, p1) {
25
34
  // Handle opposite points case
26
35
  const tempPlane = planeCreate(vec3create(), 0);
27
36
  _oppositePointsHandle(p0, p1, normal, tempPlane);
28
- vec3copy(coverPlaneNormal, tempPlane.normal);
29
37
  distance = tempPlane.distance;
30
38
  }
31
39
  return {
@@ -43,6 +51,7 @@ function set(out, p0, p1) {
43
51
  vec3copy(out.p0, p0);
44
52
  vec3copy(out.p1, p1);
45
53
  cross(out.normal, p0, p1);
54
+ normalize(out.normal, out.normal); // ← ADD THIS LINE - normalize the normal vector!
46
55
  vec3set(_0vector, p0[0] + p1[0], p0[1] + p1[1], p0[2] + p1[2]);
47
56
  const ls = lengthSquared(_0vector);
48
57
  if (ls > EPSILON) {
@@ -52,6 +61,8 @@ function set(out, p0, p1) {
52
61
  else {
53
62
  _oppositePointsHandle(p0, p1, out.normal, out.coverPlane);
54
63
  }
64
+ // Also update coverAngle to match what create() does
65
+ out.coverAngle = Math.acos(dot(p0, p1));
55
66
  }
56
67
  function copy(out, a) {
57
68
  vec3copy(out.p0, a.p0);
@@ -119,6 +130,7 @@ function _oppositePointsHandle(p0, p1, outNormal, outCoverPlane) {
119
130
  }
120
131
  planeFromPoints({ normal: outNormal, distance: 0 }, p0, _0vector, p1);
121
132
  cross(outCoverPlane.normal, outNormal, p0);
133
+ normalize(outCoverPlane.normal, outCoverPlane.normal);
122
134
  }
123
135
  function _populatePointsWithClosestPointInsideArc(out, arc, count, closestPoint) {
124
136
  // two parts divided by closest point will be populated seperately
@@ -199,4 +211,82 @@ function _distanceSampling(out, count, inArc, cameraPosition = vec3create(0, 0,
199
211
  out[finalIndex * 2 + 1] = _longLat[1];
200
212
  }
201
213
  }
202
- export { create, set, copy, clone, isPointOn, equals, closestPoint, populatePoints };
214
+ function calculateZLimitPoint(inArc, out) {
215
+ // The arc's plane is perpendicular to the equator, so the arc is on the equator.
216
+ // All points have z=0, so there's no unique z-limit point.
217
+ if (Math.abs(inArc.normal[2]) > 1 - EPSILON) {
218
+ return false;
219
+ }
220
+ // The Z-limit points of a great circle are the two points on it that are
221
+ // closest to the North and South poles. Their 3D coordinates can be
222
+ // calculated from the normal vector of the great circle's plane.
223
+ const nz = inArc.normal[2];
224
+ const n_xy_len = Math.sqrt(inArc.normal[0] * inArc.normal[0] + inArc.normal[1] * inArc.normal[1]);
225
+ // Candidate 1: Highest Z value (closest to North Pole)
226
+ const p_max_z = vec3.create(-inArc.normal[0] * nz / n_xy_len, -inArc.normal[1] * nz / n_xy_len, n_xy_len);
227
+ // Candidate 2: Lowest Z value (closest to South Pole)
228
+ const p_min_z = vec3.create(inArc.normal[0] * nz / n_xy_len, inArc.normal[1] * nz / n_xy_len, -n_xy_len);
229
+ // Now, we check if either of these points lie on the given arc segment.
230
+ // A point is on the shorter arc if its projection onto the cover plane's
231
+ // normal is on the positive side.
232
+ const d_max = dot(p_max_z, inArc.coverPlane.normal);
233
+ const d_min = dot(p_min_z, inArc.coverPlane.normal);
234
+ if (d_max >= inArc.coverPlane.distance - EPSILON) {
235
+ vec3.copy(out, p_max_z);
236
+ return true;
237
+ }
238
+ if (d_min >= inArc.coverPlane.distance - EPSILON) {
239
+ vec3.copy(out, p_min_z);
240
+ return true;
241
+ }
242
+ return false;
243
+ }
244
+ function doesArcPassThroughMeridian(inArc, meridians) {
245
+ const result = new Array(meridians.length).fill(false);
246
+ // Get longitude angles for p0 and p1
247
+ const p0Lon = Math.atan2(inArc.p0[1], inArc.p0[0]);
248
+ const p1Lon = Math.atan2(inArc.p1[1], inArc.p1[0]);
249
+ if (inArc.p0[2] >= 1 - EPSILON || inArc.p1[2] >= 1 - EPSILON) {
250
+ return result;
251
+ }
252
+ const p0LonNorm = normalizeLon(p0Lon);
253
+ const p1LonNorm = normalizeLon(p1Lon);
254
+ // Determine if we're taking the shorter or longer arc
255
+ let startLon = p0LonNorm;
256
+ let endLon = p1LonNorm;
257
+ // Calculate the angular difference both ways
258
+ const diff1 = normalizeLon(endLon - startLon);
259
+ // Take the shorter path (great circle property)
260
+ const takeShorterPath = diff1 <= Math.PI;
261
+ if (!takeShorterPath) {
262
+ // Swap start and end for the shorter path
263
+ [startLon, endLon] = [endLon, startLon];
264
+ }
265
+ for (let i = 0; i < meridians.length; i++) {
266
+ const meridian = normalizeLon(meridians[i]);
267
+ // Check if meridian is between start and end longitudes
268
+ if (takeShorterPath) {
269
+ if (startLon <= endLon) {
270
+ // Normal case: no wraparound
271
+ result[i] = meridian >= startLon && meridian <= endLon;
272
+ }
273
+ else {
274
+ // Wraparound case: arc crosses 0°/360°
275
+ result[i] = meridian >= startLon || meridian <= endLon;
276
+ }
277
+ }
278
+ else {
279
+ // Taking the longer path
280
+ if (startLon <= endLon) {
281
+ // Arc goes the long way around
282
+ result[i] = meridian <= startLon || meridian >= endLon;
283
+ }
284
+ else {
285
+ // Normal case for long path
286
+ result[i] = meridian >= endLon && meridian <= startLon;
287
+ }
288
+ }
289
+ }
290
+ return result;
291
+ }
292
+ export { create, set, copy, clone, isPointOn, equals, closestPoint, populatePoints, calculateZLimitPoint, doesArcPassThroughMeridian };
@@ -1,4 +1,4 @@
1
- import { RADIANS } from "./methods";
1
+ import { RADIAN } from "./methods";
2
2
  function createCummulativeTemplate(numberOfPoints, strength, denseRatio = 0.5 // Ratio of points to be densely packed at the start.
3
3
  ) {
4
4
  // Handle edge cases for the number of points.
@@ -60,7 +60,7 @@ function globeFindPointByPolar(out, globe, centerLong, centerLat, radius, ratios
60
60
  }
61
61
  }
62
62
  function globeFindPointByPolarHalfCircle(out, globe, centerLong, centerLat, radius, rotation, ratios) {
63
- const rotCentigrade = rotation / RADIANS + 720;
63
+ const rotCentigrade = rotation / RADIAN + 720;
64
64
  for (let i = 0; i < ratios.length; i++) {
65
65
  const point = globe.Math.FindPointByPolar(centerLong, centerLat, radius, (ratios[i] * 180 + rotCentigrade) % 360);
66
66
  out[i * 2] = point.long;
package/Math/circle.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RADIANS } from './methods';
1
+ import { RADIAN } from './methods';
2
2
  import { subtract, normalize, dot, fromLongLatToUnitVector, copy, multiplyScalar, clone } from './vec3';
3
3
  const _0vec3 = [0, 0, 0];
4
4
  function closestAzimuthAngle(circleProperties, point) {
@@ -15,7 +15,7 @@ function closestAzimuthAngle(circleProperties, point) {
15
15
  }
16
16
  function createCircleClosestAzimuthAngleProperties(circle) {
17
17
  const normal = Array(3);
18
- fromLongLatToUnitVector(normal, [circle.center[0] * RADIANS, circle.center[1] * RADIANS]);
18
+ fromLongLatToUnitVector(normal, [circle.center[0] * RADIAN, circle.center[1] * RADIAN]);
19
19
  const N = clone(normal);
20
20
  const distance = dot([0, 0, 1], normal);
21
21
  multiplyScalar(N, N, distance);
@@ -1,9 +1,9 @@
1
1
  import { EPSILON } from "../constants";
2
- import { create as vec3create, copy as vec3copy, dot, distanceSquared, } from "../vec3";
2
+ import { create as vec3create, copy as vec3copy, dot, distanceSquared, copy, normalize } from "../vec3";
3
3
  import { create as lineCreate } from "../line";
4
4
  import { create as planeCreate, distanceToPoint, getUnitSphereRadiusAngle } from "../plane";
5
5
  import { copy as arcCopy, set as arcSet } from "../arc";
6
- import { planePlaneJuction } from "./plane-plane";
6
+ import { planePlaneJunction } from "./plane-plane";
7
7
  import { lineSphereIntersection } from "./line-sphere";
8
8
  const _intersectionLine = /*@__PURE__*/ lineCreate();
9
9
  const _originPlane = /*@__PURE__*/ planeCreate();
@@ -39,9 +39,9 @@ export function arcSlice(out, inArc, junctionPlane) {
39
39
  }
40
40
  // plane-plane intersection line should be calculated for the rest of the calculations
41
41
  vec3copy(_originPlane.normal, inArc.normal);
42
- const isPlaneJunctions = planePlaneJuction(_intersectionLine, _originPlane, junctionPlane);
42
+ const isPlaneJunctions = planePlaneJunction(_intersectionLine, _originPlane, junctionPlane);
43
43
  if (!isPlaneJunctions) { // case C: planes are parallel.
44
- if (junctionPlane.distance <= 0) {
44
+ if (junctionPlane.distance <= 0) { // same direction
45
45
  arcCopy(out[0], inArc);
46
46
  return 1; // No intersection
47
47
  }
@@ -53,23 +53,35 @@ export function arcSlice(out, inArc, junctionPlane) {
53
53
  // calculate the intersection points
54
54
  const isSphereIntersection = lineSphereIntersection(_intersectionPoints, _intersectionLine, _originSphere);
55
55
  if (!isSphereIntersection) {
56
- // other edge caes should be covered by now
57
56
  return 0; // No intersection
58
57
  }
59
- const i0IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[0]) > -EPSILON;
60
- const i1IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[1]) > -EPSILON;
61
- const p0IsVisible = distanceToPoint(junctionPlane, inArc.p0) > -EPSILON;
62
- const p1IsVisible = distanceToPoint(junctionPlane, inArc.p1) > -EPSILON;
58
+ // ADD NORMALIZATION HERE
59
+ normalize(_intersectionPoints[0], _intersectionPoints[0]);
60
+ normalize(_intersectionPoints[1], _intersectionPoints[1]);
61
+ const i0IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[0]) > EPSILON;
62
+ const i1IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[1]) > EPSILON;
63
+ const p0IsVisible = distanceToPoint(junctionPlane, inArc.p0) > EPSILON;
64
+ const p1IsVisible = distanceToPoint(junctionPlane, inArc.p1) > EPSILON;
63
65
  if (!p0IsVisible && !p1IsVisible && !i0IsCovered && !i1IsCovered) {
64
66
  return 0; // No intersection
65
67
  }
66
68
  if (i0IsCovered && i1IsCovered && p0IsVisible && p1IsVisible) {
67
69
  // calculate which points are closer
70
+ if (dot(inArc.coverPlane.normal, junctionPlane.normal) > 1 - EPSILON) {
71
+ arcCopy(out[0], inArc);
72
+ return 1;
73
+ }
74
+ else if (dot(inArc.coverPlane.normal, junctionPlane.normal) < -1 + EPSILON) {
75
+ return 0;
76
+ }
77
+ // Determine which intersection point is closer to p0
68
78
  const p0i0DistanceSquared = distanceSquared(inArc.p0, _intersectionPoints[0]);
69
79
  const p0i1DistanceSquared = distanceSquared(inArc.p0, _intersectionPoints[1]);
70
- const case0 = p0i0DistanceSquared < p0i1DistanceSquared;
71
- arcSet(out[0], inArc.p0, case0 ? _intersectionPoints[0] : _intersectionPoints[1]);
72
- arcSet(out[1], inArc.p1, !case0 ? _intersectionPoints[0] : _intersectionPoints[1]);
80
+ const closerToP0 = p0i0DistanceSquared < p0i1DistanceSquared ? 0 : 1;
81
+ // The visible portion is from p0 to the closer intersection point
82
+ arcSet(out[0], inArc.p0, _intersectionPoints[closerToP0]);
83
+ // The second arc goes from the farther point to p1
84
+ arcSet(out[1], _intersectionPoints[1 - closerToP0], inArc.p1);
73
85
  return 2;
74
86
  }
75
87
  if (i0IsCovered && i1IsCovered) {
@@ -86,3 +98,46 @@ export function arcSlice(out, inArc, junctionPlane) {
86
98
  arcSet(out[0], p0IsVisible ? inArc.p0 : inArc.p1, i0IsCovered ? _intersectionPoints[0] : _intersectionPoints[1]);
87
99
  return 1;
88
100
  }
101
+ function showArc(arc) {
102
+ return `Arc: p0(${arc.p0[0].toFixed(2)}, ${arc.p0[1].toFixed(2)}, ${arc.p0[2]}) - p1(${arc.p1[0]}, ${arc.p1[1].toFixed(2)}, ${arc.p1[2].toFixed(2)})`;
103
+ }
104
+ function showPlane(plane) {
105
+ return `Plane: n(${plane.normal[0].toFixed(2)}, ${plane.normal[1].toFixed(2)}, ${plane.normal[2].toFixed(2)}) d(${plane.distance.toFixed(2)})`;
106
+ }
107
+ export function pointsOnArc(inArc, junctionPlane, out) {
108
+ // case A: junction plane is too far
109
+ if (Math.abs(junctionPlane.distance) > 1) {
110
+ return 0;
111
+ }
112
+ // Calculate plane-plane intersection
113
+ vec3copy(_originPlane.normal, inArc.normal);
114
+ const isPlaneJunctions = planePlaneJunction(_intersectionLine, _originPlane, junctionPlane);
115
+ // case B: planes are parallel
116
+ if (!isPlaneJunctions) {
117
+ return 0;
118
+ }
119
+ // Calculate intersection points with unit sphere
120
+ const isSphereIntersection = lineSphereIntersection(_intersectionPoints, _intersectionLine, _originSphere);
121
+ // case C: intersection line does not intersect the unit sphere
122
+ if (!isSphereIntersection) {
123
+ return 0;
124
+ }
125
+ // Check which intersection points are covered by the arc
126
+ const i0IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[0]) > -EPSILON;
127
+ const i1IsCovered = distanceToPoint(inArc.coverPlane, _intersectionPoints[1]) > -EPSILON;
128
+ // Check which endpoints are visible
129
+ let count = 0;
130
+ // Add covered intersection points
131
+ if (i0IsCovered) {
132
+ copy(out[count], _intersectionPoints[0]);
133
+ count++;
134
+ }
135
+ if (Math.abs(Math.abs(junctionPlane.distance) - 1) < EPSILON) {
136
+ return count; // Tangent case, only one intersection point
137
+ }
138
+ if (i1IsCovered) {
139
+ copy(out[count], _intersectionPoints[1]);
140
+ count++;
141
+ }
142
+ return count;
143
+ }
@@ -3,18 +3,18 @@ import { at } from "../line";
3
3
  const _0vector = /*@__PURE__*/ create(0, 0, 0);
4
4
  export function lineSphereIntersection(out, inLine, inSphere) {
5
5
  subtract(_0vector, inLine.origin, inSphere.center);
6
+ const dirLengthSq = lengthSquared(inLine.direction);
7
+ const dot_ = dot(_0vector, inLine.direction);
6
8
  const distanceSquared = lengthSquared(_0vector);
7
9
  const radiusSquared = inSphere.radius * inSphere.radius;
8
- const dot_ = dot(_0vector, inLine.direction);
9
- const dotSquared = dot_ * dot_;
10
- const discriminant = dotSquared + radiusSquared - distanceSquared;
10
+ const discriminant = dot_ * dot_ - dirLengthSq * (distanceSquared - radiusSquared);
11
11
  if (discriminant < 0) {
12
12
  return false; // no intersection
13
13
  }
14
14
  else {
15
- const a = Math.sqrt(discriminant);
16
- const t1 = -dot_ - a;
17
- const t2 = -dot_ + a;
15
+ const sqrtDiscriminant = Math.sqrt(discriminant);
16
+ const t1 = (-dot_ - sqrtDiscriminant) / dirLengthSq;
17
+ const t2 = (-dot_ + sqrtDiscriminant) / dirLengthSq;
18
18
  at(out[0], inLine, t1);
19
19
  at(out[1], inLine, t2);
20
20
  return true;
@@ -1,10 +1,8 @@
1
1
  import { EPSILON } from "../constants";
2
- import { copy, create, dot, cross, lengthSquared } from "../vec3";
3
- const _normal1 = create();
4
- const _normal2 = create();
5
- export function planePlaneJuction(out, plane1, plane2) {
6
- copy(_normal1, plane1.normal);
7
- copy(_normal2, plane2.normal);
2
+ import { dot, cross, lengthSquared } from "../vec3";
3
+ export function planePlaneJunction(out, plane1, plane2) {
4
+ const _normal1 = plane1.normal;
5
+ const _normal2 = plane2.normal;
8
6
  const distance1 = plane1.distance;
9
7
  const distance2 = plane2.distance;
10
8
  const { origin, direction } = out;
package/Math/methods.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { WORLD_RADIUS_3D, WORLD_RADIUS_MERCATOR } from './constants';
2
2
  import { dot as dot3, copy as copy3 } from './vec3';
3
- export const RADIANS = Math.PI / 180;
3
+ export const RADIAN = Math.PI / 180;
4
4
  const _0vec3 = [0, 0, 0];
5
5
  const _0vec2 = [0, 0];
6
6
  export const cartesian3dToRadian = (output, cartesian) => {
@@ -47,8 +47,8 @@ export const sphericalLinearInterpolation_Cartesian3d = (output, a, b, ratio) =>
47
47
  output[2] = _0vec3[2] * height;
48
48
  };
49
49
  export const wgs84ToCartesian3d = (output, long, lat, height) => {
50
- const longRad = long * RADIANS;
51
- const latRad = lat * RADIANS;
50
+ const longRad = long * RADIAN;
51
+ const latRad = lat * RADIAN;
52
52
  const x = Math.cos(latRad) * Math.cos(longRad);
53
53
  const y = Math.cos(latRad) * Math.sin(longRad);
54
54
  const z = Math.sin(latRad);
@@ -59,8 +59,8 @@ export const wgs84ToCartesian3d = (output, long, lat, height) => {
59
59
  };
60
60
  export const wgs84ToMercator = (long, lat) => {
61
61
  return [
62
- WORLD_RADIUS_MERCATOR * long * RADIANS,
63
- WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + lat * RADIANS / 2))
62
+ WORLD_RADIUS_MERCATOR * long * RADIAN,
63
+ WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + lat * RADIAN / 2))
64
64
  ];
65
65
  };
66
66
  export const pixelXYToRadians = (pixelXY) => {
@@ -41,7 +41,6 @@ export function createfillGrid(globe, origin, startX, startY, rowSize, columnSiz
41
41
  grid[startY][i] = [long, lat];
42
42
  }
43
43
  // fill single horizontal from origin from startY to 0
44
- console.log("grid", grid);
45
44
  for (let i = startY - 1; i >= 0; i--) {
46
45
  for (let j = 0; j < rowSize; j++) {
47
46
  const [long, lat] = moveByAngle(grid[i + 1][j], angleRadians - Math.PI / 2, cellSizeY);
@@ -0,0 +1,37 @@
1
+ function geoJSONToEarcut(geojson) {
2
+ const vertices = [];
3
+ const holes = [];
4
+ const dimensions = 2; // Assuming 2D coordinates (longitude, latitude)
5
+ let holeIndex = 0;
6
+ if (geojson.type !== 'FeatureCollection') {
7
+ throw new Error('Invalid GeoJSON: Expected FeatureCollection');
8
+ }
9
+ const features = geojson.features;
10
+ function processPolygon(coordinates) {
11
+ for (let i = 0; i < coordinates.length; i++) {
12
+ if (i > 0) {
13
+ holeIndex += coordinates[i - 1].length;
14
+ holes.push(holeIndex);
15
+ }
16
+ for (const coord of coordinates[i]) {
17
+ vertices.push(coord[0], coord[1]);
18
+ }
19
+ }
20
+ }
21
+ function processMultiPolygon(coordinates) {
22
+ for (const polygon of coordinates) {
23
+ processPolygon(polygon);
24
+ }
25
+ }
26
+ for (const feature of features) {
27
+ const geometry = feature.geometry;
28
+ if (geometry.type === 'Polygon') {
29
+ processPolygon(geometry.coordinates);
30
+ }
31
+ else if (geometry.type === 'MultiPolygon') {
32
+ processMultiPolygon(geometry.coordinates);
33
+ }
34
+ }
35
+ return { vertices, holes, dimensions };
36
+ }
37
+ export { geoJSONToEarcut };
@@ -0,0 +1,46 @@
1
+ import { TILE_COUNTS } from "./zoom-catch";
2
+ /**
3
+ * If the slope is not close the zero not very important but
4
+ * If a line goes along a parallel its latitude can tilt a lot
5
+ * For these cases:
6
+ * Meridian junctions should be first.
7
+ * So we have information about possible edge latitude
8
+ * Or the counting box should be calculated accourding to great circle
9
+ *
10
+ *
11
+ */
12
+ export function latToTileY(lat, zoom) {
13
+ return (1 - Math.log(Math.tan(lat) + 1 / Math.cos(lat)) / Math.PI) / 2 * TILE_COUNTS[zoom];
14
+ }
15
+ export function lonToTileX(lon, zoom) {
16
+ return (lon + Math.PI) / (2 * Math.PI) * TILE_COUNTS[zoom];
17
+ }
18
+ export function longLatToTileDecimal(lon, lat, zoom) {
19
+ return [lonToTileX(lon, zoom), latToTileY(lat, zoom)];
20
+ }
21
+ export function tileYtoLat(y, zoom) {
22
+ const n = Math.PI - 2 * Math.PI * y / TILE_COUNTS[zoom];
23
+ return (Math.PI / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
24
+ }
25
+ export function tileXtoLon(x, zoom) {
26
+ return x / TILE_COUNTS[zoom] * (2 * Math.PI) - Math.PI;
27
+ }
28
+ export function tessellationLatDimention(zoom, lowLat, highLat) {
29
+ const lowY = latToTileY(lowLat, zoom);
30
+ const highY = latToTileY(highLat, zoom);
31
+ const latitudes = [];
32
+ if (lowY % 1 !== 0)
33
+ latitudes.push(lowLat);
34
+ for (let y = Math.ceil(lowY); y <= Math.floor(highY); y++) {
35
+ latitudes.push(tileYtoLat(y, zoom));
36
+ }
37
+ if (highY % 1 !== 0)
38
+ latitudes.push(highLat);
39
+ return latitudes;
40
+ }
41
+ export function isOnTileEdge(longLat, zoom) {
42
+ const tileX = lonToTileX(longLat[0], zoom);
43
+ const tileY = latToTileY(longLat[1], zoom);
44
+ const epsilon = 1 / TILE_COUNTS[zoom] / 200;
45
+ return (Math.abs(tileX % 1) < epsilon || Math.abs(tileY % 1) < epsilon || Math.abs(tileX % 1 - 1) < epsilon || Math.abs(tileY % 1 - 1) < epsilon);
46
+ }
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * @input
4
+ * A series of points defining a polygon
5
+ * @output
6
+ * A series of triangles that fill the polygon
7
+ *
8
+ * @steps
9
+ * @1. cut
10
+ * @2. sort
11
+ * @3. connect
12
+ *
13
+ * @cut
14
+ * @1. find tile cuts on the arcs, tag: enum vertex {pillar, corner},
15
+ * @2. find inner cuts on the arcs
16
+ *
17
+ * @sorter
18
+ * sort by
19
+ * @1 y coordinate, then x coordinate
20
+ * @2
21
+ *
22
+ *
23
+ * @connect
24
+ *
25
+ * 1. Pick two rows from the top
26
+ * 2. Go left to right
27
+ * 3. Compeare x values to connect point closest to it
28
+ *
29
+ * @smartConnect
30
+ *
31
+ * if hit from left to right, take a break
32
+ * if hit a concave edge, fonnect all the points until jump over to the following point of the concave
33
+ *
34
+ * that way I can calculate polygons with holes
35
+ *
36
+ * That raises a division
37
+ *
38
+ * instead of dividing into triangles
39
+ * divide into convex polygons
40
+ *
41
+ * convex save points and zoom level of convex shape.
42
+ * populate middle points when on zoom level increase
43
+ *
44
+ * @Future
45
+ *
46
+ * 1. cut is ready.
47
+ * WEBMercator(DEM data) to globe:
48
+ * cutting with tileXY coordinates base and convert back to longlat and vector3
49
+ * solves
50
+ * 2. connect looks promising. Can run on triangle approach as well
51
+ *
52
+ * Solving a polygon
53
+ * in a single shot
54
+ * without dividing into triangles
55
+ * takes all the arcs to be cut in single go.
56
+ * To continue following questions arise:
57
+ * how to match points in a row?
58
+ * Cut arcs in two if they have Z limits
59
+ * cut by parallel lines,
60
+ * sort by x
61
+ * if 2
62
+ * How to handle points in between rows?
63
+ *
64
+ *
65
+ */
66
+ class PartialTesselation {
67
+ }
@@ -0,0 +1,50 @@
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
+ // // }