nodes2ts 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +116 -13
  3. package/dist/export.cjs +5331 -0
  4. package/dist/export.cjs.map +1 -0
  5. package/dist/export.d.cts +1838 -0
  6. package/dist/export.d.ts +1828 -20
  7. package/dist/export.js +5279 -51
  8. package/dist/export.js.map +1 -1
  9. package/package.json +34 -49
  10. package/dist/Interval.d.ts +0 -24
  11. package/dist/Interval.js +0 -22
  12. package/dist/Interval.js.map +0 -1
  13. package/dist/MutableInteger.d.ts +0 -4
  14. package/dist/MutableInteger.js +0 -9
  15. package/dist/MutableInteger.js.map +0 -1
  16. package/dist/R1Interval.d.ts +0 -76
  17. package/dist/R1Interval.js +0 -167
  18. package/dist/R1Interval.js.map +0 -1
  19. package/dist/R2Vector.d.ts +0 -34
  20. package/dist/R2Vector.js +0 -138
  21. package/dist/R2Vector.js.map +0 -1
  22. package/dist/S1Angle.d.ts +0 -26
  23. package/dist/S1Angle.js +0 -78
  24. package/dist/S1Angle.js.map +0 -1
  25. package/dist/S1Interval.d.ts +0 -109
  26. package/dist/S1Interval.js +0 -403
  27. package/dist/S1Interval.js.map +0 -1
  28. package/dist/S2.d.ts +0 -91
  29. package/dist/S2.js +0 -236
  30. package/dist/S2.js.map +0 -1
  31. package/dist/S2Cap.d.ts +0 -113
  32. package/dist/S2Cap.js +0 -392
  33. package/dist/S2Cap.js.map +0 -1
  34. package/dist/S2Cell.d.ts +0 -103
  35. package/dist/S2Cell.js +0 -361
  36. package/dist/S2Cell.js.map +0 -1
  37. package/dist/S2CellId.d.ts +0 -267
  38. package/dist/S2CellId.js +0 -933
  39. package/dist/S2CellId.js.map +0 -1
  40. package/dist/S2CellUnion.d.ts +0 -180
  41. package/dist/S2CellUnion.js +0 -518
  42. package/dist/S2CellUnion.js.map +0 -1
  43. package/dist/S2EdgeUtil.d.ts +0 -17
  44. package/dist/S2EdgeUtil.js +0 -787
  45. package/dist/S2EdgeUtil.js.map +0 -1
  46. package/dist/S2LatLng.d.ts +0 -72
  47. package/dist/S2LatLng.js +0 -182
  48. package/dist/S2LatLng.js.map +0 -1
  49. package/dist/S2LatLngRect.d.ts +0 -185
  50. package/dist/S2LatLngRect.js +0 -605
  51. package/dist/S2LatLngRect.js.map +0 -1
  52. package/dist/S2Metric.d.ts +0 -38
  53. package/dist/S2Metric.js +0 -75
  54. package/dist/S2Metric.js.map +0 -1
  55. package/dist/S2Point.d.ts +0 -43
  56. package/dist/S2Point.js +0 -200
  57. package/dist/S2Point.js.map +0 -1
  58. package/dist/S2Projections.d.ts +0 -67
  59. package/dist/S2Projections.js +0 -152
  60. package/dist/S2Projections.js.map +0 -1
  61. package/dist/S2Region.d.ts +0 -31
  62. package/dist/S2Region.js +0 -17
  63. package/dist/S2Region.js.map +0 -1
  64. package/dist/S2RegionCoverer.d.ts +0 -171
  65. package/dist/S2RegionCoverer.js +0 -435
  66. package/dist/S2RegionCoverer.js.map +0 -1
  67. package/yarn.lock +0 -4381
package/dist/export.d.ts CHANGED
@@ -1,23 +1,1829 @@
1
- import { S2Region } from "./S2Region";
2
- import { S2LatLng } from "./S2LatLng";
3
- export * from './Interval';
4
- export * from './MutableInteger';
5
- export * from './R1Interval';
6
- export * from './R2Vector';
7
- export * from './S1Angle';
8
- export * from './S1Interval';
9
- export * from './S2';
10
- export * from './S2Cap';
11
- export * from './S2Cell';
12
- export * from './S2CellId';
13
- export * from './S2CellUnion';
14
- export * from './S2LatLng';
15
- export * from './S2LatLngRect';
16
- export * from './S2Point';
17
- export * from './S2Projections';
18
- export * from './S2Region';
19
- export * from './S2RegionCoverer';
20
- export declare class Utils {
1
+ declare abstract class Interval {
2
+ lo: number;
3
+ hi: number;
4
+ constructor(lo: number, hi: number);
5
+ /** Return true if the interval is empty, i.e. it contains no points. */
6
+ abstract isEmpty(): boolean;
7
+ /**
8
+ * Return the center of the interval. For empty intervals, the result is
9
+ * arbitrary.
10
+ */
11
+ abstract getCenter(): number;
12
+ /**
13
+ * Return the length of the interval. The length of an empty interval is
14
+ * negative.
15
+ */
16
+ abstract getLength(): number;
17
+ abstract contains(p: number): boolean;
18
+ abstract interiorContains(p: number): boolean;
19
+ toString(): string;
20
+ /**
21
+ * Return true if two intervals contains the same set of points.
22
+ */
23
+ equals(that: Interval): boolean;
24
+ }
25
+
26
+ declare class S1Interval extends Interval {
27
+ constructor(lo: number, hi: number, checked?: boolean);
28
+ /**
29
+ * An interval is valid if neither bound exceeds Pi in absolute value, and the
30
+ * value -Pi appears only in the Empty() and Full() intervals.
31
+ */
32
+ isValid(): boolean;
33
+ /** Return true if the interval contains all points on the unit circle. */
34
+ isFull(): boolean;
35
+ /** Return true if the interval is empty, i.e. it contains no points. */
36
+ isEmpty(): boolean;
37
+ isInverted(): boolean;
38
+ /**
39
+ * Return the midpoint of the interval. For full and empty intervals, the
40
+ * result is arbitrary.
41
+ */
42
+ getCenter(): number;
43
+ /**
44
+ * Return the length of the interval. The length of an empty interval is
45
+ * negative.
46
+ */
47
+ getLength(): number;
48
+ /**
49
+ * Return the complement of the interior of the interval. An interval and its
50
+ * complement have the same boundary but do not share any interior values. The
51
+ * complement operator is not a bijection, since the complement of a singleton
52
+ * interval (containing a single value) is the same as the complement of an
53
+ * empty interval.
54
+ */
55
+ complement(): S1Interval;
56
+ /** Return true if the interval (which is closed) contains the point 'p'. */
57
+ contains(_p: number): boolean;
58
+ /**
59
+ * Return true if the interval (which is closed) contains the point 'p'. Skips
60
+ * the normalization of 'p' from -Pi to Pi.
61
+ *
62
+ */
63
+ fastContains(_p: number): boolean;
64
+ /** Return true if the interior of the interval contains the point 'p'. */
65
+ interiorContains(_p: number): boolean;
66
+ /**
67
+ * Return true if the interval contains the given interval 'y'. Works for
68
+ * empty, full, and singleton intervals.
69
+ */
70
+ containsI(y: S1Interval): boolean;
71
+ /**
72
+ * Returns true if the interior of this interval contains the entire interval
73
+ * 'y'. Note that x.InteriorContains(x) is true only when x is the empty or
74
+ * full interval, and x.InteriorContains(S1Interval(p,p)) is equivalent to
75
+ * x.InteriorContains(p).
76
+ */
77
+ interiorContainsI(y: S1Interval): boolean;
78
+ /**
79
+ * Return true if the two intervals contain any points in common. Note that
80
+ * the point +/-Pi has two representations, so the intervals [-Pi,-3] and
81
+ * [2,Pi] intersect, for example.
82
+ */
83
+ intersects(y: S1Interval): boolean;
84
+ /**
85
+ * Return true if the interior of this interval contains any point of the
86
+ * interval 'y' (including its boundary). Works for empty, full, and singleton
87
+ * intervals.
88
+ */
89
+ interiorIntersects(y: S1Interval): boolean;
90
+ /**
91
+ * Expand the interval by the minimum amount necessary so that it contains the
92
+ * given point "p" (an angle in the range [-Pi, Pi]).
93
+ */
94
+ addPoint(_p: number): S1Interval;
95
+ /**
96
+ * Return an interval that contains all points within a distance "radius" of
97
+ * a point in this interval. Note that the expansion of an empty interval is
98
+ * always empty. The radius must be non-negative.
99
+ */
100
+ expanded(radius: number): S1Interval;
101
+ /**
102
+ * Return the smallest interval that contains this interval and the given
103
+ * interval "y".
104
+ */
105
+ union(y: S1Interval): S1Interval;
106
+ /**
107
+ * Return the smallest interval that contains the intersection of this
108
+ * interval with "y". Note that the region of intersection may consist of two
109
+ * disjoint intervals.
110
+ */
111
+ intersection(y: S1Interval): S1Interval;
112
+ /**
113
+ * Return true if the length of the symmetric difference between the two
114
+ * intervals is at most the given tolerance.
115
+ */
116
+ approxEquals(y: S1Interval, maxError?: number): boolean;
117
+ static empty(): S1Interval;
118
+ static full(): S1Interval;
119
+ static fromPoint(_p: number): S1Interval;
120
+ /**
121
+ * Convenience method to construct the minimal interval containing the two
122
+ * given points. This is equivalent to starting with an empty interval and
123
+ * calling AddPoint() twice, but it is more efficient.
124
+ */
125
+ static fromPointPair(_p1: number, _p2: number): S1Interval;
126
+ /**
127
+ * Compute the distance from "a" to "b" in the range [0, 2*Pi). This is
128
+ * equivalent to (drem(b - a - S2.M_PI, 2 * S2.M_PI) + S2.M_PI), except that
129
+ * it is more numerically stable (it does not lose precision for very small
130
+ * positive distances).
131
+ */
132
+ static positiveDistance(_a: number, _b: number): number;
133
+ }
134
+
135
+ /**
136
+ * An R1Interval represents a closed interval on a unit circle (also known as a
137
+ * 1-dimensional sphere). It is capable of representing the empty interval
138
+ * (containing no points), the full interval (containing all points), and
139
+ * zero-length intervals (containing a single point).
140
+ *
141
+ * Points are represented by the angle they make with the positive x-axis in
142
+ * the range [-Pi, Pi]. An interval is represented by its lower and upper bounds
143
+ * (both inclusive, since the interval is closed). The lower bound may be
144
+ * greater than the upper bound, in which case the interval is "inverted" (i.e.
145
+ * it passes through the point (-1, 0)).
146
+ *
147
+ * Note that the point (-1, 0) has two valid representations, Pi and -Pi. The
148
+ * normalized representation of this point internally is Pi, so that endpoints
149
+ * of normal intervals are in the range (-Pi, Pi]. However, we take advantage of
150
+ * the point -Pi to construct two special intervals: the Full() interval is
151
+ * [-Pi, Pi], and the Empty() interval is [Pi, -Pi].
152
+ *
153
+ */
154
+ declare class R1Interval extends Interval {
155
+ /** Return true if the interval is empty, i.e. it contains no points. */
156
+ isEmpty(): boolean;
157
+ getCenter(): number;
158
+ getLength(): number;
159
+ contains(p: number): boolean;
160
+ /** Return true if the interior of the interval contains the point 'p'. */
161
+ interiorContains(p: number): boolean;
162
+ /**
163
+ * Return true if the interval contains the given interval 'y'. Works for
164
+ * empty, full, and singleton intervals.
165
+ */
166
+ containsI(y: R1Interval): boolean;
167
+ interiorContainsI(y: R1Interval): boolean;
168
+ /**
169
+ * Return true if this interval intersects the given interval, i.e. if they
170
+ * have any points in common.
171
+ */
172
+ intersects(y: R1Interval): boolean;
173
+ /**
174
+ * Return true if the interior of this interval intersects any point of the
175
+ * given interval (including its boundary).
176
+ */
177
+ interiorIntersects(y: R1Interval): boolean;
178
+ /** Expand the interval so that it contains the given point "p". */
179
+ addPoint(p: number): R1Interval;
180
+ /**
181
+ * Return an interval that contains all points with a distance "radius" of a
182
+ * point in this interval. Note that the expansion of an empty interval is
183
+ * always empty.
184
+ */
185
+ expanded(radius: number): R1Interval;
186
+ /**
187
+ * Return the smallest interval that contains this interval and the given
188
+ * interval "y".
189
+ */
190
+ union(y: R1Interval): R1Interval;
191
+ /**
192
+ * Return the intersection of this interval with the given interval. Empty
193
+ * intervals do not need to be special-cased.
194
+ */
195
+ intersection(y: R1Interval): R1Interval;
196
+ /**
197
+ * Return true if the length of the symmetric difference between the two
198
+ * intervals is at most the given tolerance.
199
+ */
200
+ approxEquals(y: R1Interval, maxError?: number): boolean;
201
+ static empty(): R1Interval;
202
+ static fromPoint(p: number): R1Interval;
203
+ /**
204
+ * Convenience method to construct the minimal interval containing the two
205
+ * given points. This is equivalent to starting with an empty interval and
206
+ * calling AddPoint() twice, but it is more efficient.
207
+ */
208
+ static fromPointPair(p1: number, p2: number): R1Interval;
209
+ }
210
+
211
+ /**
212
+ * R2Vector represents a vector in the two-dimensional space. It defines the
213
+ * basic geometrical operations for 2D vectors, e.g. cross product, addition,
214
+ * norm, comparison etc.
215
+ *
216
+ */
217
+ declare class R2Vector {
218
+ private _x;
219
+ private _y;
220
+ constructor(_x: number, _y: number);
221
+ get x(): number;
222
+ get y(): number;
223
+ get(index: number): number;
224
+ static fromPointFace(p: S2Point, face: number): R2Vector;
225
+ static add(p1: R2Vector, p2: R2Vector): R2Vector;
226
+ static mul(p: R2Vector, m: number): R2Vector;
227
+ norm2(): number;
228
+ static dotProd(p1: R2Vector, p2: R2Vector): number;
229
+ dotProd(that: R2Vector): number;
230
+ crossProd(that: R2Vector): number;
231
+ lessThan(vb: R2Vector): boolean;
232
+ static fromSTVector(stVector: R2Vector): R2Vector;
233
+ static singleStTOUV(s: number): number;
234
+ static singleUVToST(u: number): number;
235
+ /**
236
+ * To be used only if this vector is representing uv.
237
+ * @param face
238
+ * @returns {S2Point}
239
+ */
240
+ toPoint(face: number): S2Point;
241
+ toSt(which: number): number;
242
+ toString(): string;
243
+ }
244
+
245
+ /**
246
+ * An S2Point represents a point on the unit sphere as a 3D vector. Usually
247
+ * points are normalized to be unit length, but some methods do not require
248
+ * this.
249
+ *
250
+ */
251
+ declare class S2Point {
252
+ /** Origin of the coordinate system, [0,0,0]. */
253
+ static ORIGIN: S2Point;
254
+ /** Direction of the x-axis. */
255
+ static X_POS: S2Point;
256
+ /** Opposite direction of the x-axis. */
257
+ static X_NEG: S2Point;
258
+ /** Direction of the y-axis. */
259
+ static Y_POS: S2Point;
260
+ /** Opposite direction of the y-axis. */
261
+ static Y_NEG: S2Point;
262
+ /** Direction of the z-axis. */
263
+ static Z_POS: S2Point;
264
+ /** Opposite direction of the z-axis. */
265
+ static Z_NEG: S2Point;
266
+ x: number;
267
+ y: number;
268
+ z: number;
269
+ constructor(x: number, y: number, z: number);
270
+ static minus(p1: S2Point, p2: S2Point): S2Point;
271
+ static neg(p: S2Point): S2Point;
272
+ norm2(): number;
273
+ norm(): number;
274
+ static crossProd(p1: S2Point, p2: S2Point): S2Point;
275
+ static add(p1: S2Point, p2: S2Point): S2Point;
276
+ static sub(p1: S2Point, p2: S2Point): S2Point;
277
+ dotProd(that: S2Point): number;
278
+ static mul(p: any, m: number): S2Point;
279
+ static div(p: S2Point, m: number): S2Point;
280
+ /**
281
+ * Returns the distance in 3D coordinates from this to that.
282
+ *
283
+ * <p>Equivalent to {@code a.sub(b).norm()}, but significantly faster.
284
+ *
285
+ * <p>If ordering points by angle, this is faster than {@link #norm}, and much faster than {@link
286
+ * #angle}, but consider using {@link S1ChordAngle}.
287
+ */
288
+ getDistance(that: S2Point): number;
289
+ /**
290
+ * Returns the square of the distance in 3D coordinates from this to that.
291
+ *
292
+ * <p>Equivalent to {@code getDistance(that)<sup>2</sup>}, but significantly faster.
293
+ *
294
+ * <p>If ordering points by angle, this is much faster than {@link #angle}, but consider using
295
+ * {@link S1ChordAngle}.
296
+ */
297
+ getDistance2(that: S2Point): number;
298
+ /** return a vector orthogonal to this one */
299
+ ortho(): S2Point;
300
+ /** Return the index of the largest component fabs */
301
+ largestAbsComponent(): number;
302
+ static largestAbsComponent(x: number, y: number, z: number): number;
303
+ get(axis: number): number;
304
+ static fabs(p: S2Point): S2Point;
305
+ /** Returns a copy of 'p' rescaled to be unit-length. */
306
+ static normalize(p: S2Point): S2Point;
307
+ axis(axis: number): number;
308
+ /** Return the angle between two vectors in radians */
309
+ angle(va: any): number;
310
+ /**
311
+ * Compare two vectors, return true if all their components are within a
312
+ * difference of margin.
313
+ */
314
+ aequal(that: S2Point, margin: number): boolean;
315
+ equals(that: S2Point): boolean;
316
+ lessThan(vb: S2Point): boolean;
317
+ compareTo(other: S2Point): number;
318
+ toFace(): number;
319
+ toR2Vector(face?: number): R2Vector;
320
+ toString(): string;
321
+ }
322
+
323
+ declare class S1Angle {
324
+ static INFINITY: S1Angle;
325
+ static ZERO: S1Angle;
326
+ radians: number;
327
+ constructor(radians: number);
328
+ degrees(): number;
329
+ /**
330
+ * Return the angle between two points, which is also equal to the distance
331
+ * between these points on the unit sphere. The points do not need to be
332
+ * normalized.
333
+ */
334
+ static fromPoints(x: S2Point, y: S2Point): S1Angle;
335
+ lessThan(that: S1Angle): boolean;
336
+ greaterThan(that: S1Angle): boolean;
337
+ lessOrEquals(that: S1Angle): boolean;
338
+ greaterOrEquals(that: S1Angle): boolean;
339
+ static max(left: S1Angle, right: S1Angle): S1Angle;
340
+ static min(left: S1Angle, right: S1Angle): S1Angle;
341
+ static radians(radians: number): S1Angle;
342
+ static degrees(degrees: number): S1Angle;
343
+ /**
344
+ * Retuns an {@link S1Angle} whose angle is <code>(this + a)</code>.
345
+ */
346
+ add(a: S1Angle): S1Angle;
347
+ /**
348
+ * Retuns an {@link S1Angle} whose angle is <code>(this - a)</code>.
349
+ */
350
+ sub(a: S1Angle): S1Angle;
351
+ /**
352
+ * Retuns an {@link S1Angle} whose angle is <code>(this * m)</code>.
353
+ */
354
+ mul(m: number): S1Angle;
355
+ /**
356
+ * Retuns an {@link S1Angle} whose angle is <code>(this / d)</code>.
357
+ */
358
+ div(d: number): S1Angle;
359
+ /**
360
+ * Returns the trigonometric cosine of the angle.
361
+ */
362
+ cos(): number;
363
+ /**
364
+ * Returns the trigonometric sine of the angle.
365
+ */
366
+ sin(): number;
367
+ /**
368
+ * Returns the trigonometric tangent of the angle.
369
+ */
370
+ tan(): number;
371
+ /** Returns the distance along the surface of a sphere of the given radius. */
372
+ distance(radius: number): number;
373
+ /**
374
+ * Writes the angle in degrees with a "d" suffix, e.g. "17.3745d". By default
375
+ * 6 digits are printed; this can be changed using setprecision(). Up to 17
376
+ * digits are required to distinguish one angle from another.
377
+ */
378
+ toString(): string;
379
+ compareTo(that: S1Angle): number;
380
+ equals(that: S1Angle): boolean;
381
+ }
382
+
383
+ /**
384
+ * This class represents a point on the unit sphere as a pair of
385
+ * latitude-longitude coordinates. Like the rest of the "geometry" package, the
386
+ * intent is to represent spherical geometry as a mathematical abstraction, so
387
+ * functions that are specifically related to the Earth's geometry (e.g.
388
+ * easting/northing conversions) should be put elsewhere.
389
+ *
390
+ */
391
+ declare class S2LatLng {
392
+ /**
393
+ * Approximate "effective" radius of the Earth in meters.
394
+ */
395
+ static EARTH_RADIUS_METERS: number;
396
+ /** The center point the lat/lng coordinate system. */
397
+ static CENTER: S2LatLng;
398
+ latRadians: number;
399
+ lngRadians: number;
400
+ constructor(latRadians: number, lngRadians: number);
401
+ get latDegrees(): number;
402
+ get lngDegrees(): number;
403
+ /** Convert an S2LatLng to the equivalent unit-length vector (S2Point). */
404
+ toPoint(): S2Point;
405
+ /**
406
+ * Returns a new S2LatLng based on this instance for which {@link #isValid()}
407
+ * will be {@code true}.
408
+ * <ul>
409
+ * <li>Latitude is clipped to the range {@code [-90, 90]}
410
+ * <li>Longitude is normalized to be in the range {@code [-180, 180]}
411
+ * </ul>
412
+ * <p>If the current point is valid then the returned point will have the same
413
+ * coordinates.
414
+ */
415
+ normalized(): S2LatLng;
416
+ static fromDegrees(latDegrees: number, lngDegrees: number): S2LatLng;
417
+ static fromRadians(latRadians: number, lngRadians: number): S2LatLng;
418
+ static fromPoint(p: S2Point): S2LatLng;
419
+ /** Returns the latitude of this point as a new S1Angle. */
420
+ lat(): S1Angle;
421
+ /** Returns the longitude of this point as a new S1Angle. */
422
+ lng(): S1Angle;
423
+ /**
424
+ * Return true if the latitude is between -90 and 90 degrees inclusive and the
425
+ * longitude is between -180 and 180 degrees inclusive.
426
+ */
427
+ isValid(): boolean;
428
+ /**
429
+ * Scales this point by the given scaling factor.
430
+ * Note that there is no guarantee that the new point will be <em>valid</em>.
431
+ */
432
+ mul(m: number): S2LatLng;
433
+ static latitude(p: S2Point): S1Angle;
434
+ static longitude(p: S2Point): S1Angle;
435
+ equals(other: S2LatLng): boolean;
436
+ pointAtDistance(distanceInKM: number, bearingRadians: number): S2LatLng;
437
+ /**
438
+ * Generates n LatLngs given a distance in km and the number of points wanted.
439
+ * Generated points will be returned in a Clockwise order starting from North.
440
+ * @param _distanceInKm
441
+ * @param nPoints
442
+ * @returns {S2LatLng[]}
443
+ */
444
+ pointsAtDistance(_distanceInKm: number, nPoints?: number): S2LatLng[];
445
+ getEarthDistance(other: S2LatLng): number;
446
+ getDistance(other: S2LatLng): S1Angle;
447
+ toString(): string;
448
+ toStringDegrees(): string;
449
+ toGEOJSON(): {
450
+ type: string;
451
+ geometry: {
452
+ type: string;
453
+ coordinates: number[];
454
+ };
455
+ properties: {};
456
+ };
457
+ }
458
+
459
+ declare class MutableInteger {
460
+ val: number;
461
+ constructor(val: number);
462
+ }
463
+
464
+ /**
465
+ * An S2CellId is a 64-bit unsigned integer that uniquely identifies a cell in
466
+ * the S2 cell decomposition. It has the following format:
467
+ *
468
+ * <pre>
469
+ * id = [face][face_pos]
470
+ * </pre>
471
+ *
472
+ * face: a 3-bit number (range 0..5) encoding the cube face.
473
+ *
474
+ * face_pos: a 61-bit number encoding the position of the center of this cell
475
+ * along the Hilbert curve over this face (see the Wiki pages for details).
476
+ *
477
+ * Sequentially increasing cell ids follow a continuous space-filling curve over
478
+ * the entire sphere. They have the following properties:
479
+ * - The id of a cell at level k consists of a 3-bit face number followed by k
480
+ * bit pairs that recursively select one of the four children of each cell. The
481
+ * next bit is always 1, and all other bits are 0. Therefore, the level of a
482
+ * cell is determined by the position of its lowest-numbered bit that is turned
483
+ * on (for a cell at level k, this position is 2 * (MAX_LEVEL - k).)
484
+ * - The id of a parent cell is at the midpoint of the range of ids spanned by
485
+ * its children (or by its descendants at any level).
486
+ *
487
+ * Leaf cells are often used to represent points on the unit sphere, and this
488
+ * class provides methods for converting directly between these two
489
+ * representations. For cells that represent 2D regions rather than discrete
490
+ * point, it is better to use the S2Cell class.
491
+ *
492
+ * v4 CHANGE: S2CellId.id is now a native bigint (unsigned uint64).
493
+ * The constructor accepts both bigint and string (signed or unsigned decimal).
494
+ */
495
+ declare class S2CellId {
496
+ static FACE_BITS: number;
497
+ static NUM_FACES: number;
498
+ static MAX_LEVEL: number;
499
+ static POS_BITS: number;
500
+ static MAX_SIZE: number;
501
+ /** Maximum unsigned 64-bit value (sentinel). */
502
+ static MAX_UNSIGNED: bigint;
503
+ static LOOKUP_BITS: number;
504
+ private static SWAP_MASK;
505
+ private static INVERT_MASK;
506
+ private static I_SHIFT;
507
+ private static J_SHIFT;
508
+ private static J_MASK;
509
+ private static SI_SHIFT;
510
+ private static ORIENTATION_MASK;
511
+ private static TI_MASK;
512
+ /** LOOKUP_POS[10-bit key] = 10-bit value (stored as bigint) */
513
+ static LOOKUP_POS: bigint[];
514
+ /** LOOKUP_IJ[10-bit key] = 10-bit value */
515
+ static LOOKUP_IJ: number[];
516
+ /**
517
+ * This is the offset required to wrap around from the beginning of the
518
+ * Hilbert curve to the end or vice versa; see next_wrap() and prev_wrap().
519
+ */
520
+ private static WRAP_OFFSET;
521
+ /**
522
+ * The 64-bit unsigned cell ID.
523
+ * v4: changed from Long to bigint. Always in [0, 2^64-1].
524
+ */
525
+ id: bigint;
526
+ /**
527
+ * Construct an S2CellId from a bigint or decimal string.
528
+ *
529
+ * The string may be signed ("-6533045114107854848") or unsigned
530
+ * ("11913698959601696768"); both are handled via BigInt.asUintN(64, ...).
531
+ */
532
+ constructor(id: bigint | string);
533
+ /**
534
+ * Construct an S2CellId from a **signed**-decimal string produced by Java's
535
+ * Long.toString() or the v3 Long-based API. Equivalent to `new S2CellId(s)`
536
+ * but makes the intent explicit.
537
+ *
538
+ * @example
539
+ * S2CellId.fromSignedDecimalString('-6533045114107854848')
540
+ */
541
+ static fromSignedDecimalString(s: string): S2CellId;
542
+ /**
543
+ * Return this cell id as a signed-decimal string, matching the output of
544
+ * Java's Long.toString() and the v3 Long-based API.
545
+ *
546
+ * @example
547
+ * cellId.toSignedDecimalString() // '-6533045114107854848'
548
+ */
549
+ toSignedDecimalString(): string;
550
+ /**
551
+ * Return this cell id as an unsigned-decimal string (same as `this.id.toString()`).
552
+ *
553
+ * @example
554
+ * cellId.toUnsignedDecimalString() // '11913698959601696768'
555
+ */
556
+ toUnsignedDecimalString(): string;
557
+ /** Which cube face this cell belongs to, in the range 0..5. */
558
+ get face(): number;
559
+ /** Return the lowest-numbered bit that is on for this cell. */
560
+ lowestOnBit(): bigint;
561
+ static lowestOnBit(id: bigint): bigint;
562
+ /** Return an invalid cell id (id == 0). */
563
+ static none(): S2CellId;
564
+ /**
565
+ * Returns an invalid cell id guaranteed to be larger than any valid cell id.
566
+ * Useful for creating indexes.
567
+ */
568
+ static sentinel(): S2CellId;
569
+ private getBits1;
570
+ /** Return the lowest-numbered bit that is on for cells at the given level. */
571
+ static lowestOnBitForLevel(level: number): bigint;
572
+ /**
573
+ * @deprecated use `toIJOrientation` instead
574
+ */
575
+ toFaceIJOrientation(pi: MutableInteger, pj: MutableInteger, orientation: MutableInteger): number;
576
+ /**
577
+ * Return a packed bigint encoding (i << I_SHIFT | j << J_SHIFT | orientation).
578
+ * Use getI(), getJ(), getOrientation() to unpack.
579
+ */
580
+ toIJOrientation(): bigint;
581
+ getI(): number;
582
+ static getI(ijo: bigint): number;
583
+ getJ(): number;
584
+ static getJ(ijo: bigint): number;
585
+ static getOrientation(ijo: bigint): number;
586
+ /** Return true if this is a leaf cell (level() == MAX_LEVEL). */
587
+ isLeaf(): boolean;
588
+ /**
589
+ * Return the cell at the given level (which must be ≤ the current level).
590
+ */
591
+ parentL(level: number): S2CellId;
592
+ parent(): S2CellId;
593
+ /**
594
+ * Return a cell given its face (range 0..5), 61-bit Hilbert curve position
595
+ * within that face, and level (range 0..MAX_LEVEL).
596
+ *
597
+ * v4: `pos` is now `bigint` (was `Long`).
598
+ */
599
+ static fromFacePosLevel(face: number, pos: bigint, level: number): S2CellId;
600
+ static fromFace(face: number): S2CellId;
601
+ static fromPoint(p: S2Point): S2CellId;
602
+ getCenterUV(): R2Vector;
603
+ toPoint(): S2Point;
604
+ /**
605
+ * Returns packed (si << 32 | ti) as a bigint.
606
+ * v4: return type changed from Long to bigint.
607
+ */
608
+ getCenterSiTi(): bigint;
609
+ static getSi(center: bigint): number;
610
+ static getTi(center: bigint): number;
611
+ toPointRaw(): S2Point;
612
+ toLatLng(): S2LatLng;
613
+ /** Return true if id() represents a valid cell. */
614
+ isValid(): boolean;
615
+ /**
616
+ * The position of the cell center along the Hilbert curve over this face,
617
+ * in the range 0..(2**kPosBits-1).
618
+ *
619
+ * v4: return type changed from Long to bigint.
620
+ */
621
+ pos(): bigint;
622
+ /** Return the subdivision level of the cell (range 0..MAX_LEVEL). */
623
+ level(): number;
624
+ getSizeIJ(): number;
625
+ static getSizeIJ(level: number): number;
626
+ getSizeST(): number;
627
+ static getSizeST(level: number): number;
628
+ isFace(): boolean;
629
+ childPosition(level: number): number;
630
+ rangeMin(): S2CellId;
631
+ rangeMax(): S2CellId;
632
+ contains(other: S2CellId): boolean;
633
+ intersects(other: S2CellId): boolean;
634
+ childBegin(): S2CellId;
635
+ childBeginL(level: number): S2CellId;
636
+ childEnd(): S2CellId;
637
+ childEndL(level: number): S2CellId;
638
+ private static childBeginAsBigInt;
639
+ private static childBeginAsBigIntL;
640
+ private static childEndAsBigInt;
641
+ private static childEndAsBigIntL;
642
+ private static fromFaceAsBigInt;
643
+ /** Return the next cell at the same level along the Hilbert curve. */
644
+ next(): S2CellId;
645
+ /** Return the previous cell at the same level along the Hilbert curve. */
646
+ prev(): S2CellId;
647
+ nextWrap(): S2CellId;
648
+ prevWrap(): S2CellId;
649
+ static begin(level: number): S2CellId;
650
+ static end(level: number): S2CellId;
651
+ /**
652
+ * Decodes a cell id from a compact hex token string.
653
+ * The maximum token length is 16 hex characters.
654
+ */
655
+ static fromToken(token: string): S2CellId;
656
+ /**
657
+ * Encodes the cell id to a compact hex token string.
658
+ * Cells at lower levels are encoded into fewer characters.
659
+ */
660
+ toToken(): string;
661
+ getEdgeNeighbors(): S2CellId[];
662
+ getVertexNeighbors(level: number): S2CellId[];
663
+ getAllNeighbors(nbrLevel: number): S2CellId[];
664
+ static fromFaceIJ(face: number, i: number, j: number): S2CellId;
665
+ private static getBits;
666
+ private static stToIJ;
667
+ private static fromFaceIJWrap;
668
+ static fromFaceIJSame(face: number, i: number, j: number, sameFace: boolean): S2CellId;
669
+ /** Returns true if x1 < x2 (unsigned comparison). */
670
+ static unsignedLongLessThan(x1: bigint, x2: bigint): boolean;
671
+ /** Returns true if x1 > x2 (unsigned comparison). */
672
+ static unsignedLongGreaterThan(x1: bigint, x2: bigint): boolean;
673
+ lessThan(x: S2CellId): boolean;
674
+ greaterThan(x: S2CellId): boolean;
675
+ lessOrEquals(x: S2CellId): boolean;
676
+ greaterOrEquals(x: S2CellId): boolean;
677
+ toString(): string;
678
+ compareTo(that: S2CellId): number;
679
+ equals(that: S2CellId): boolean;
680
+ /**
681
+ * Binary search in a sorted S2CellId array.
682
+ * Returns index if found, or -(insertionPoint+1) if not found.
683
+ *
684
+ * v4: `_id` accepts bigint, string, or S2CellId (was Long, string, or S2CellId).
685
+ */
686
+ static binarySearch(ids: S2CellId[], _id: bigint | string | S2CellId, low?: number): number;
687
+ static indexedBinarySearch(ids: S2CellId[], id: bigint | string | S2CellId, low?: number): number;
688
+ }
689
+
690
+ /**
691
+ * S1ChordAngle represents the angle subtended by a chord (i.e., the straight 3D Cartesian line
692
+ * segment connecting two points on the unit sphere). Its representation makes it very efficient for
693
+ * computing and comparing distances, but unlike S1Angle it is only capable of representing angles
694
+ * between 0 and Pi radians. Generally, S1ChordAngle should only be used in loops where many angles
695
+ * need to be calculated and compared. Otherwise it is simpler to use S1Angle.
696
+ *
697
+ * <p>S1ChordAngle also loses some accuracy as the angle approaches Pi radians. Specifically, the
698
+ * representation of (Pi - x) radians can be expected to have an error of about (1e-15 / x), with a
699
+ * maximum error of about 1e-7.
700
+ */
701
+
702
+ declare class S1ChordAngle {
703
+ /** Max value that can be returned from {@link #getLength2()}. */
704
+ static MAX_LENGTH2: number;
705
+ /** The zero chord angle. */
706
+ static ZERO: S1ChordAngle;
707
+ /** The chord angle of 90 degrees (a "right angle"). */
708
+ static RIGHT: S1ChordAngle;
709
+ /** The chord angle of 180 degrees (a "straight angle"). This is the max finite chord angle. */
710
+ static STRAIGHT: S1ChordAngle;
711
+ /**
712
+ * A chord angle larger than any finite chord angle. The only valid operations on {@code INFINITY}
713
+ * are comparisons and {@link S1Angle} conversions.
714
+ */
715
+ static INFINITY: S1ChordAngle;
716
+ /**
717
+ * A chord angle smaller than {@link #ZERO}. The only valid operations on {@code NEGATIVE} are
718
+ * comparisons and {@link S1Angle} conversions.
719
+ */
720
+ static NEGATIVE: S1ChordAngle;
721
+ private length2;
722
+ /**
723
+ * S1ChordAngles are represented by the squared chord length, which can range from 0 to {@code
724
+ * MAX_LENGTH2}. {@link #INFINITY} uses an infinite squared length.
725
+ */
726
+ constructor(length2: number);
727
+ /**
728
+ * Constructs the S1ChordAngle corresponding to the distance between the two given points. The
729
+ * points must be unit length.
730
+ */
731
+ static fromS2Point(x: S2Point, y: S2Point): S1ChordAngle;
732
+ /**
733
+ * Returns a new chord angle approximated from {@code angle} (see {@link
734
+ * #getS1AngleConstructorMaxError()} for the max magnitude of the error).
735
+ *
736
+ * <p>Angles outside the range [0, Pi] are handled as follows:
737
+ *
738
+ * <ul>
739
+ * <li>{@link S1Angle#INFINITY} is mapped to {@link #INFINITY}
740
+ * <li>negative angles are mapped to {@link #NEGATIVE}
741
+ * <li>finite angles larger than Pi are mapped to {@link #STRAIGHT}
742
+ * </ul>
743
+ *
744
+ * <p>Note that this operation is relatively expensive and should be avoided. To use {@link
745
+ * S1ChordAngle} effectively, you should structure your code so that input arguments are converted
746
+ * to S1ChordAngles at the beginning of your algorithm, and results are converted back to {@link
747
+ * S1Angle}s only at the end.
748
+ */
749
+ static fromS1Angle(angle: S1Angle): S1ChordAngle;
750
+ /**
751
+ * Construct an S1ChordAngle from the squared chord length. Note that the argument is
752
+ * automatically clamped to a maximum of {@code MAX_LENGTH2} to handle possible roundoff errors.
753
+ * The argument must be non-negative.
754
+ */
755
+ static fromLength2(length2: number): S1ChordAngle;
756
+ /** Returns whether the chord distance is exactly 0. */
757
+ isZero(): boolean;
758
+ /** Returns whether the chord distance is negative. */
759
+ isNegative(): boolean;
760
+ /** Returns whether the chord distance is exactly (positive) infinity. */
761
+ isInfinity(): boolean;
762
+ /** Returns true if the angle is negative or infinity. */
763
+ isSpecial(): boolean;
764
+ /**
765
+ * Returns true if getLength2() is within the normal range of 0 to 4 (inclusive) or the angle is
766
+ * special.
767
+ */
768
+ isValid(): boolean;
769
+ /**
770
+ * Convert the chord angle to an {@link S1Angle}. {@link #INFINITY} is converted to {@link
771
+ * S1Angle#INFINITY}, and {@link #NEGATIVE} is converted to a negative {@link S1Angle}. This
772
+ * operation is relatively expensive.
773
+ */
774
+ toAngle(): S1Angle;
775
+ /** The squared length of the chord. (Most clients will not need this.) */
776
+ getLength2(): number;
777
+ /**
778
+ * Returns the smallest representable S1ChordAngle larger than this object. This can be used to
779
+ * convert a "<" comparison to a "<=" comparison.
780
+ *
781
+ * <p>Note the following special cases:
782
+ *
783
+ * <ul>
784
+ * <li>NEGATIVE.successor() == ZERO
785
+ * <li>STRAIGHT.successor() == INFINITY
786
+ * <li>INFINITY.Successor() == INFINITY
787
+ * </ul>
788
+ */
789
+ /**
790
+ * As {@link #successor}, but returns the largest representable S1ChordAngle less than this
791
+ * object.
792
+ *
793
+ * <p>Note the following special cases:
794
+ *
795
+ * <ul>
796
+ * <li>INFINITY.predecessor() == STRAIGHT
797
+ * <li>ZERO.predecessor() == NEGATIVE
798
+ * <li>NEGATIVE.predecessor() == NEGATIVE
799
+ * </ul>
800
+ */
801
+ /**
802
+ * Returns a new S1ChordAngle whose chord distance represents the sum of the angular distances
803
+ * represented by the 'a' and 'b' chord angles.
804
+ *
805
+ * <p>Note that this method is much more efficient than converting the chord angles to S1Angles
806
+ * and adding those. It requires only one square root plus a few additions and multiplications.
807
+ */
808
+ static add(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle;
809
+ /**
810
+ * Subtract one S1ChordAngle from another.
811
+ *
812
+ * <p>Note that this method is much more efficient than converting the chord angles to S1Angles
813
+ * and adding those. It requires only one square root plus a few additions and multiplications.
814
+ */
815
+ static sub(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle;
816
+ /** Returns the smaller of the given instances. */
817
+ static min(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle;
818
+ /** Returns the larger of the given instances. */
819
+ static max(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle;
820
+ /** Returns the square of Math.sin(toAngle().radians()), but computed more efficiently. */
821
+ static sin2(a: S1ChordAngle): number;
822
+ /** Returns Math.sin(toAngle().radians()), but computed more efficiently. */
823
+ static sin(a: S1ChordAngle): number;
824
+ /** Returns Math.cos(toAngle().radians()), but computed more efficiently. */
825
+ static cos(a: S1ChordAngle): number;
826
+ /** Returns Math.tan(toAngle().radians()), but computed more efficiently. */
827
+ static tan(a: S1ChordAngle): number;
828
+ /**
829
+ * Returns a new S1ChordAngle that has been adjusted by the given error bound (which can be
830
+ * positive or negative). {@code error} should be the value returned by one of the error bound
831
+ * methods below. For example:
832
+ *
833
+ * <pre>
834
+ * {@code S1ChordAngle a = new S1ChordAngle(x, y);}
835
+ * {@code S1ChordAngle a1 = a.plusError(a.getS2PointConstructorMaxError());}
836
+ * </pre>
837
+ *
838
+ * <p>If this {@link #isSpecial}, we return {@code this}.
839
+ */
840
+ plusError(error: number): S1ChordAngle;
841
+ /** Returns the error in {@link #fromS1Angle}. */
842
+ getS1AngleConstructorMaxError(): number;
843
+ /**
844
+ * There is a relative error of {@code 2.5 * DBL_EPSILON} when computing the squared distance,
845
+ * plus a relative error of {@code 2 * DBL_EPSILON} and an absolute error of {@code 16 *
846
+ * DBL_EPSILON^2} because the lengths of the input points may differ from 1 by up to {@code 2 *
847
+ * DBL_EPSILON} each. (This is the maximum length error in {@link S2Point#normalize}).
848
+ */
849
+ getS2PointConstructorMaxError(): number;
850
+ /** Returns the string of the closest {@link S1Angle} to this chord distance. */
851
+ toString(): string;
852
+ compareTo(that: S1ChordAngle): number;
853
+ equals(that: S1ChordAngle): boolean;
854
+ }
855
+
856
+ /**
857
+ * This class represents a spherical cap, i.e. a portion of a sphere cut off by
858
+ * a plane. The cap is defined by its axis and height. This representation has
859
+ * good numerical accuracy for very small caps (unlike the (axis,
860
+ * min-distance-from-origin) representation), and is also efficient for
861
+ * containment tests (unlike the (axis, angle) representation).
862
+ *
863
+ * Here are some useful relationships between the cap height (h), the cap
864
+ * opening angle (theta), the maximum chord length from the cap's center (d),
865
+ * and the radius of cap's base (a). All formulas assume a unit radius.
866
+ *
867
+ * h = 1 - cos(theta) = 2 sin^2(theta/2) d^2 = 2 h = a^2 + h^2
868
+ *
869
+ */
870
+ declare class S2Cap implements S2Region {
871
+ /**
872
+ * Multiply a positive number by this constant to ensure that the result of a
873
+ * floating point operation is at least as large as the true
874
+ * infinite-precision result.
875
+ */
876
+ private static ROUND_UP;
877
+ axis: S2Point;
878
+ radius: S1ChordAngle;
879
+ /**
880
+ * Create a cap given its axis and the cap height, i.e. the maximum projected
881
+ * distance along the cap axis from the cap center. 'axis' should be a
882
+ * unit-length vector.
883
+ */
884
+ constructor(axis: S2Point, radius: S1ChordAngle);
885
+ static fromAxisChord(center: S2Point, radius: S1ChordAngle): S2Cap;
886
+ /**
887
+ * Create a cap given its axis and the cap height, i.e. the maximum projected distance along the
888
+ * cap axis from the cap center. 'axis' should be a unit-length vector.
889
+ */
890
+ static fromAxisHeight(axis: S2Point, height: number): S2Cap;
891
+ /**
892
+ * Create a cap given its axis and the cap opening angle, i.e. maximum angle
893
+ * between the axis and a point on the cap. 'axis' should be a unit-length
894
+ * vector, and 'angle' should be between 0 and 180 degrees.
895
+ */
896
+ static fromAxisAngle(axis: S2Point, angle: S1Angle): S2Cap;
897
+ /**
898
+ * Create a cap given its axis and its area in steradians. 'axis' should be a unit-length vector,
899
+ * and 'area' should be between 0 and 4 * M_PI.
900
+ */
901
+ static fromAxisArea(axis: S2Point, area: number): S2Cap;
902
+ /** Return an empty cap, i.e. a cap that contains no points. */
903
+ static empty(): S2Cap;
904
+ /** Return a full cap, i.e. a cap that contains all points. */
905
+ static full(): S2Cap;
906
+ getCapBound(): S2Cap;
907
+ height(): number;
908
+ area(): number;
909
+ /**
910
+ * Returns the cap radius as an S1Angle. Since the cap angle is stored internally as an
911
+ * S1ChordAngle, this method requires a trigonometric operation and may yield a slightly different
912
+ * result than the value passed to {@link #fromAxisAngle(S2Point, S1Angle)}.
913
+ */
914
+ angle(): S1Angle;
915
+ /**
916
+ * Returns true if the axis is {@link S2#isUnitLength unit length}, and the angle is less than Pi.
917
+ *
918
+ * <p>Negative angles or heights are valid, and represent empty caps.
919
+ */
920
+ isValid(): boolean;
921
+ /** Return true if the cap is empty, i.e. it contains no points. */
922
+ isEmpty(): boolean;
923
+ /** Return true if the cap is full, i.e. it contains all points. */
924
+ isFull(): boolean;
925
+ /**
926
+ * Return the complement of the interior of the cap. A cap and its complement have the same
927
+ * boundary but do not share any interior points. The complement operator is not a bijection,
928
+ * since the complement of a singleton cap (containing a single point) is the same as the
929
+ * complement of an empty cap.
930
+ */
931
+ complement(): S2Cap;
932
+ /**
933
+ * Return true if and only if this cap contains the given other cap (in a set
934
+ * containment sense, e.g. every cap contains the empty cap).
935
+ */
936
+ containsCap(other: S2Cap): boolean;
937
+ /**
938
+ * Return true if and only if the interior of this cap intersects the given other cap. (This
939
+ * relationship is not symmetric, since only the interior of this cap is used.)
940
+ */
941
+ interiorIntersects(other: S2Cap): boolean;
942
+ /**
943
+ * Return true if and only if the given point is contained in the interior of the region (i.e. the
944
+ * region excluding its boundary). 'p' should be a unit-length vector.
945
+ */
946
+ interiorContains(p: S2Point): boolean;
947
+ /**
948
+ * Increase the cap radius if necessary to include the given point. If the cap is empty the axis
949
+ * is set to the given point, but otherwise it is left unchanged.
950
+ *
951
+ * @param p must be {@link S2#isUnitLength unit length}
952
+ */
953
+ addPoint(p: S2Point): S2Cap;
954
+ addCap(other: S2Cap): S2Cap;
955
+ getRectBound(): S2LatLngRect;
956
+ mayIntersectC(cell: S2Cell): boolean;
957
+ /**
958
+ * Return true if the cap intersects 'cell', given that the cap vertices have
959
+ * alrady been checked.
960
+ */
961
+ intersects(cell: S2Cell, vertices: S2Point[]): boolean;
962
+ contains(p: S2Point): boolean;
963
+ containsC(cell: S2Cell): boolean;
964
+ /**
965
+ * Return true if the cap axis and height differ by at most "max_error" from
966
+ * the given cap "other".
967
+ */
968
+ approxEquals(other: S2Cap, maxError?: number): boolean;
969
+ toString(): string;
970
+ toGEOJSON(): {
971
+ type: string;
972
+ geometry: {
973
+ type: string;
974
+ coordinates: number[][][];
975
+ };
976
+ properties: {};
977
+ };
978
+ }
979
+
980
+ declare class S2Cell {
981
+ private cellID?;
982
+ private static MAX_CELL_SIZE;
983
+ private _face;
984
+ private _level;
985
+ private _orientation;
986
+ private uMin;
987
+ private uMax;
988
+ private vMin;
989
+ private vMax;
990
+ constructor(cellID?: S2CellId);
991
+ get id(): S2CellId;
992
+ static fromFace(face: number): S2Cell;
993
+ static fromFacePosLevel(face: number, pos: number, level: number): S2Cell;
994
+ static fromPoint(p: S2Point): S2Cell;
995
+ static fromLatLng(ll: S2LatLng): S2Cell;
996
+ isLeaf(): boolean;
997
+ getVertex(k: number): S2Point;
998
+ /**
999
+ * Return the k-th vertex of the cell (k = 0,1,2,3). Vertices are returned in
1000
+ * CCW order. The points returned by GetVertexRaw are not necessarily unit
1001
+ * length.
1002
+ */
1003
+ getVertexRaw(k: number): S2Point;
1004
+ getEdge(k: number): S2Point;
1005
+ getEdgeRaw(k: number): S2Point;
1006
+ /**
1007
+ * Return the inward-facing normal of the great circle passing through the
1008
+ * edge from vertex k to vertex k+1 (mod 4). The normals returned by
1009
+ * GetEdgeRaw are not necessarily unit length.
1010
+ *
1011
+ * If this is not a leaf cell, set children[0..3] to the four children of
1012
+ * this cell (in traversal order) and return true. Otherwise returns false.
1013
+ * This method is equivalent to the following:
1014
+ *
1015
+ * for (pos=0, id=child_begin(); id != child_end(); id = id.next(), ++pos)
1016
+ * children[i] = S2Cell(id);
1017
+ *
1018
+ * except that it is more than two times faster.
1019
+ */
1020
+ subdivide(): S2Cell[];
1021
+ /**
1022
+ * Return the direction vector corresponding to the center in (s,t)-space of
1023
+ * the given cell. This is the point at which the cell is divided into four
1024
+ * subcells; it is not necessarily the centroid of the cell in (u,v)-space or
1025
+ * (x,y,z)-space. The point returned by GetCenterRaw is not necessarily unit
1026
+ * length.
1027
+ */
1028
+ getCenter(): S2Point;
1029
+ getCenterRaw(): S2Point;
1030
+ /**
1031
+ * Return the center of the cell in (u,v) coordinates (see {@code
1032
+ * S2Projections}). Note that the center of the cell is defined as the point
1033
+ * at which it is recursively subdivided into four children; in general, it is
1034
+ * not at the midpoint of the (u,v) rectangle covered by the cell
1035
+ */
1036
+ getCenterUV(): R2Vector;
1037
+ /**
1038
+ * Return the average area of cells at this level. This is accurate to within
1039
+ * a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to
1040
+ * compute.
1041
+ */
1042
+ static averageArea(level: any): number;
1043
+ /**
1044
+ * Return the average area of cells at this level. This is accurate to within
1045
+ * a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to
1046
+ * compute.
1047
+ */
1048
+ averageArea(): number;
1049
+ /**
1050
+ * Return the approximate area of this cell. This method is accurate to within
1051
+ * 3% percent for all cell sizes and accurate to within 0.1% for cells at
1052
+ * level 5 or higher (i.e. 300km square or smaller). It is moderately cheap to
1053
+ * compute.
1054
+ */
1055
+ approxArea(): number;
1056
+ exactArea(): number;
1057
+ getCapBound(): S2Cap;
1058
+ private static MAX_ERROR;
1059
+ private static POLE_MIN_LAT;
1060
+ private getPoint;
1061
+ getRectBound(): S2LatLngRect;
1062
+ mayIntersectC(cell: S2Cell): boolean;
1063
+ contains(p: S2Point): boolean;
1064
+ containsC(cell: S2Cell): boolean;
1065
+ private init;
1066
+ get face(): number;
1067
+ get orientation(): number;
1068
+ get level(): number;
1069
+ toString(): string;
1070
+ toGEOJSON(): {
1071
+ type: string;
1072
+ geometry: {
1073
+ type: string;
1074
+ coordinates: number[][][];
1075
+ };
1076
+ properties: {};
1077
+ title: string;
1078
+ };
1079
+ }
1080
+
1081
+ declare class S2LatLngRect implements S2Region {
1082
+ lat: R1Interval;
1083
+ lng: S1Interval;
1084
+ constructor(lat: R1Interval, lng: S1Interval);
1085
+ static fromLatLng(lo: S2LatLng, hi: S2LatLng): S2LatLngRect;
1086
+ /** The canonical empty rectangle */
1087
+ static empty(): S2LatLngRect;
1088
+ /** The canonical full rectangle. */
1089
+ static full(): S2LatLngRect;
1090
+ /** The full allowable range of latitudes. */
1091
+ static fullLat(): R1Interval;
1092
+ /**
1093
+ * Construct a rectangle from a center point (in lat-lng space) and size in
1094
+ * each dimension. If size.lng is greater than 360 degrees it is clamped,
1095
+ * and latitudes greater than +/- 90 degrees are also clamped. So for example,
1096
+ * FromCenterSize((80,170),(20,20)) -> (lo=(60,150),hi=(90,-170)).
1097
+ */
1098
+ static fromCenterSize(center: S2LatLng, size: S2LatLng): S2LatLngRect;
1099
+ /** Convenience method to construct a rectangle containing a single point. */
1100
+ static fromPoint(p: S2LatLng): S2LatLngRect;
1101
+ /**
1102
+ * Convenience method to construct the minimal bounding rectangle containing
1103
+ * the two given points. This is equivalent to starting with an empty
1104
+ * rectangle and calling AddPoint() twice. Note that it is different than the
1105
+ * S2LatLngRect(lo, hi) constructor, where the first point is always used as
1106
+ * the lower-left corner of the resulting rectangle.
1107
+ */
1108
+ static fromPointPair(p1: S2LatLng, p2: S2LatLng): S2LatLngRect;
1109
+ /**
1110
+ * Return a latitude-longitude rectangle that contains the edge from "a" to
1111
+ * "b". Both points must be unit-length. Note that the bounding rectangle of
1112
+ * an edge can be larger than the bounding rectangle of its endpoints.
1113
+ */
1114
+ static fromEdge(a: S2Point, b: S2Point): S2LatLngRect;
1115
+ /**
1116
+ * Return true if the rectangle is valid, which essentially just means that
1117
+ * the latitude bounds do not exceed Pi/2 in absolute value and the longitude
1118
+ * bounds do not exceed Pi in absolute value.
1119
+ *
1120
+ */
1121
+ isValid(): boolean;
1122
+ lo(): S2LatLng;
1123
+ hi(): S2LatLng;
1124
+ latLo(): S1Angle;
1125
+ latHi(): S1Angle;
1126
+ lngLo(): S1Angle;
1127
+ lngHi(): S1Angle;
1128
+ /**
1129
+ * Return true if the rectangle is empty, i.e. it contains no points at all.
1130
+ */
1131
+ isEmpty(): boolean;
1132
+ isFull(): boolean;
1133
+ /**
1134
+ * Return true if lng_.lo() > lng_.hi(), i.e. the rectangle crosses the 180
1135
+ * degree latitude line.
1136
+ */
1137
+ isInverted(): boolean;
1138
+ /** Return the k-th vertex of the rectangle (k = 0,1,2,3) in CCW order. */
1139
+ getVertex(k: number): S2LatLng;
1140
+ /**
1141
+ * Return the center of the rectangle in latitude-longitude space (in general
1142
+ * this is not the center of the region on the sphere).
1143
+ */
1144
+ getCenter(): S2LatLng;
1145
+ /**
1146
+ * Return the minimum distance (measured along the surface of the sphere)
1147
+ * from a given point to the rectangle (both its boundary and its interior).
1148
+ * The latLng must be valid.
1149
+ */
1150
+ getDistanceLL(p: S2LatLng): S1Angle;
1151
+ /**
1152
+ * Return the minimum distance (measured along the surface of the sphere) to
1153
+ * the given S2LatLngRect. Both S2LatLngRects must be non-empty.
1154
+ */
1155
+ getDistanceLLR(other: S2LatLngRect): S1Angle;
1156
+ /**
1157
+ * Return the width and height of this rectangle in latitude-longitude space.
1158
+ * Empty rectangles have a negative width and height.
1159
+ */
1160
+ getSize(): S2LatLng;
1161
+ /**
1162
+ * More efficient version of Contains() that accepts a S2LatLng rather than an
1163
+ * S2Point.
1164
+ */
1165
+ containsLL(ll: S2LatLng): boolean;
1166
+ /**
1167
+ * Return true if and only if the given point is contained in the interior of
1168
+ * the region (i.e. the region excluding its boundary). The point 'p' does not
1169
+ * need to be normalized.
1170
+ */
1171
+ interiorContainsP(p: S2Point): boolean;
1172
+ /**
1173
+ * More efficient version of InteriorContains() that accepts a S2LatLng rather
1174
+ * than an S2Point.
1175
+ */
1176
+ interiorContainsLL(ll: S2LatLng): boolean;
1177
+ /**
1178
+ * Return true if and only if the rectangle contains the given other
1179
+ * rectangle.
1180
+ */
1181
+ containsLLR(other: S2LatLngRect): boolean;
1182
+ /**
1183
+ * Return true if and only if the interior of this rectangle contains all
1184
+ * points of the given other rectangle (including its boundary).
1185
+ */
1186
+ interiorContainsLLR(other: S2LatLngRect): boolean;
1187
+ /** Return true if this rectangle and the given other rectangle have any
1188
+ points in common. */
1189
+ intersectsLLR(other: S2LatLngRect): boolean;
1190
+ /**
1191
+ * Returns true if this rectangle intersects the given cell. (This is an exact
1192
+ * test and may be fairly expensive, see also MayIntersect below.)
1193
+ */
1194
+ intersects(cell: S2Cell): boolean;
1195
+ /**
1196
+ * Return true if and only if the interior of this rectangle intersects any
1197
+ * point (including the boundary) of the given other rectangle.
1198
+ */
1199
+ interiorIntersects(other: S2LatLngRect): boolean;
1200
+ addPoint(p: S2Point): S2LatLngRect;
1201
+ addPointLL(ll: S2LatLng): S2LatLngRect;
1202
+ /**
1203
+ * Return a rectangle that contains all points whose latitude distance from
1204
+ * this rectangle is at most margin.lat, and whose longitude distance from
1205
+ * this rectangle is at most margin.lng. In particular, latitudes are
1206
+ * clamped while longitudes are wrapped. Note that any expansion of an empty
1207
+ * interval remains empty, and both components of the given margin must be
1208
+ * non-negative.
1209
+ *
1210
+ * NOTE: If you are trying to grow a rectangle by a certain *distance* on the
1211
+ * sphere (e.g. 5km), use the ConvolveWithCap() method instead.
1212
+ */
1213
+ expanded(margin: S2LatLng): S2LatLngRect;
1214
+ polarClosure(): S2LatLngRect;
1215
+ /**
1216
+ * Return the smallest rectangle containing the union of this rectangle and
1217
+ * the given rectangle.
1218
+ */
1219
+ union(other: S2LatLngRect): S2LatLngRect;
1220
+ /**
1221
+ * Return the smallest rectangle containing the intersection of this rectangle
1222
+ * and the given rectangle. Note that the region of intersection may consist
1223
+ * of two disjoint rectangles, in which case a single rectangle spanning both
1224
+ * of them is returned.
1225
+ */
1226
+ intersection(other: S2LatLngRect): S2LatLngRect;
1227
+ /** Return the surface area of this rectangle on the unit sphere. */
1228
+ area(): number;
1229
+ /** Return true if two rectangles contains the same set of points. */
1230
+ equals(that: S2LatLngRect): boolean;
1231
+ /**
1232
+ * Return true if the latitude and longitude intervals of the two rectangles
1233
+ * are the same up to the given tolerance (see r1interval.h and s1interval.h
1234
+ * for details).
1235
+ */
1236
+ approxEquals(other: S2LatLngRect, maxError?: number): boolean;
1237
+ clone(): S2Region;
1238
+ getCapBound(): S2Cap;
1239
+ getRectBound(): S2LatLngRect;
1240
+ containsC(cell: S2Cell): boolean;
1241
+ /**
1242
+ * This test is cheap but is NOT exact. Use Intersects() if you want a more
1243
+ * accurate and more expensive test. Note that when this method is used by an
1244
+ * S2RegionCoverer, the accuracy isn't all that important since if a cell may
1245
+ * intersect the region then it is subdivided, and the accuracy of this method
1246
+ * goes up as the cells get smaller.
1247
+ */
1248
+ mayIntersectC(cell: S2Cell): boolean;
1249
+ /** The point 'p' does not need to be normalized. */
1250
+ containsP(p: S2Point): boolean;
1251
+ /**
1252
+ * Return true if the edge AB intersects the given edge of constant longitude.
1253
+ */
1254
+ private static intersectsLngEdge;
1255
+ /**
1256
+ * Return true if the edge AB intersects the given edge of constant latitude.
1257
+ */
1258
+ private static intersectsLatEdge;
1259
+ allVertex(): S2LatLng[];
1260
+ toGEOJSON(): {
1261
+ type: string;
1262
+ geometry: {
1263
+ type: string;
1264
+ coordinates: number[][][];
1265
+ };
1266
+ properties: {};
1267
+ };
1268
+ toString(): string;
1269
+ }
1270
+
1271
+ /**
1272
+ * An S2Region represents a two-dimensional region over the unit sphere. It is
1273
+ * an abstract interface with various concrete subtypes.
1274
+ *
1275
+ * The main purpose of this interface is to allow complex regions to be
1276
+ * approximated as simpler regions. So rather than having a wide variety of
1277
+ * virtual methods that are implemented by all subtypes, the interface is
1278
+ * restricted to methods that are useful for computing approximations.
1279
+ *
1280
+ *
1281
+ */
1282
+ interface S2Region {
1283
+ /** Return a bounding spherical cap. */
1284
+ getCapBound(): S2Cap;
1285
+ /** Return a bounding latitude-longitude rectangle. */
1286
+ getRectBound(): S2LatLngRect;
1287
+ /**
1288
+ * If this method returns true, the region completely contains the given cell.
1289
+ * Otherwise, either the region does not contain the cell or the containment
1290
+ * relationship could not be determined.
1291
+ */
1292
+ containsC(cell: S2Cell): boolean;
1293
+ /**
1294
+ * If this method returns false, the region does not intersect the given cell.
1295
+ * Otherwise, either region intersects the cell, or the intersection
1296
+ * relationship could not be determined.
1297
+ */
1298
+ mayIntersectC(cell: S2Cell): boolean;
1299
+ }
1300
+
1301
+ /**
1302
+ * Utility helpers for unsigned 64-bit bigint arithmetic.
1303
+ *
1304
+ * All values stored in S2CellId.id are guaranteed to be in [0, 2^64-1].
1305
+ * Use u64() to mask any operation that can produce an out-of-range value
1306
+ * (addition, subtraction, multiplication, shift-left, bitwise-not, negation).
1307
+ */
1308
+ /** Mask a bigint value to the unsigned 64-bit range [0, 2^64-1]. */
1309
+ declare function u64(n: bigint): bigint;
1310
+ /** Extract the lower 32 bits as an unsigned JS number [0, 2^32-1]. */
1311
+ declare function low32(n: bigint): number;
1312
+ /**
1313
+ * Extract the lower 32 bits as a signed JS number [-2^31, 2^31-1].
1314
+ * Equivalent to Java Long.getLowBits().
1315
+ */
1316
+ declare function low32s(n: bigint): number;
1317
+ /** Maximum value of a uint64: 2^64 - 1 */
1318
+ declare const UINT64_MAX = 18446744073709551615n;
1319
+
1320
+ /**
1321
+ * Transitional utilities for consumers migrating from nodes2-ts v3 (Long-based API)
1322
+ * to v4 (bigint-based API).
1323
+ *
1324
+ * These helpers make it easy to work with signed-decimal cell ID strings that
1325
+ * older code or Java S2 libraries produce (e.g. "-6533045114107854848") alongside
1326
+ * the new unsigned bigint representation.
1327
+ */
1328
+ /**
1329
+ * Convert a signed-decimal string (as produced by Java's Long.toString()) to an
1330
+ * unsigned 64-bit bigint.
1331
+ *
1332
+ * @example
1333
+ * signedDecimalToUnsigned('-6533045114107854848')
1334
+ * // => 11913698959601696768n
1335
+ */
1336
+ declare function signedDecimalToUnsigned(s: string): bigint;
1337
+ /**
1338
+ * Convert an unsigned 64-bit bigint back to a signed-decimal string, as Java's
1339
+ * Long.toString() would produce.
1340
+ *
1341
+ * @example
1342
+ * unsignedToSignedDecimal(11913698959601696768n)
1343
+ * // => '-6533045114107854848'
1344
+ */
1345
+ declare function unsignedToSignedDecimal(id: bigint): string;
1346
+ /**
1347
+ * Convenience: convert a signed-decimal S2 cell ID string (from Java) to its
1348
+ * token representation.
1349
+ *
1350
+ * @example
1351
+ * signedDecimalTokenMap('-6533045114107854848')
1352
+ * // => 'a555f6151'
1353
+ */
1354
+ declare function signedDecimalTokenMap(signedId: string): string;
1355
+
1356
+ /**
1357
+ * Defines an area or a length cell metric.
1358
+ */
1359
+ declare class S2Metric {
1360
+ private _dim;
1361
+ private _deriv;
1362
+ /**
1363
+ * Defines a cell metric of the given dimension (1 == length, 2 == area).
1364
+ */
1365
+ constructor(_dim: number, _deriv: number);
1366
+ deriv(): number;
1367
+ dim(): number;
1368
+ /** Return the value of a metric for cells at the given level. */
1369
+ getValue(level: number): number;
1370
+ /**
1371
+ * Return the level at which the metric has approximately the given value.
1372
+ * For example, S2::kAvgEdge.GetClosestLevel(0.1) returns the level at which
1373
+ * the average cell edge length is approximately 0.1. The return value is
1374
+ * always a valid level.
1375
+ */
1376
+ getClosestLevel(/*double*/ value: number): number;
1377
+ /**
1378
+ * Return the minimum level such that the metric is at most the given value,
1379
+ * or S2CellId::kMaxLevel if there is no such level. For example,
1380
+ * S2::kMaxDiag.GetMinLevel(0.1) returns the minimum level such that all
1381
+ * cell diagonal lengths are 0.1 or smaller. The return value is always a
1382
+ * valid level.
1383
+ */
1384
+ getMinLevel(value: number): number;
1385
+ /**
1386
+ * Return the maximum level such that the metric is at least the given
1387
+ * value, or zero if there is no such level. For example,
1388
+ * S2.kMinWidth.GetMaxLevel(0.1) returns the maximum level such that all
1389
+ * cells have a minimum width of 0.1 or larger. The return value is always a
1390
+ * valid level.
1391
+ */
1392
+ getMaxLevel(value: number): number;
1393
+ }
1394
+
1395
+ declare class S2 {
1396
+ static M_PI: number;
1397
+ static M_1_PI: number;
1398
+ static M_PI_2: number;
1399
+ static M_PI_4: number;
1400
+ static M_SQRT2: number;
1401
+ static M_E: number;
1402
+ static SWAP_MASK: number;
1403
+ static INVERT_MASK: number;
1404
+ /** Mapping from cell orientation + Hilbert traversal to IJ-index. */
1405
+ static POS_TO_ORIENTATION: number[];
1406
+ static DBL_EPSILON: number;
1407
+ static POS_TO_IJ: number[][];
1408
+ static MAX_LEVEL: number;
1409
+ static IEEEremainder(f1: number, f2: number): number;
1410
+ /**
1411
+ * Return true if the given point is approximately unit length (this is mainly
1412
+ * useful for assertions).
1413
+ */
1414
+ static isUnitLength(p: S2Point): boolean;
1415
+ /**
1416
+ * If v is non-zero, return an integer {@code exp} such that
1417
+ * {@code (0.5 <= |v|*2^(-exp) < 1)}. If v is zero, return 0.
1418
+ *
1419
+ * <p>Note that this arguably a bad definition of exponent because it makes
1420
+ * {@code exp(9) == 4}. In decimal this would be like saying that the
1421
+ * exponent of 1234 is 4, when in scientific 'exponent' notation 1234 is
1422
+ * {@code 1.234 x 10^3}.
1423
+ *
1424
+ * TODO(dbeaumont): Replace this with "DoubleUtils.getExponent(v) - 1" ?
1425
+ */
1426
+ static exp(v: number): number;
1427
+ /**
1428
+ * Return a vector "c" that is orthogonal to the given unit-length vectors "a"
1429
+ * and "b". This function is similar to a.CrossProd(b) except that it does a
1430
+ * better job of ensuring orthogonality when "a" is nearly parallel to "b",
1431
+ * and it returns a non-zero result even when a == b or a == -b.
1432
+ *
1433
+ * It satisfies the following properties (RCP == RobustCrossProd):
1434
+ *
1435
+ * (1) RCP(a,b) != 0 for all a, b (2) RCP(b,a) == -RCP(a,b) unless a == b or
1436
+ * a == -b (3) RCP(-a,b) == -RCP(a,b) unless a == b or a == -b (4) RCP(a,-b)
1437
+ * == -RCP(a,b) unless a == b or a == -b
1438
+ */
1439
+ static robustCrossProd(a: S2Point, b: S2Point): S2Point;
1440
+ /**
1441
+ * Return the area of triangle ABC. The method used is about twice as
1442
+ * expensive as Girard's formula, but it is numerically stable for both large
1443
+ * and very small triangles. The points do not need to be normalized. The area
1444
+ * is always positive.
1445
+ *
1446
+ * The triangle area is undefined if it contains two antipodal points, and
1447
+ * becomes numerically unstable as the length of any edge approaches 180
1448
+ * degrees.
1449
+ */
1450
+ static area(a: S2Point, b: S2Point, c: S2Point): number;
1451
+ /**
1452
+ * Return the area of the triangle computed using Girard's formula. This is
1453
+ * slightly faster than the Area() method above is not accurate for very small
1454
+ * triangles.
1455
+ */
1456
+ static girardArea(a: S2Point, b: S2Point, c: S2Point): number;
1457
+ /**
1458
+ * Return true if the points A, B, C are strictly counterclockwise. Return
1459
+ * false if the points are clockwise or colinear (i.e. if they are all
1460
+ * contained on some great circle).
1461
+ *
1462
+ * Due to numerical errors, situations may arise that are mathematically
1463
+ * impossible, e.g. ABC may be considered strictly CCW while BCA is not.
1464
+ * However, the implementation guarantees the following:
1465
+ *
1466
+ * If SimpleCCW(a,b,c), then !SimpleCCW(c,b,a) for all a,b,c.
1467
+ *
1468
+ * In other words, ABC and CBA are guaranteed not to be both CCW
1469
+ */
1470
+ static simpleCCW(a: S2Point, b: S2Point, c: S2Point): boolean;
1471
+ /**
1472
+ *
1473
+ * Return true if edge AB crosses CD at a point that is interior to both
1474
+ * edges. Properties:
1475
+ *
1476
+ * (1) SimpleCrossing(b,a,c,d) == SimpleCrossing(a,b,c,d) (2)
1477
+ * SimpleCrossing(c,d,a,b) == SimpleCrossing(a,b,c,d)
1478
+ */
1479
+ static simpleCrossing(a: S2Point, b: S2Point, c: S2Point, d: S2Point): boolean;
1480
+ static approxEqualsPointError(a: S2Point, b: S2Point, maxError: number): boolean;
1481
+ static approxEqualsPoint(a: S2Point, b: S2Point): boolean;
1482
+ static approxEqualsNumberError(a: number, b: number, maxError: number): boolean;
1483
+ static approxEqualsNumber(a: number, b: number): boolean;
1484
+ static Metric: typeof S2Metric;
1485
+ }
1486
+
1487
+ /**
1488
+ * An S2CellUnion is a region consisting of cells of various sizes.
1489
+ */
1490
+ declare class S2CellUnion implements S2Region {
1491
+ /** The CellIds that form the Union */
1492
+ private cellIds;
1493
+ /**
1494
+ * Populates a cell union with the given S2CellIds or 64-bit cell ids, and
1495
+ * then calls Normalize().
1496
+ *
1497
+ * v4: `cellIds` accepts `bigint[] | string[]` (was `Long[] | string[]`).
1498
+ */
1499
+ initFromIds(cellIds: bigint[] | string[]): void;
1500
+ initFromCellIds(cellIds: S2CellId[]): void;
1501
+ initSwap(cellIds: S2CellId[]): void;
1502
+ initRawCellIds(cellIds: S2CellId[]): void;
1503
+ initRawIds(cellIds: bigint[] | string[]): void;
1504
+ initRawSwap(cellIds: S2CellId[]): void;
1505
+ size(): number;
1506
+ cellId(i: number): S2CellId;
1507
+ getCellIds(): S2CellId[];
1508
+ denormalize(minLevel: number, levelMod: number): S2CellId[];
1509
+ pack(): void;
1510
+ containsC(cell: S2Cell): boolean;
1511
+ mayIntersectC(cell: S2Cell): boolean;
1512
+ contains(id: S2CellId): boolean;
1513
+ intersects(id: S2CellId): boolean;
1514
+ containsUnion(that: S2CellUnion): boolean;
1515
+ containsCell(cell: S2Cell): boolean;
1516
+ intersectsUnion(that: S2CellUnion): boolean;
1517
+ getUnion(x: S2CellUnion, y: S2CellUnion): void;
1518
+ getIntersection(x: S2CellUnion, id: S2CellId): void;
1519
+ getIntersectionUU(x: S2CellUnion, y: S2CellUnion): void;
1520
+ expand(level: number): void;
1521
+ expandA(minRadius: S1Angle, maxLevelDiff: number): void;
1522
+ getCapBound(): S2Cap;
1523
+ getRectBound(): S2LatLngRect;
1524
+ mayIntersectCell(cell: S2Cell): boolean;
1525
+ containsPoint(p: S2Point): boolean;
1526
+ /**
1527
+ * The number of leaf cells covered by the union.
1528
+ *
1529
+ * v4: return type changed from Long to bigint.
1530
+ */
1531
+ leafCellsCovered(): bigint;
1532
+ /**
1533
+ * Approximate area by summing the average area of each contained cell.
1534
+ *
1535
+ * v4: uses Number(bigint) instead of Long.toNumber().
1536
+ */
1537
+ averageBasedArea(): number;
1538
+ approxArea(): number;
1539
+ exactArea(): number;
1540
+ normalize(): boolean;
1541
+ }
1542
+
1543
+ /**
1544
+ * This class specifies the details of how the cube faces are projected onto the
1545
+ * unit sphere. This includes getting the face ordering and orientation correct
1546
+ * so that sequentially increasing cell ids follow a continuous space-filling
1547
+ * curve over the entire sphere, and defining the transformation from cell-space
1548
+ * to cube-space (see s2.h) in order to make the cells more uniform in size.
1549
+ *
1550
+ *
1551
+ * We have implemented three different projections from cell-space (s,t) to
1552
+ * cube-space (u,v): linear, quadratic, and tangent. They have the following
1553
+ * tradeoffs:
1554
+ *
1555
+ * Linear - This is the fastest transformation, but also produces the least
1556
+ * uniform cell sizes. Cell areas vary by a factor of about 5.2, with the
1557
+ * largest cells at the center of each face and the smallest cells in the
1558
+ * corners.
1559
+ *
1560
+ * Tangent - Transforming the coordinates via atan() makes the cell sizes more
1561
+ * uniform. The areas vary by a maximum ratio of 1.4 as opposed to a maximum
1562
+ * ratio of 5.2. However, each call to atan() is about as expensive as all of
1563
+ * the other calculations combined when converting from points to cell ids, i.e.
1564
+ * it reduces performance by a factor of 3.
1565
+ *
1566
+ * Quadratic - This is an approximation of the tangent projection that is much
1567
+ * faster and produces cells that are almost as uniform in size. It is about 3
1568
+ * times faster than the tangent projection for converting cell ids to points,
1569
+ * and 2 times faster for converting points to cell ids. Cell areas vary by a
1570
+ * maximum ratio of about 2.1.
1571
+ *
1572
+ * Here is a table comparing the cell uniformity using each projection. "Area
1573
+ * ratio" is the maximum ratio over all subdivision levels of the largest cell
1574
+ * area to the smallest cell area at that level, "edge ratio" is the maximum
1575
+ * ratio of the longest edge of any cell to the shortest edge of any cell at the
1576
+ * same level, and "diag ratio" is the ratio of the longest diagonal of any cell
1577
+ * to the shortest diagonal of any cell at the same level. "ToPoint" and
1578
+ * "FromPoint" are the times in microseconds required to convert cell ids to and
1579
+ * from points (unit vectors) respectively.
1580
+ *
1581
+ * Area Edge Diag ToPoint FromPoint Ratio Ratio Ratio (microseconds)
1582
+ * ------------------------------------------------------- Linear: 5.200 2.117
1583
+ * 2.959 0.103 0.123 Tangent: 1.414 1.414 1.704 0.290 0.306 Quadratic: 2.082
1584
+ * 1.802 1.932 0.116 0.161
1585
+ *
1586
+ * The worst-case cell aspect ratios are about the same with all three
1587
+ * projections. The maximum ratio of the longest edge to the shortest edge
1588
+ * within the same cell is about 1.4 and the maximum ratio of the diagonals
1589
+ * within the same cell is about 1.7.
1590
+ *
1591
+ * This data was produced using s2cell_unittest and s2cellid_unittest.
1592
+ *
1593
+ */
1594
+
1595
+ type UvTransformFunction = (x: number, y: number, z: number) => number;
1596
+ type XyzTransformFunction = (u: number, v: number) => number;
1597
+ type UvTransform = {
1598
+ xyzToU: UvTransformFunction;
1599
+ xyzToV: UvTransformFunction;
1600
+ };
1601
+ type XyzTransform = {
1602
+ uvToX: XyzTransformFunction;
1603
+ uvToY: XyzTransformFunction;
1604
+ uvToZ: XyzTransformFunction;
1605
+ };
1606
+ declare class S2Projections {
1607
+ static MIN_WIDTH: S2Metric;
1608
+ static AVG_AREA: S2Metric;
1609
+ static MAX_LEVEL: number;
1610
+ private static FACE_UVW_AXES;
1611
+ private static UV_TRANSFORMS;
1612
+ private static XYZ_TRANSFORMS;
1613
+ /**
1614
+ * The maximum value of an si- or ti-coordinate. The range of valid (si,ti) values is
1615
+ * [0..MAX_SiTi].
1616
+ */
1617
+ static MAX_SITI: bigint;
1618
+ static getUNorm(face: number, u: number): S2Point;
1619
+ static getVNorm(face: number, v: number): S2Point;
1620
+ static getUAxis(face: number): S2Point;
1621
+ static getVAxis(face: number): S2Point;
1622
+ static getNorm(face: number): S2Point;
1623
+ /** Returns the given axis of the given face (u=0, v=1, w=2). */
1624
+ static getUVWAxis(face: number, axis: number): S2Point;
1625
+ /**
1626
+ * Convert (face, si, ti) coordinates (see s2.h) to a direction vector (not
1627
+ * necessarily unit length).
1628
+ */
1629
+ static faceSiTiToXYZ(face: number, si: number, ti: number): S2Point;
1630
+ static faceUvToXyz(face: number, u: number, v: number): S2Point;
1631
+ static faceXyzToUv(face: number, p: S2Point): R2Vector;
1632
+ static validFaceXyzToUv(face: number, p: S2Point): R2Vector;
1633
+ static ijToStMin(i: number): number;
1634
+ static stToIj(s: number): number;
1635
+ static siTiToSt(si: number): number;
1636
+ static ijToUV(ij: number, cellSize: number): number;
1637
+ static xyzToFaceP(p: S2Point): number;
1638
+ static xyzToFace(x: number, y: number, z: number): number;
1639
+ static faceToUvTransform(face: number): UvTransform;
1640
+ static faceToXyzTransform(face: number): XyzTransform;
1641
+ }
1642
+
1643
+ /**
1644
+ * An S2RegionCoverer is a class that allows arbitrary regions to be
1645
+ * approximated as unions of cells (S2CellUnion). This is useful for
1646
+ * implementing various sorts of search and precomputation operations.
1647
+ *
1648
+ * Typical usage: {@code S2RegionCoverer coverer; coverer.setMaxCells(5); S2Cap
1649
+ * cap = S2Cap.fromAxisAngle(...); S2CellUnion covering;
1650
+ * coverer.getCovering(cap, covering); * }
1651
+ *
1652
+ * This yields a cell union of at most 5 cells that is guaranteed to cover the
1653
+ * given cap (a disc-shaped region on the sphere).
1654
+ *
1655
+ * The approximation algorithm is not optimal but does a pretty good job in
1656
+ * practice. The output does not always use the maximum number of cells allowed,
1657
+ * both because this would not always yield a better approximation, and because
1658
+ * max_cells() is a limit on how much work is done exploring the possible
1659
+ * covering as well as a limit on the final output size.
1660
+ *
1661
+ * One can also generate interior coverings, which are sets of cells which are
1662
+ * entirely contained within a region. Interior coverings can be empty, even for
1663
+ * non-empty regions, if there are no cells that satisfy the provided
1664
+ * constraints and are contained by the region. Note that for performance
1665
+ * reasons, it is wise to specify a max_level when computing interior coverings
1666
+ * - otherwise for regions with small or zero area, the algorithm may spend a
1667
+ * lot of time subdividing cells all the way to leaf level to try to find
1668
+ * contained cells.
1669
+ *
1670
+ * This class is thread-unsafe. Simultaneous calls to any of the getCovering
1671
+ * methods will conflict and produce unpredictable results.
1672
+ *
1673
+ */
1674
+ declare class S2RegionCoverer {
1675
+ /**
1676
+ * By default, the covering uses at most 8 cells at any level. This gives a
1677
+ * reasonable tradeoff between the number of cells used and the accuracy of
1678
+ * the approximation (see table below).
1679
+ */
1680
+ static DEFAULT_MAX_CELLS: number;
1681
+ private static FACE_CELLS;
1682
+ private minLevel;
1683
+ private maxLevel;
1684
+ private levelMod;
1685
+ private maxCells;
1686
+ private interiorCovering;
1687
+ private candidatesCreatedCounter;
1688
+ /**
1689
+ * We save a temporary copy of the pointer passed to GetCovering() in order to
1690
+ * avoid passing this parameter around internally. It is only used (and only
1691
+ * valid) for the duration of a single GetCovering() call.
1692
+ */
1693
+ protected region: S2Region;
1694
+ /**
1695
+ * A temporary variable used by GetCovering() that holds the cell ids that
1696
+ * have been added to the covering so far.
1697
+ */
1698
+ protected result: S2CellId[];
1699
+ /**
1700
+ * We keep the candidates in a priority queue. We specify a vector to hold the
1701
+ * queue entries since for some reason priority_queue<> uses a deque by
1702
+ * default.
1703
+ */
1704
+ private candidateQueue;
1705
+ /**
1706
+ * Default constructor, sets all fields to default values.
1707
+ */
1708
+ constructor();
1709
+ /**
1710
+ * Sets the minimum level to be used.
1711
+ */
1712
+ setMinLevel(minLevel: number): S2RegionCoverer;
1713
+ /**
1714
+ * Sets the maximum level to be used.
1715
+ */
1716
+ setMaxLevel(maxLevel: number): S2RegionCoverer;
1717
+ /**
1718
+ * If specified, then only cells where (level - min_level) is a multiple of
1719
+ * "level_mod" will be used (default 1). This effectively allows the branching
1720
+ * factor of the S2CellId hierarchy to be increased. Currently the only
1721
+ * parameter values allowed are 1, 2, or 3, corresponding to branching factors
1722
+ * of 4, 16, and 64 respectively.
1723
+ */
1724
+ setLevelMod(levelMod: number): S2RegionCoverer;
1725
+ /**
1726
+ * Sets the maximum desired number of cells in the approximation (defaults to
1727
+ * kDefaultMaxCells). Note the following:
1728
+ *
1729
+ * <ul>
1730
+ * <li>For any setting of max_cells(), up to 6 cells may be returned if that
1731
+ * is the minimum number of cells required (e.g. if the region intersects all
1732
+ * six face cells). Up to 3 cells may be returned even for very tiny convex
1733
+ * regions if they happen to be located at the intersection of three cube
1734
+ * faces.
1735
+ *
1736
+ * <li>For any setting of max_cells(), an arbitrary number of cells may be
1737
+ * returned if min_level() is too high for the region being approximated.
1738
+ *
1739
+ * <li>If max_cells() is less than 4, the area of the covering may be
1740
+ * arbitrarily large compared to the area of the original region even if the
1741
+ * region is convex (e.g. an S2Cap or S2LatLngRect).
1742
+ * </ul>
1743
+ *
1744
+ * Accuracy is measured by dividing the area of the covering by the area of
1745
+ * the original region. The following table shows the median and worst case
1746
+ * values for this area ratio on a test case consisting of 100,000 spherical
1747
+ * caps of random size (generated using s2regioncoverer_unittest):
1748
+ *
1749
+ * <pre>
1750
+ * max_cells: 3 4 5 6 8 12 20 100 1000
1751
+ * median ratio: 5.33 3.32 2.73 2.34 1.98 1.66 1.42 1.11 1.01
1752
+ * worst case: 215518 14.41 9.72 5.26 3.91 2.75 1.92 1.20 1.02
1753
+ * </pre>
1754
+ */
1755
+ setMaxCells(maxCells: number): S2RegionCoverer;
1756
+ getMinLevel(): number;
1757
+ getMaxLevel(): number;
1758
+ getMaxCells(): number;
1759
+ getLevelMod(): number;
1760
+ /**
1761
+ * Computes a list of cell ids that covers the given region and satisfies the
1762
+ * various restrictions specified above.
1763
+ *
1764
+ * @param region The region to cover
1765
+ * @param covering The list filled in by this method
1766
+ */
1767
+ getCoveringCells(region: S2Region): S2CellId[];
1768
+ /**
1769
+ * Computes a list of cell ids that is contained within the given region and
1770
+ * satisfies the various restrictions specified above.
1771
+ *
1772
+ * @param region The region to fill
1773
+ * @param interior The list filled in by this method
1774
+ */
1775
+ getInteriorCoveringCells(region: S2Region): S2CellId[];
1776
+ /**
1777
+ * Return a normalized cell union that covers the given region and satisfies
1778
+ * the restrictions *EXCEPT* for min_level() and level_mod(). These criteria
1779
+ * cannot be satisfied using a cell union because cell unions are
1780
+ * automatically normalized by replacing four child cells with their parent
1781
+ * whenever possible. (Note that the list of cell ids passed to the cell union
1782
+ * constructor does in fact satisfy all the given restrictions.)
1783
+ */
1784
+ getCoveringUnion(region: S2Region, covering?: S2CellUnion): S2CellUnion;
1785
+ /**
1786
+ * Return a normalized cell union that is contained within the given region
1787
+ * and satisfies the restrictions *EXCEPT* for min_level() and level_mod().
1788
+ */
1789
+ getInteriorCoveringUnion(region: S2Region, covering?: S2CellUnion): S2CellUnion;
1790
+ /**
1791
+ * Given a connected region and a starting point, return a set of cells at the given level that
1792
+ * cover the region.
1793
+ */
1794
+ static getSimpleCovering(region: S2Region, start: S2Point, level: number): S2CellId[];
1795
+ /**
1796
+ * If the cell intersects the given region, return a new candidate with no
1797
+ * children, otherwise return null. Also marks the candidate as "terminal" if
1798
+ * it should not be expanded further.
1799
+ */
1800
+ private newCandidate;
1801
+ /** Return the log base 2 of the maximum number of children of a candidate. */
1802
+ private maxChildrenShift;
1803
+ /**
1804
+ * Process a candidate by either adding it to the result list or expanding its
1805
+ * children and inserting it into the priority queue. Passing an argument of
1806
+ * NULL does nothing.
1807
+ */
1808
+ private addCandidate;
1809
+ /**
1810
+ * Populate the children of "candidate" by expanding the given number of
1811
+ * levels from the given cell. Returns the number of children that were marked
1812
+ * "terminal".
1813
+ */
1814
+ private expandChildren;
1815
+ /** Computes a set of initial candidates that cover the given region. */
1816
+ private getInitialCandidates;
1817
+ /** Generates a covering and stores it in result. */
1818
+ private getCoveringInternal;
1819
+ /**
1820
+ * Given a region and a starting cell, return the set of all the edge-connected cells at the same
1821
+ * level that intersect "region". The output cells are returned in arbitrary order.
1822
+ */
1823
+ private static floodFill;
1824
+ }
1825
+
1826
+ declare class Utils {
21
1827
  /**
22
1828
  * Calculates a region covering a circle
23
1829
  * NOTE: The current implementation uses S2Cap while S2Loop would be better (S2Loop is not implemented yet)
@@ -28,3 +1834,5 @@ export declare class Utils {
28
1834
  */
29
1835
  static calcRegionFromCenterRadius(center: S2LatLng, radiusInKM: number, points?: number): S2Region;
30
1836
  }
1837
+
1838
+ export { Interval, MutableInteger, R1Interval, R2Vector, S1Angle, S1Interval, S2, S2Cap, S2Cell, S2CellId, S2CellUnion, S2LatLng, S2LatLngRect, S2Metric, S2Point, S2Projections, type S2Region, S2RegionCoverer, UINT64_MAX, Utils, type UvTransform, type UvTransformFunction, type XyzTransform, type XyzTransformFunction, low32, low32s, signedDecimalToUnsigned, signedDecimalTokenMap, u64, unsignedToSignedDecimal };