@mark1russell7/visuals 0.0.0-stage → 0.1.1

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/build/globe.js ADDED
@@ -0,0 +1,1046 @@
1
+ import { n as ballView, r as capView, t as FIT_MARGIN } from "./extent-CALhBZU-.js";
2
+ import { BufferAttribute, BufferGeometry, Color, FrontSide, InstancedInterleavedBuffer, InterleavedBufferAttribute, Mesh, MeshBasicMaterial, Points, ShaderMaterial, ShapeUtils, Sphere, SphereGeometry, Vector2, Vector3 } from "three";
3
+ import { densify, fromUnitVector, pointLocator, toUnitVector } from "@mark1russell7/geo";
4
+ import { LineMaterial } from "three/addons/lines/LineMaterial.js";
5
+ import { LineSegments2 } from "three/addons/lines/LineSegments2.js";
6
+ import { LineSegmentsGeometry } from "three/addons/lines/LineSegmentsGeometry.js";
7
+ // src/globe/mesh.ts
8
+ /** The largest count of corners of the surface of one region. A smaller step gives more corners. */
9
+ const MAX_SURFACE_CORNERS = 2e6;
10
+ /**
11
+ * The longest edge in a surface, as a factor of the step. An edge of the outline is not longer than the step.
12
+ * An edge in the surface can be longer by this factor, so the count of the passes has a small limit.
13
+ */
14
+ const LONG_EDGE = 1.25;
15
+ /**
16
+ * The smallest length of a degree of longitude in the size of an edge, as a part of a degree at the equator.
17
+ * Near a pole, a degree of longitude is short, and an edge can go across many of them. This limit keeps such an edge to 5 steps of longitude.
18
+ * A straight edge on the Earth is not a straight line in longitude and latitude. The two are far apart for an edge across many degrees.
19
+ */
20
+ const MIN_WIDTH = .25;
21
+ /** The largest count of passes that divide the long edges. Each pass makes the longest edge shorter by almost a half. */
22
+ const MAX_PASSES = 48;
23
+ /** The factor of the first corner in the key of an edge. A key is an exact integer for each pair of corners below this count. */
24
+ const KEY = 2 ** 26;
25
+ /** The largest distance of a corner from an edge that it is on, as a part of the length of the edge. */
26
+ const ON_EDGE = 1e-12;
27
+ /** The largest distance of a longitude from 180 degrees, or of a latitude from 90 degrees, that is on the antimeridian or on a pole. */
28
+ const ON_LINE = 1e-9;
29
+ const RADIANS$1 = Math.PI / 180;
30
+ /** This function gives one number of a list. The index is always in the list, so the default 0 has no use. */
31
+ function at(list, index) {
32
+ return list[index] ?? 0;
33
+ }
34
+ function edgeKey(a, b) {
35
+ return a < b ? a * KEY + b : b * KEY + a;
36
+ }
37
+ /**
38
+ * This function gives the height of the flat triangles of a surface below a ball of radius 1, at most.
39
+ * A layer at this height above a ball does not go into the ball. `step` is the step of the surface, in degrees.
40
+ */
41
+ function surfaceSag(step) {
42
+ return 1 - Math.cos(step * RADIANS$1 * LONG_EDGE * Math.SQRT2 / Math.sqrt(3));
43
+ }
44
+ /** This function gives the points of a ring, each one time. A point is different from the point before it, and the last point is different from the first point. */
45
+ function openRing(ring) {
46
+ const points = [];
47
+ for (const position of ring) {
48
+ const last = points[points.length - 1];
49
+ if (last === void 0 || last.x !== position[0] || last.y !== position[1]) points.push(new Vector2(position[0], position[1]));
50
+ }
51
+ const first = points[0];
52
+ while (points.length > 1 && first !== void 0 && points[points.length - 1]?.equals(first) === true) points.pop();
53
+ return points;
54
+ }
55
+ /**
56
+ * This function gives the size of an edge for the division of a surface, in degrees. The size is the larger of its steps in latitude and in longitude.
57
+ * A step of longitude is as long as it is on the Earth, at the end of the edge that is nearer to the equator.
58
+ */
59
+ function edgeSize(lon, lat, a, b) {
60
+ const latA = at(lat, a);
61
+ const latB = at(lat, b);
62
+ const wide = Math.abs(at(lon, a) - at(lon, b)) * Math.max(Math.cos(Math.min(Math.abs(latA), Math.abs(latB)) * RADIANS$1), MIN_WIDTH);
63
+ return Math.max(Math.abs(latA - latB), wide);
64
+ }
65
+ /** This function gives, for each edge of a list of faces, a face that has it. An edge of an outline has only one face. */
66
+ function ownersOf(faces) {
67
+ const owner = /* @__PURE__ */ new Map();
68
+ faces.forEach((face, index) => {
69
+ for (let side = 0; side < face.length; side++) owner.set(edgeKey(at(face, side), at(face, (side + 1) % face.length)), index);
70
+ });
71
+ return owner;
72
+ }
73
+ /**
74
+ * This function divides the face with the edge from `a` to `b` at each corner of `run`. The corners of `run` are on the edge, in the sequence from `a` to `b`.
75
+ * Each new face has the third corner of the face, and the direction of the face. An edge with no face changes nothing.
76
+ */
77
+ function divideAt(faces, owner, a, b, run) {
78
+ const index = owner.get(edgeKey(a, b));
79
+ const face = index === void 0 ? void 0 : faces[index];
80
+ const c = face?.find((corner) => corner !== a && corner !== b);
81
+ if (index === void 0 || face === void 0 || c === void 0 || run.length === 0) return;
82
+ const forward = face[(face.indexOf(a) + 1) % 3] === b;
83
+ const chain = [
84
+ a,
85
+ ...run,
86
+ b
87
+ ];
88
+ for (let piece = 0; piece + 1 < chain.length; piece++) {
89
+ const from = at(chain, piece);
90
+ const to = at(chain, piece + 1);
91
+ const place = piece === 0 ? index : faces.length;
92
+ faces[place] = forward ? [
93
+ from,
94
+ to,
95
+ c
96
+ ] : [
97
+ to,
98
+ from,
99
+ c
100
+ ];
101
+ owner.set(edgeKey(from, to), place);
102
+ if (piece === 0) owner.set(edgeKey(a, c), place);
103
+ if (piece === chain.length - 2) owner.set(edgeKey(b, c), place);
104
+ }
105
+ }
106
+ /**
107
+ * This function gives the corners that are on the edge from `u` to `v`, between its ends, in the sequence from `u` to `v`.
108
+ * `byLon` has each corner, from the smallest longitude to the largest.
109
+ */
110
+ function cornersOn(points, byLon, u, v) {
111
+ const from = points[u];
112
+ const to = points[v];
113
+ if (from === void 0 || to === void 0) return [];
114
+ const dx = to.x - from.x;
115
+ const dy = to.y - from.y;
116
+ const square = dx * dx + dy * dy;
117
+ if (!(square > 0)) return [];
118
+ const slack = Math.sqrt(square) * ON_EDGE;
119
+ const low = Math.min(from.x, to.x) - slack;
120
+ const high = Math.max(from.x, to.x) + slack;
121
+ let first = 0;
122
+ let end = byLon.length;
123
+ while (first < end) {
124
+ const middle = first + end >> 1;
125
+ if ((points[at(byLon, middle)]?.x ?? 1e400) < low) first = middle + 1;
126
+ else end = middle;
127
+ }
128
+ const found = [];
129
+ for (let index = first; index < byLon.length; index++) {
130
+ const corner = at(byLon, index);
131
+ const point = points[corner];
132
+ if (point === void 0 || point.x > high) break;
133
+ if (corner === u || corner === v) continue;
134
+ const px = point.x - from.x;
135
+ const py = point.y - from.y;
136
+ const part = (px * dx + py * dy) / square;
137
+ if (part > 0 && part < 1 && Math.abs(px * dy - py * dx) <= square * ON_EDGE) found.push({
138
+ corner,
139
+ part
140
+ });
141
+ }
142
+ return found.sort((one, other) => one.part - other.part).map(({ corner }) => corner);
143
+ }
144
+ /**
145
+ * This function divides a polygon into triangles. Each ring has no point two times in sequence. The faces have indices of the points of the rings, as one list.
146
+ *
147
+ * The division ignores a corner on the straight line between its two neighbors. A face then has an edge with a corner on it,
148
+ * and the face on the other side of that corner has a different edge. The function divides such a face at each corner on its edge,
149
+ * so two faces with a common border have a common edge.
150
+ */
151
+ function facesOf(rings) {
152
+ const [outer = [], ...holes] = rings;
153
+ const faces = ShapeUtils.triangulateShape([...outer], holes.map((hole) => [...hole]));
154
+ const points = rings.flat();
155
+ const ringOf = [];
156
+ const spotOf = [];
157
+ rings.forEach((ring, index) => {
158
+ for (let spot = 0; spot < ring.length; spot++) {
159
+ ringOf.push(index);
160
+ spotOf.push(spot);
161
+ }
162
+ });
163
+ const owner = /* @__PURE__ */ new Map();
164
+ const counts = /* @__PURE__ */ new Map();
165
+ faces.forEach((face, index) => {
166
+ for (let side = 0; side < face.length; side++) {
167
+ const key = edgeKey(at(face, side), at(face, (side + 1) % face.length));
168
+ owner.set(key, index);
169
+ counts.set(key, (counts.get(key) ?? 0) + 1);
170
+ }
171
+ });
172
+ let byLon;
173
+ for (const [key, count] of counts) {
174
+ if (count !== 1) continue;
175
+ const u = Math.floor(key / KEY);
176
+ const v = key % KEY;
177
+ const ring = at(ringOf, u);
178
+ const gap = Math.abs(at(spotOf, u) - at(spotOf, v));
179
+ if (ring === at(ringOf, v) && (gap === 1 || gap === (rings[ring]?.length ?? 0) - 1)) continue;
180
+ byLon ??= points.map((_, index) => index).sort((one, other) => (points[one]?.x ?? 0) - (points[other]?.x ?? 0));
181
+ divideAt(faces, owner, u, v, cornersOn(points, byLon, u, v));
182
+ }
183
+ return faces;
184
+ }
185
+ /**
186
+ * This function gives the place of each point of a ring in the same ring with more points on its edges.
187
+ * It gives `undefined` for a ring whose points are not in the other ring, in the same sequence.
188
+ */
189
+ function placesIn(dense, own) {
190
+ const places = [];
191
+ let index = 0;
192
+ for (const point of own) {
193
+ while (index < dense.length && dense[index]?.equals(point) !== true) index++;
194
+ if (index >= dense.length) return void 0;
195
+ places.push(index);
196
+ index += 1;
197
+ }
198
+ return places;
199
+ }
200
+ /**
201
+ * This function divides each triangle that has a long edge, at the middle of each long edge. It gives the new triangles,
202
+ * or `undefined` when no edge is long. Two triangles with one edge get the same middle, so the surface has no hole.
203
+ */
204
+ function dividePass(triangles, lon, lat, limit, middles) {
205
+ const next = [];
206
+ let divided = false;
207
+ const middle = (a, b) => {
208
+ const key = edgeKey(a, b);
209
+ const found = middles.get(key);
210
+ if (found !== void 0) return found;
211
+ lon.push((at(lon, a) + at(lon, b)) / 2);
212
+ lat.push((at(lat, a) + at(lat, b)) / 2);
213
+ middles.set(key, lon.length - 1);
214
+ return lon.length - 1;
215
+ };
216
+ for (let index = 0; index < triangles.length; index += 3) {
217
+ const a = at(triangles, index);
218
+ const b = at(triangles, index + 1);
219
+ const c = at(triangles, index + 2);
220
+ const ab = edgeSize(lon, lat, a, b) > limit;
221
+ const bc = edgeSize(lon, lat, b, c) > limit;
222
+ const ca = edgeSize(lon, lat, c, a) > limit;
223
+ const count = Number(ab) + Number(bc) + Number(ca);
224
+ if (count === 0) {
225
+ next.push(a, b, c);
226
+ continue;
227
+ }
228
+ divided = true;
229
+ if (count === 3) {
230
+ const mab = middle(a, b);
231
+ const mbc = middle(b, c);
232
+ const mca = middle(c, a);
233
+ next.push(a, mab, mca, mab, b, mbc, mca, mbc, c, mab, mbc, mca);
234
+ continue;
235
+ }
236
+ let p = a;
237
+ let q = b;
238
+ let r = c;
239
+ if (count === 1 ? bc : !ab) {
240
+ p = b;
241
+ q = c;
242
+ r = a;
243
+ } else if (count === 1 ? ca : !bc) {
244
+ p = c;
245
+ q = a;
246
+ r = b;
247
+ }
248
+ const mpq = middle(p, q);
249
+ if (count === 1) {
250
+ next.push(p, mpq, r, mpq, q, r);
251
+ continue;
252
+ }
253
+ const mqr = middle(q, r);
254
+ next.push(mpq, q, mqr);
255
+ if (edgeSize(lon, lat, p, mqr) <= edgeSize(lon, lat, mpq, r)) next.push(p, mpq, mqr, p, mqr, r);
256
+ else next.push(p, mpq, r, mpq, mqr, r);
257
+ }
258
+ return divided ? next : void 0;
259
+ }
260
+ /**
261
+ * This function divides the surface of a region into triangles that follow the curve of the Earth.
262
+ *
263
+ * `step` is the largest step of an edge of the outline in longitude or latitude, in degrees. The outline is the outline of `densify` with this step:
264
+ * each edge of the outline of the surface is an edge of that outline. So a line through the points of `densify` is exactly on the outline of the surface.
265
+ * An edge in the surface is not longer than 1.25 steps. A step of longitude is as long as it is on the Earth at that latitude, and a quarter of a step at least.
266
+ *
267
+ * A straight edge in the plane is a curve on the Earth. So a flat triangle on a globe is not exactly the triangle in the plane.
268
+ * The difference is small for a small step. It is largest near a pole.
269
+ *
270
+ * The function throws a `GeoError` for a region or a step that is not correct, and a `RangeError` for a surface with too many corners.
271
+ */
272
+ function regionSurface(region, step, maxCorners = MAX_SURFACE_CORNERS) {
273
+ const dense = densify(region, step);
274
+ const ownPolygons = region.type === "Polygon" ? [region.coordinates] : region.coordinates;
275
+ const densePolygons = dense.type === "Polygon" ? [dense.coordinates] : dense.coordinates;
276
+ const lon = [];
277
+ const lat = [];
278
+ let triangles = [];
279
+ ownPolygons.forEach((polygon, polygonIndex) => {
280
+ const own = [];
281
+ const more = [];
282
+ const spots = [];
283
+ for (let index = 0; index < polygon.length; index++) {
284
+ const ring = openRing(polygon[index] ?? []);
285
+ if (ring.length < 3) {
286
+ if (index === 0) return;
287
+ continue;
288
+ }
289
+ const added = openRing(densePolygons[polygonIndex]?.[index] ?? []);
290
+ const places = placesIn(added, ring);
291
+ own.push(ring);
292
+ more.push(places === void 0 ? ring : added);
293
+ spots.push(places ?? ring.map((_, spot) => spot));
294
+ }
295
+ const base = lon.length;
296
+ /** The corner of the surface for each corner of the region, as an index from `base`. */
297
+ const cornerOf = [];
298
+ const starts = [];
299
+ more.forEach((ring, index) => {
300
+ const start = lon.length - base;
301
+ starts.push(start);
302
+ for (const spot of spots[index] ?? []) cornerOf.push(start + spot);
303
+ for (const point of ring) {
304
+ lon.push(point.x);
305
+ lat.push(point.y);
306
+ }
307
+ });
308
+ if (lon.length > maxCorners) throw tooManyCorners(maxCorners);
309
+ const faces = facesOf(own).map((face) => face.map((corner) => at(cornerOf, corner)));
310
+ const owner = ownersOf(faces);
311
+ more.forEach((ring, index) => {
312
+ const places = spots[index] ?? [];
313
+ const start = at(starts, index);
314
+ places.forEach((place, spot) => {
315
+ const next = at(places, (spot + 1) % places.length);
316
+ const run = [];
317
+ for (let between = (place + 1) % ring.length; between !== next; between = (between + 1) % ring.length) run.push(start + between);
318
+ divideAt(faces, owner, start + place, start + next, run);
319
+ });
320
+ });
321
+ const turnOf = ([a = 0, b = 0, c = 0]) => (at(lon, base + b) - at(lon, base + a)) * (at(lat, base + c) - at(lat, base + a)) - (at(lon, base + c) - at(lon, base + a)) * (at(lat, base + b) - at(lat, base + a));
322
+ let turn = 0;
323
+ for (const face of faces) turn += turnOf(face);
324
+ for (const [a = 0, b = 0, c = 0] of faces) if (turn >= 0) triangles.push(base + a, base + b, base + c);
325
+ else triangles.push(base + a, base + c, base + b);
326
+ });
327
+ const limit = step * LONG_EDGE;
328
+ const middles = /* @__PURE__ */ new Map();
329
+ for (let pass = 0;; pass++) {
330
+ const next = dividePass(triangles, lon, lat, limit, middles);
331
+ if (next === void 0) break;
332
+ triangles = next;
333
+ if (lon.length > maxCorners) throw tooManyCorners(maxCorners);
334
+ if (pass >= MAX_PASSES) throw new RangeError(`The surface of the region has edges longer than ${limit} degrees after ${MAX_PASSES} passes.`);
335
+ }
336
+ const corners = new Float64Array(lon.length * 2);
337
+ for (let index = 0; index < lon.length; index++) {
338
+ corners[index * 2] = at(lon, index);
339
+ corners[index * 2 + 1] = at(lat, index);
340
+ }
341
+ return {
342
+ corners,
343
+ triangles: Uint32Array.from(triangles)
344
+ };
345
+ }
346
+ function tooManyCorners(maxCorners) {
347
+ return /* @__PURE__ */ new RangeError(`The surface of the region has more than ${maxCorners} corners. Use a larger step.`);
348
+ }
349
+ /** This function gives 1 for a longitude of 180 degrees east, -1 for 180 degrees west, and 0 for each other longitude. */
350
+ function sideOf(position) {
351
+ if (Math.abs(position[0] - 180) <= ON_LINE) return 1;
352
+ return Math.abs(position[0] + 180) <= ON_LINE ? -1 : 0;
353
+ }
354
+ /** This function gives 1 for the north pole, -1 for the south pole, and 0 for each other latitude. */
355
+ function poleOf(position) {
356
+ if (position[1] >= 89.999999999) return 1;
357
+ return position[1] <= -89.999999999 ? -1 : 0;
358
+ }
359
+ /**
360
+ * This function gives the edges of a region as lines, for the outline that a person sees. Each line is a list of longitudes and latitudes, in degrees:
361
+ * two numbers for each point.
362
+ *
363
+ * `step` is the largest step of a line in longitude or latitude, in degrees. The points are the points of `densify`, so they are corners of `regionSurface`.
364
+ * An edge that is only a cut gets no line. A cut is an edge along a pole, or an edge on the antimeridian with an edge of the region on its other side.
365
+ */
366
+ function regionEdges(region, step) {
367
+ const polygons = region.type === "Polygon" ? [region.coordinates] : region.coordinates;
368
+ const east = [];
369
+ const west = [];
370
+ for (const polygon of polygons) for (const ring of polygon) for (let index = 0; index + 1 < ring.length; index++) {
371
+ const from = ring[index];
372
+ const to = ring[index + 1];
373
+ if (from === void 0 || to === void 0) continue;
374
+ const side = sideOf(from);
375
+ if (side === 0 || side !== sideOf(to)) continue;
376
+ (side > 0 ? east : west).push({
377
+ low: Math.min(from[1], to[1]),
378
+ high: Math.max(from[1], to[1])
379
+ });
380
+ }
381
+ const isCut = (from, to) => {
382
+ const pole = poleOf(from);
383
+ if (pole !== 0 && pole === poleOf(to)) return true;
384
+ const side = sideOf(from);
385
+ if (side === 0 || side !== sideOf(to)) return false;
386
+ const low = Math.min(from[1], to[1]);
387
+ const high = Math.max(from[1], to[1]);
388
+ return (side > 0 ? west : east).some((cut) => Math.min(cut.high, high) > Math.max(cut.low, low));
389
+ };
390
+ const lines = [];
391
+ const add = (run) => {
392
+ if (run.length < 2) return;
393
+ const dense = densify({
394
+ type: "LineString",
395
+ coordinates: [...run]
396
+ }, step).coordinates;
397
+ const line = new Float64Array(dense.length * 2);
398
+ dense.forEach((position, index) => {
399
+ line[index * 2] = position[0];
400
+ line[index * 2 + 1] = position[1];
401
+ });
402
+ lines.push(line);
403
+ };
404
+ for (const polygon of polygons) for (const ring of polygon) {
405
+ const count = ring.length - 1;
406
+ if (count < 1) continue;
407
+ const cut = [];
408
+ for (let index = 0; index < count; index++) {
409
+ const from = ring[index];
410
+ const to = ring[index + 1];
411
+ cut.push(from === void 0 || to === void 0 || isCut(from, to));
412
+ }
413
+ const first = cut.indexOf(true);
414
+ if (first < 0) {
415
+ add(ring);
416
+ continue;
417
+ }
418
+ let run = [];
419
+ for (let steps = 1; steps <= count; steps++) {
420
+ const edge = (first + steps) % count;
421
+ const from = ring[edge];
422
+ const to = ring[edge + 1];
423
+ if (cut[edge] === true || from === void 0 || to === void 0) {
424
+ add(run);
425
+ run = [];
426
+ continue;
427
+ }
428
+ if (run.length === 0) run.push(from);
429
+ run.push(to);
430
+ }
431
+ }
432
+ return lines;
433
+ }
434
+ /**
435
+ * This function gives the lines of a grid of meridians and parallels. Each line is a list of longitudes and latitudes, in degrees: two numbers for each point.
436
+ *
437
+ * `spacing` is the angle between two lines, in degrees, and `step` is the largest step of a line. A spacing of 0 or less gives no lines.
438
+ * The meridians at each 90 degrees go to the poles. The other meridians stop one spacing before each pole, so the poles stay clear.
439
+ */
440
+ function gridLines(spacing, step) {
441
+ if (!(spacing > 0) || !(step > 0) || !Number.isFinite(spacing)) return [];
442
+ const lines = [];
443
+ const add = (fromLon, fromLat, toLon, toLat) => {
444
+ const parts = Math.max(Math.ceil(Math.max(Math.abs(toLon - fromLon), Math.abs(toLat - fromLat)) / step), 1);
445
+ const line = new Float64Array((parts + 1) * 2);
446
+ for (let part = 0; part <= parts; part++) {
447
+ line[part * 2] = fromLon + (toLon - fromLon) * part / parts;
448
+ line[part * 2 + 1] = fromLat + (toLat - fromLat) * part / parts;
449
+ }
450
+ lines.push(line);
451
+ };
452
+ const top = (Math.ceil(90 / spacing) - 1) * spacing;
453
+ for (let index = 0; index * spacing < 359.999999999; index++) {
454
+ const lon = -180 + index * spacing;
455
+ const end = Math.abs(lon / 90 - Math.round(lon / 90)) <= ON_LINE ? 90 : top;
456
+ if (end > 0) add(lon, -end, lon, end);
457
+ }
458
+ for (let lat = -top; lat <= top + ON_LINE; lat += spacing) add(-180, lat, 180, lat);
459
+ return lines;
460
+ }
461
+ // src/globe/space.ts
462
+ /**
463
+ * The polar limits of the camera of a globe: the camera goes above each pole.
464
+ * Give this value to the option `polar` of a stage. Set the option `pan` to false, so the camera turns around the center of the Earth.
465
+ */
466
+ const GLOBE_POLAR = {
467
+ min: .01,
468
+ max: Math.PI - .01
469
+ };
470
+ const RADIANS = Math.PI / 180;
471
+ /**
472
+ * This function gives the point of a globe for a place on the Earth. The center of the globe is the origin of the stage.
473
+ *
474
+ * The axis `y` of the stage goes to the north pole. The axis `z` goes to latitude 0 and longitude 0, and the axis `x` goes to latitude 0 and longitude 90 east.
475
+ * `radius` is the distance of the point from the center. The default is 1.
476
+ */
477
+ function globePoint(place, radius = 1) {
478
+ const unit = toUnitVector(place);
479
+ return {
480
+ x: unit.y * radius,
481
+ y: unit.z * radius,
482
+ z: unit.x * radius
483
+ };
484
+ }
485
+ /**
486
+ * This function gives the place on the Earth in the direction of a point of the stage, as seen from the center of the globe.
487
+ * The center of the globe has no direction, so it gives `undefined`.
488
+ */
489
+ function globePlace(point) {
490
+ if (point.x === 0 && point.y === 0 && point.z === 0) return void 0;
491
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) return void 0;
492
+ return fromUnitVector({
493
+ x: point.z,
494
+ y: point.x,
495
+ z: point.y
496
+ });
497
+ }
498
+ /** This function gives the direction of a camera that is above a place on the Earth. */
499
+ function globeAngles(place) {
500
+ return {
501
+ polar: Math.PI / 2 - place.lat * RADIANS,
502
+ azimuth: place.lon * RADIANS
503
+ };
504
+ }
505
+ /**
506
+ * This function makes a view from above a place on the Earth. The picture shows the cap of the Earth around the place.
507
+ *
508
+ * `degrees` is the angle of the cap at the center of the Earth. It is the distance from the place to the edge of the cap, in degrees of a great circle.
509
+ * The default is 90: the picture shows a half of the Earth. `margin` is the space around the cap, as a factor of the height above the surface.
510
+ */
511
+ function globeView(place, degrees = 90, margin = FIT_MARGIN) {
512
+ return capView(globeAngles(place), Math.min(Math.max(degrees, 0), 90) * RADIANS, margin);
513
+ }
514
+ /**
515
+ * This function makes a view that shows each region of a list. The camera is above the middle of the regions.
516
+ * A list with no regions gives a view of a half of the Earth. `margin` is the space around the regions, as a factor of the height above the surface.
517
+ */
518
+ function regionView(regions, margin = FIT_MARGIN) {
519
+ const points = [];
520
+ for (const region of regions) {
521
+ const polygons = region.type === "Polygon" ? [region.coordinates] : region.coordinates;
522
+ for (const polygon of polygons) for (const position of polygon[0] ?? []) points.push(globePoint({
523
+ lat: position[1],
524
+ lon: position[0]
525
+ }));
526
+ }
527
+ return ballView(points, margin);
528
+ }
529
+ /**
530
+ * This function gives the first point of a ball that a ray finds. The center of the ball is the origin of the stage.
531
+ *
532
+ * `direction` has the length 1. A ray that does not find the ball gives `undefined`, and a ray that starts in the ball also gives `undefined`.
533
+ */
534
+ function rayBall(origin, direction, radius) {
535
+ const along = origin.x * direction.x + origin.y * direction.y + origin.z * direction.z;
536
+ const outside = origin.x * origin.x + origin.y * origin.y + origin.z * origin.z - radius * radius;
537
+ if (!(outside > 0)) return void 0;
538
+ const root = along * along - outside;
539
+ if (!(root >= 0)) return void 0;
540
+ const distance = -along - Math.sqrt(root);
541
+ if (!(distance >= 0)) return void 0;
542
+ return {
543
+ x: origin.x + direction.x * distance,
544
+ y: origin.y + direction.y * distance,
545
+ z: origin.z + direction.z * distance
546
+ };
547
+ }
548
+ /**
549
+ * This function tells if a camera at `eye` sees a point of the surface of a ball. The center of the ball is the origin of the stage.
550
+ * A point on the far side of the ball gives false.
551
+ */
552
+ function inSight(point, eye, radius) {
553
+ const length = Math.hypot(point.x, point.y, point.z);
554
+ if (!(length > 0)) return false;
555
+ return (point.x * eye.x + point.y * eye.y + point.z * eye.z) / length > radius;
556
+ }
557
+ // src/globe/content.ts
558
+ /** The smallest height of the layer of the areas above the ball, as a part of the radius. */
559
+ const MIN_LIFT = 5e-4;
560
+ /** The opacity that a mark adds to the surface of an area. */
561
+ const MARK_OPACITY = .16;
562
+ /** The factor of the width of a point with a mark. */
563
+ const MARK_SIZE = 1.35;
564
+ /** The width of the ring around a point, in CSS pixels. */
565
+ const RING_WIDTH = 1.5;
566
+ /** The distance around a point where the pointer finds it, in CSS pixels. */
567
+ const PICK_MARGIN = 4;
568
+ /** The exponent of the shade at the rim. A large value keeps the shade near the rim. */
569
+ const SHADE_POWER = 2.6;
570
+ const BALL_SEGMENTS = 128;
571
+ const SHADE_VERTEX = `
572
+ varying vec3 vNormal;
573
+ varying vec3 vToEye;
574
+ void main() {
575
+ vec4 inView = modelViewMatrix * vec4(position, 1.0);
576
+ vNormal = normalMatrix * normal;
577
+ vToEye = -inView.xyz;
578
+ gl_Position = projectionMatrix * inView;
579
+ }`;
580
+ const SHADE_FRAGMENT = `
581
+ uniform vec3 shade;
582
+ uniform float strength;
583
+ uniform float power;
584
+ varying vec3 vNormal;
585
+ varying vec3 vToEye;
586
+ void main() {
587
+ float facing = clamp(dot(normalize(vNormal), normalize(vToEye)), 0.0, 1.0);
588
+ gl_FragColor = vec4(shade, strength * pow(1.0 - facing, power));
589
+ #include <colorspace_fragment>
590
+ }`;
591
+ const POINT_VERTEX = `
592
+ uniform float pixelRatio;
593
+ uniform float ringWidth;
594
+ attribute vec3 fill;
595
+ attribute vec3 ring;
596
+ attribute float size;
597
+ varying vec3 vFill;
598
+ varying vec3 vRing;
599
+ varying float vFade;
600
+ varying float vInner;
601
+ void main() {
602
+ vec4 inWorld = modelMatrix * vec4(position, 1.0);
603
+ vec3 up = normalize(inWorld.xyz - modelMatrix[3].xyz);
604
+ float facing = dot(up, normalize(cameraPosition - inWorld.xyz));
605
+ vFill = fill;
606
+ vRing = ring;
607
+ vFade = smoothstep(0.0, 0.1, facing);
608
+ vInner = size / (size + 2.0 * ringWidth);
609
+ gl_PointSize = (size + 2.0 * ringWidth) * pixelRatio;
610
+ gl_Position = projectionMatrix * viewMatrix * inWorld;
611
+ // A point on the far side of the Earth, and a point that the picture does not show, goes out of the picture.
612
+ if (facing <= 0.0 || size <= 0.0) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
613
+ }`;
614
+ const POINT_FRAGMENT = `
615
+ varying vec3 vFill;
616
+ varying vec3 vRing;
617
+ varying float vFade;
618
+ varying float vInner;
619
+ void main() {
620
+ float distance = length(gl_PointCoord * 2.0 - 1.0);
621
+ float soft = fwidth(distance);
622
+ float dot = 1.0 - smoothstep(1.0 - soft, 1.0, distance);
623
+ float middle = 1.0 - smoothstep(vInner - soft, vInner, distance);
624
+ gl_FragColor = vec4(mix(vRing, vFill, middle), dot * vFade);
625
+ if (gl_FragColor.a <= 0.0) discard;
626
+ #include <colorspace_fragment>
627
+ }`;
628
+ /** This function gives the text of a thrown value. */
629
+ function messageOf(error) {
630
+ return error instanceof Error ? error.message : String(error);
631
+ }
632
+ /** This function writes the points of lines into a list of segments on a ball: six numbers for each segment. It gives the count of the segments. */
633
+ function addSegments(lines, radius, to) {
634
+ let count = 0;
635
+ for (const line of lines) {
636
+ let from;
637
+ for (let index = 0; index + 1 < line.length; index += 2) {
638
+ const next = globePoint({
639
+ lat: line[index + 1] ?? 0,
640
+ lon: line[index] ?? 0
641
+ }, radius);
642
+ if (from !== void 0) {
643
+ to.push(from.x, from.y, from.z, next.x, next.y, next.z);
644
+ count += 1;
645
+ }
646
+ from = next;
647
+ }
648
+ }
649
+ return count;
650
+ }
651
+ /** This function makes the geometry of thick line segments from a buffer of positions and a buffer of colors: six numbers for each segment. */
652
+ function segmentGeometry(positions, colors, count, bounds) {
653
+ const geometry = new LineSegmentsGeometry();
654
+ geometry.setAttribute("instanceStart", new InterleavedBufferAttribute(positions, 3, 0));
655
+ geometry.setAttribute("instanceEnd", new InterleavedBufferAttribute(positions, 3, 3));
656
+ if (colors !== void 0) {
657
+ geometry.setAttribute("instanceColorStart", new InterleavedBufferAttribute(colors, 3, 0));
658
+ geometry.setAttribute("instanceColorEnd", new InterleavedBufferAttribute(colors, 3, 3));
659
+ }
660
+ geometry.instanceCount = count;
661
+ geometry.boundingSphere = bounds;
662
+ return geometry;
663
+ }
664
+ /**
665
+ * This function makes the content of a stage that shows the Earth as a globe. The center of the globe is the origin of the stage.
666
+ *
667
+ * The materials use no light, so each color in the picture is the color of the theme. Use `GLOBE_POLAR` and no pan in the options of the stage.
668
+ * The function throws an `Error` with the name of the record for an area that is not correct. Its cause is the error of `@mark1russell7/geo`.
669
+ */
670
+ function createGlobe(options = {}) {
671
+ const radius = options.radius ?? 1;
672
+ const step = options.step ?? 1;
673
+ const layer = radius * (1 + Math.max(MIN_LIFT, surfaceSag(step) * 2));
674
+ const bounds = new Sphere(new Vector3(0, 0, 0), layer);
675
+ const color = new Color();
676
+ const ballGeometry = new SphereGeometry(radius, BALL_SEGMENTS, BALL_SEGMENTS / 2);
677
+ const ballMaterial = new MeshBasicMaterial();
678
+ const ball = new Mesh(ballGeometry, ballMaterial);
679
+ const shadeColor = { value: new Color() };
680
+ const shadeMaterial = new ShaderMaterial({
681
+ uniforms: {
682
+ shade: shadeColor,
683
+ strength: { value: Math.min(Math.max(options.shade ?? .4, 0), 1) },
684
+ power: { value: SHADE_POWER }
685
+ },
686
+ vertexShader: SHADE_VERTEX,
687
+ fragmentShader: SHADE_FRAGMENT,
688
+ transparent: true,
689
+ depthTest: false,
690
+ depthWrite: false,
691
+ side: FrontSide
692
+ });
693
+ const shade = new Mesh(ballGeometry, shadeMaterial);
694
+ shade.renderOrder = 4;
695
+ const gridList = [];
696
+ const gridCount = addSegments(gridLines(options.grid ?? 15, step), layer, gridList);
697
+ const gridMaterial = new LineMaterial({
698
+ linewidth: options.gridWidth ?? 1,
699
+ transparent: true,
700
+ depthWrite: false
701
+ });
702
+ const grid = new LineSegments2(segmentGeometry(new InstancedInterleavedBuffer(Float32Array.from(gridList), 6, 1), void 0, gridCount, bounds), gridMaterial);
703
+ grid.renderOrder = 1;
704
+ grid.visible = gridCount > 0;
705
+ grid.frustumCulled = false;
706
+ const surfaces = [];
707
+ const segmentList = [];
708
+ const areaParts = [];
709
+ let cornerTotal = 0;
710
+ let indexTotal = 0;
711
+ let segmentTotal = 0;
712
+ for (const area of options.areas ?? []) try {
713
+ const surface = regionSurface(area.region, step);
714
+ const segmentCount = addSegments(regionEdges(area.region, step), layer, segmentList);
715
+ areaParts.push({
716
+ area,
717
+ locate: area.pick === false ? void 0 : pointLocator(area.region),
718
+ firstCorner: cornerTotal,
719
+ cornerCount: surface.corners.length / 2,
720
+ firstIndex: indexTotal,
721
+ indexCount: surface.triangles.length,
722
+ firstSegment: segmentTotal,
723
+ segmentCount,
724
+ shown: true,
725
+ filled: false,
726
+ lined: false,
727
+ mark: 0
728
+ });
729
+ surfaces.push(surface);
730
+ cornerTotal += surface.corners.length / 2;
731
+ indexTotal += surface.triangles.length;
732
+ segmentTotal += segmentCount;
733
+ } catch (error) {
734
+ throw new Error(`The area of the record ${area.record} is not correct: ${messageOf(error)}`, { cause: error });
735
+ }
736
+ const fillPositions = new Float32Array(cornerTotal * 3);
737
+ const allIndices = new Uint32Array(indexTotal);
738
+ surfaces.forEach((surface, index) => {
739
+ const part = areaParts[index];
740
+ if (part === void 0) return;
741
+ for (let corner = 0; corner < part.cornerCount; corner++) {
742
+ const point = globePoint({
743
+ lat: surface.corners[corner * 2 + 1] ?? 0,
744
+ lon: surface.corners[corner * 2] ?? 0
745
+ }, layer);
746
+ fillPositions.set([
747
+ point.x,
748
+ point.y,
749
+ point.z
750
+ ], (part.firstCorner + corner) * 3);
751
+ }
752
+ for (let at = 0; at < part.indexCount; at++) allIndices[part.firstIndex + at] = (surface.triangles[at] ?? 0) + part.firstCorner;
753
+ });
754
+ const fillColors = new BufferAttribute(new Float32Array(cornerTotal * 4), 4);
755
+ const fillIndices = new BufferAttribute(new Uint32Array(indexTotal), 1);
756
+ const fillGeometry = new BufferGeometry();
757
+ fillGeometry.setAttribute("position", new BufferAttribute(fillPositions, 3));
758
+ fillGeometry.setAttribute("color", fillColors);
759
+ fillGeometry.setIndex(fillIndices);
760
+ fillGeometry.boundingSphere = bounds;
761
+ const fillMaterial = new MeshBasicMaterial({
762
+ vertexColors: true,
763
+ transparent: true,
764
+ depthWrite: false,
765
+ side: FrontSide
766
+ });
767
+ const fills = new Mesh(fillGeometry, fillMaterial);
768
+ fills.renderOrder = 2;
769
+ fills.frustumCulled = false;
770
+ const allSegments = Float32Array.from(segmentList);
771
+ const allSegmentColors = new Float32Array(allSegments.length);
772
+ const edgePositions = new InstancedInterleavedBuffer(new Float32Array(allSegments.length), 6, 1);
773
+ const edgeColors = new InstancedInterleavedBuffer(new Float32Array(allSegments.length), 6, 1);
774
+ const edgeGeometry = segmentGeometry(edgePositions, edgeColors, 0, bounds);
775
+ const edgeMaterial = new LineMaterial({
776
+ linewidth: options.lineWidth ?? 1.25,
777
+ vertexColors: true,
778
+ transparent: true,
779
+ depthWrite: false
780
+ });
781
+ const edges = new LineSegments2(edgeGeometry, edgeMaterial);
782
+ edges.renderOrder = 3;
783
+ edges.frustumCulled = false;
784
+ const markMaterial = new LineMaterial({
785
+ linewidth: options.markWidth ?? 2.5,
786
+ vertexColors: true,
787
+ transparent: true,
788
+ depthWrite: false
789
+ });
790
+ const marked = new LineSegments2(new LineSegmentsGeometry(), markMaterial);
791
+ marked.renderOrder = 5;
792
+ marked.frustumCulled = false;
793
+ marked.visible = false;
794
+ const pointSize = options.pointSize ?? 9;
795
+ const pointParts = (options.points ?? []).map((point) => ({
796
+ point,
797
+ at: globePoint(point.place, layer),
798
+ size: point.size ?? pointSize,
799
+ shown: true,
800
+ filled: false,
801
+ mark: 0
802
+ }));
803
+ const pointPositions = new Float32Array(pointParts.length * 3);
804
+ pointParts.forEach((part, index) => pointPositions.set([
805
+ part.at.x,
806
+ part.at.y,
807
+ part.at.z
808
+ ], index * 3));
809
+ const pointFills = new BufferAttribute(new Float32Array(pointParts.length * 3), 3);
810
+ const pointRings = new BufferAttribute(new Float32Array(pointParts.length * 3), 3);
811
+ const pointSizes = new BufferAttribute(new Float32Array(pointParts.length), 1);
812
+ const pointGeometry = new BufferGeometry();
813
+ pointGeometry.setAttribute("position", new BufferAttribute(pointPositions, 3));
814
+ pointGeometry.setAttribute("fill", pointFills);
815
+ pointGeometry.setAttribute("ring", pointRings);
816
+ pointGeometry.setAttribute("size", pointSizes);
817
+ pointGeometry.boundingSphere = bounds;
818
+ const pixelRatio = { value: 1 };
819
+ const pointMaterial = new ShaderMaterial({
820
+ uniforms: {
821
+ pixelRatio,
822
+ ringWidth: { value: RING_WIDTH }
823
+ },
824
+ vertexShader: POINT_VERTEX,
825
+ fragmentShader: POINT_FRAGMENT,
826
+ transparent: true,
827
+ depthTest: false,
828
+ depthWrite: false
829
+ });
830
+ const dots = new Points(pointGeometry, pointMaterial);
831
+ dots.renderOrder = 6;
832
+ dots.frustumCulled = false;
833
+ dots.visible = pointParts.length > 0;
834
+ dots.onBeforeRender = (renderer) => {
835
+ pixelRatio.value = renderer.getPixelRatio();
836
+ };
837
+ const records = /* @__PURE__ */ new Set([...areaParts.map((part) => part.area.record), ...pointParts.map((part) => part.point.record)]);
838
+ let painted;
839
+ /** The angle of one CSS pixel at the middle of the picture, in radians. */
840
+ let pixelAngle = .001;
841
+ const styleOf = (theme, kind) => theme.styles[kind] ?? theme.other;
842
+ const markColor = (theme, mark) => mark === 2 ? theme.selected : theme.hovered;
843
+ /** This function writes the colors of an area into the buffers. */
844
+ const paintArea = (part, theme) => {
845
+ const style = styleOf(theme, part.area.kind);
846
+ part.filled = style.fill !== void 0;
847
+ part.lined = style.line !== void 0;
848
+ if (style.fill !== void 0) {
849
+ color.set(style.fill);
850
+ const opacity = Math.min(Math.max(style.opacity ?? 1, 0), 1);
851
+ const alpha = part.mark === 0 ? opacity : Math.min(opacity + MARK_OPACITY, 1);
852
+ const values = [
853
+ color.r,
854
+ color.g,
855
+ color.b,
856
+ alpha
857
+ ];
858
+ for (let corner = 0; corner < part.cornerCount; corner++) fillColors.array.set(values, (part.firstCorner + corner) * 4);
859
+ fillColors.needsUpdate = true;
860
+ }
861
+ if (style.line !== void 0) {
862
+ color.set(style.line);
863
+ const values = [
864
+ color.r,
865
+ color.g,
866
+ color.b,
867
+ color.r,
868
+ color.g,
869
+ color.b
870
+ ];
871
+ for (let segment = 0; segment < part.segmentCount; segment++) allSegmentColors.set(values, (part.firstSegment + segment) * 6);
872
+ }
873
+ };
874
+ /** This function puts the data of the shown parts at the start of the buffers that the picture draws. */
875
+ const sync = (theme) => {
876
+ let indexCount = 0;
877
+ let segmentCount = 0;
878
+ let markCount = 0;
879
+ for (const part of areaParts) {
880
+ if (!part.shown) continue;
881
+ if (part.filled) {
882
+ fillIndices.array.set(allIndices.subarray(part.firstIndex, part.firstIndex + part.indexCount), indexCount);
883
+ indexCount += part.indexCount;
884
+ }
885
+ if (part.lined) {
886
+ const from = part.firstSegment * 6;
887
+ const to = from + part.segmentCount * 6;
888
+ edgePositions.array.set(allSegments.subarray(from, to), segmentCount * 6);
889
+ edgeColors.array.set(allSegmentColors.subarray(from, to), segmentCount * 6);
890
+ segmentCount += part.segmentCount;
891
+ }
892
+ if (part.mark !== 0) markCount += part.segmentCount;
893
+ }
894
+ fillIndices.needsUpdate = true;
895
+ fillGeometry.setDrawRange(0, indexCount);
896
+ fills.visible = indexCount > 0;
897
+ edgePositions.needsUpdate = true;
898
+ edgeColors.needsUpdate = true;
899
+ edgeGeometry.instanceCount = segmentCount;
900
+ edges.visible = segmentCount > 0;
901
+ const markPositions = new Float32Array(markCount * 6);
902
+ const markColors = new Float32Array(markCount * 6);
903
+ let at = 0;
904
+ for (const part of areaParts) {
905
+ if (!part.shown || part.mark === 0) continue;
906
+ color.set(markColor(theme, part.mark));
907
+ const values = [
908
+ color.r,
909
+ color.g,
910
+ color.b,
911
+ color.r,
912
+ color.g,
913
+ color.b
914
+ ];
915
+ markPositions.set(allSegments.subarray(part.firstSegment * 6, (part.firstSegment + part.segmentCount) * 6), at * 6);
916
+ for (let segment = 0; segment < part.segmentCount; segment++) markColors.set(values, (at + segment) * 6);
917
+ at += part.segmentCount;
918
+ }
919
+ marked.geometry.dispose();
920
+ marked.geometry = markCount > 0 ? segmentGeometry(new InstancedInterleavedBuffer(markPositions, 6, 1), new InstancedInterleavedBuffer(markColors, 6, 1), markCount, bounds) : new LineSegmentsGeometry();
921
+ marked.visible = markCount > 0;
922
+ pointParts.forEach((part, index) => {
923
+ const style = styleOf(theme, part.point.kind);
924
+ part.filled = style.fill !== void 0;
925
+ const visible = part.shown && style.fill !== void 0;
926
+ pointSizes.array[index] = visible ? part.size * (part.mark === 0 ? 1 : MARK_SIZE) : 0;
927
+ if (style.fill === void 0) return;
928
+ color.set(style.fill);
929
+ pointFills.array.set([
930
+ color.r,
931
+ color.g,
932
+ color.b
933
+ ], index * 3);
934
+ color.set(part.mark === 0 ? style.line ?? style.fill : markColor(theme, part.mark));
935
+ pointRings.array.set([
936
+ color.r,
937
+ color.g,
938
+ color.b
939
+ ], index * 3);
940
+ });
941
+ pointSizes.needsUpdate = true;
942
+ pointFills.needsUpdate = true;
943
+ pointRings.needsUpdate = true;
944
+ };
945
+ return {
946
+ objects: [
947
+ ball,
948
+ grid,
949
+ fills,
950
+ edges,
951
+ shade,
952
+ marked,
953
+ dots
954
+ ],
955
+ extent: {
956
+ center: {
957
+ x: 0,
958
+ y: 0,
959
+ z: 0
960
+ },
961
+ corners: [],
962
+ surface: radius,
963
+ minDistance: radius * (1 + Math.max(options.nearest ?? .005, 1e-6))
964
+ },
965
+ has: (record) => records.has(record),
966
+ pick(ray) {
967
+ const { origin, direction } = ray.ray;
968
+ let found;
969
+ let nearest = 1e400;
970
+ for (const part of pointParts) {
971
+ if (!part.shown || !part.filled || part.point.pick === false || !inSight(part.at, origin, radius)) continue;
972
+ const x = part.at.x - origin.x;
973
+ const y = part.at.y - origin.y;
974
+ const z = part.at.z - origin.z;
975
+ const cosine = (x * direction.x + y * direction.y + z * direction.z) / Math.hypot(x, y, z);
976
+ const angle = Math.acos(Math.min(Math.max(cosine, -1), 1));
977
+ if (angle > (part.size / 2 + PICK_MARGIN) * pixelAngle || angle >= nearest) continue;
978
+ found = part;
979
+ nearest = angle;
980
+ }
981
+ if (found !== void 0) return {
982
+ record: found.point.record,
983
+ value: found.point.value
984
+ };
985
+ const hit = rayBall(origin, direction, radius);
986
+ const place = hit === void 0 ? void 0 : globePlace(hit);
987
+ if (place === void 0) return void 0;
988
+ for (let index = areaParts.length - 1; index >= 0; index--) {
989
+ const part = areaParts[index];
990
+ if (part === void 0 || !part.shown || part.locate === void 0 || !(part.filled || part.lined)) continue;
991
+ if (part.locate(place) !== "outside") return {
992
+ record: part.area.record,
993
+ value: part.area.value
994
+ };
995
+ }
996
+ },
997
+ paint(theme, mark) {
998
+ const all = theme !== painted;
999
+ painted = theme;
1000
+ if (all) {
1001
+ ballMaterial.color.set(theme.ball);
1002
+ gridMaterial.color.set(theme.grid);
1003
+ shadeColor.value.set(theme.shade);
1004
+ }
1005
+ for (const part of areaParts) {
1006
+ const next = mark(part.area.record);
1007
+ if (!all && next === part.mark) continue;
1008
+ part.mark = next;
1009
+ paintArea(part, theme);
1010
+ }
1011
+ for (const part of pointParts) part.mark = mark(part.point.record);
1012
+ sync(theme);
1013
+ },
1014
+ step(frame) {
1015
+ pixelAngle = 2 * Math.tan(frame.fieldOfView * Math.PI / 360) / Math.max(frame.height, 1);
1016
+ return false;
1017
+ },
1018
+ show(test) {
1019
+ for (const part of areaParts) part.shown = test(part.area);
1020
+ for (const part of pointParts) part.shown = test(part.point);
1021
+ if (painted !== void 0) sync(painted);
1022
+ },
1023
+ placeAt(ray) {
1024
+ const hit = rayBall(ray.ray.origin, ray.ray.direction, radius);
1025
+ return hit === void 0 ? void 0 : globePlace(hit);
1026
+ },
1027
+ dispose() {
1028
+ ballGeometry.dispose();
1029
+ ballMaterial.dispose();
1030
+ shadeMaterial.dispose();
1031
+ grid.geometry.dispose();
1032
+ gridMaterial.dispose();
1033
+ fillGeometry.dispose();
1034
+ fillMaterial.dispose();
1035
+ edgeGeometry.dispose();
1036
+ edgeMaterial.dispose();
1037
+ marked.geometry.dispose();
1038
+ markMaterial.dispose();
1039
+ pointGeometry.dispose();
1040
+ pointMaterial.dispose();
1041
+ }
1042
+ };
1043
+ }
1044
+ export { GLOBE_POLAR, MAX_SURFACE_CORNERS, createGlobe, globeAngles, globePlace, globePoint, globeView, gridLines, inSight, rayBall, regionEdges, regionSurface, regionView, surfaceSag };
1045
+
1046
+ //# sourceMappingURL=globe.js.map