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