nodes2ts 1.1.9 → 3.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.
- package/.eslintignore +3 -0
- package/.eslintrc.cjs +11 -0
- package/.github/workflows/lint.js.yml +22 -0
- package/.github/workflows/node.js.yml +22 -0
- package/.mocharc.js +7 -0
- package/README.md +22 -5
- package/dist/Interval.d.ts +7 -8
- package/dist/Interval.js +12 -12
- package/dist/Interval.js.map +1 -1
- package/dist/MutableInteger.js +5 -4
- package/dist/MutableInteger.js.map +1 -1
- package/dist/Platform.d.ts +15 -0
- package/dist/Platform.js +53 -0
- package/dist/Platform.js.map +1 -0
- package/dist/R1Interval.d.ts +8 -9
- package/dist/R1Interval.js +59 -78
- package/dist/R1Interval.js.map +1 -1
- package/dist/R2Vector.d.ts +12 -13
- package/dist/R2Vector.js +65 -85
- package/dist/R2Vector.js.map +1 -1
- package/dist/S1Angle.d.ts +38 -5
- package/dist/S1Angle.js +89 -37
- package/dist/S1Angle.js.map +1 -1
- package/dist/S1ChordAngle.d.ts +166 -0
- package/dist/S1ChordAngle.js +318 -0
- package/dist/S1ChordAngle.js.map +1 -0
- package/dist/S1Interval.d.ts +11 -12
- package/dist/S1Interval.js +134 -140
- package/dist/S1Interval.js.map +1 -1
- package/dist/S2.d.ts +8 -5
- package/dist/S2.js +91 -108
- package/dist/S2.js.map +1 -1
- package/dist/S2Cap.d.ts +33 -25
- package/dist/S2Cap.js +199 -203
- package/dist/S2Cap.js.map +1 -1
- package/dist/S2Cell.d.ts +15 -13
- package/dist/S2Cell.js +196 -206
- package/dist/S2Cell.js.map +1 -1
- package/dist/S2CellId.d.ts +37 -14
- package/dist/S2CellId.js +407 -359
- package/dist/S2CellId.js.map +1 -1
- package/dist/S2CellUnion.d.ts +1 -2
- package/dist/S2CellUnion.js +137 -133
- package/dist/S2CellUnion.js.map +1 -1
- package/dist/S2EdgeUtil.js +14 -17
- package/dist/S2EdgeUtil.js.map +1 -1
- package/dist/S2LatLng.d.ts +15 -11
- package/dist/S2LatLng.js +100 -114
- package/dist/S2LatLng.js.map +1 -1
- package/dist/S2LatLngRect.d.ts +8 -4
- package/dist/S2LatLngRect.js +215 -197
- package/dist/S2LatLngRect.js.map +1 -1
- package/dist/S2Metric.d.ts +4 -5
- package/dist/S2Metric.js +30 -27
- package/dist/S2Metric.js.map +1 -1
- package/dist/S2Point.d.ts +48 -14
- package/dist/S2Point.js +156 -109
- package/dist/S2Point.js.map +1 -1
- package/dist/S2Projections.d.ts +43 -9
- package/dist/S2Projections.js +226 -47
- package/dist/S2Projections.js.map +1 -1
- package/dist/S2Region.js +2 -1
- package/dist/S2Region.js.map +1 -1
- package/dist/S2RegionCoverer.d.ts +21 -6
- package/dist/S2RegionCoverer.js +144 -109
- package/dist/S2RegionCoverer.js.map +1 -1
- package/dist/export.d.ts +0 -1
- package/dist/export.js +42 -32
- package/dist/export.js.map +1 -1
- package/dist/utils/preconditions.d.ts +2 -0
- package/dist/utils/preconditions.js +16 -0
- package/dist/utils/preconditions.js.map +1 -0
- package/package.json +28 -34
- package/.npmignore +0 -8
- package/.nyc_output/1eb1f420a13c15f529aac41a40bcaa21.json +0 -1
- package/.nyc_output/5ff62256eb1c111254ba0b469fb547da.json +0 -1
- package/.nyc_output/949d6e8c2061067f3bdfd27dfff5ba83.json +0 -1
- package/coverage/Interval.ts.html +0 -203
- package/coverage/MutableInteger.ts.html +0 -77
- package/coverage/R1Interval.ts.html +0 -647
- package/coverage/R2Vector.ts.html +0 -587
- package/coverage/S1Angle.ts.html +0 -344
- package/coverage/S1Interval.ts.html +0 -1349
- package/coverage/S2.ts.html +0 -1178
- package/coverage/S2Cap.ts.html +0 -1433
- package/coverage/S2Cell.ts.html +0 -1415
- package/coverage/S2CellId.ts.html +0 -3329
- package/coverage/S2EdgeUtil.ts.html +0 -2534
- package/coverage/S2LatLng.ts.html +0 -848
- package/coverage/S2LatLngRect.ts.html +0 -2222
- package/coverage/S2Point.ts.html +0 -758
- package/coverage/S2Projections.ts.html +0 -518
- package/coverage/base.css +0 -212
- package/coverage/decimal.ts.html +0 -68
- package/coverage/index.html +0 -288
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -1
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -158
- package/dist/decimal.d.ts +0 -3
- package/dist/decimal.js +0 -4
- package/dist/decimal.js.map +0 -1
- package/dist/decimal_augmentation.d.ts +0 -24
- package/dist/decimal_augmentation.js +0 -2
- package/dist/decimal_augmentation.js.map +0 -1
package/dist/S2Cell.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="decimal.js" />
|
|
2
1
|
import { S2CellId } from "./S2CellId";
|
|
3
2
|
import { S2Point } from "./S2Point";
|
|
4
3
|
import { S2LatLng } from "./S2LatLng";
|
|
@@ -6,17 +5,18 @@ import { R2Vector } from "./R2Vector";
|
|
|
6
5
|
import { S2LatLngRect } from "./S2LatLngRect";
|
|
7
6
|
import { S2Cap } from "./S2Cap";
|
|
8
7
|
export declare class S2Cell {
|
|
9
|
-
private cellID
|
|
8
|
+
private cellID?;
|
|
10
9
|
private static MAX_CELL_SIZE;
|
|
11
10
|
private _face;
|
|
12
11
|
private _level;
|
|
13
12
|
private _orientation;
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
private uMin;
|
|
14
|
+
private uMax;
|
|
15
|
+
private vMin;
|
|
16
|
+
private vMax;
|
|
17
|
+
constructor(cellID?: S2CellId);
|
|
18
|
+
get id(): S2CellId;
|
|
19
|
+
static fromFace(face: number): S2Cell;
|
|
20
20
|
static fromFacePosLevel(face: number, pos: number, level: number): S2Cell;
|
|
21
21
|
static fromPoint(p: S2Point): S2Cell;
|
|
22
22
|
static fromLatLng(ll: S2LatLng): S2Cell;
|
|
@@ -80,17 +80,19 @@ export declare class S2Cell {
|
|
|
80
80
|
* compute.
|
|
81
81
|
*/
|
|
82
82
|
approxArea(): number;
|
|
83
|
-
exactArea():
|
|
83
|
+
exactArea(): number;
|
|
84
84
|
getCapBound(): S2Cap;
|
|
85
85
|
private static MAX_ERROR;
|
|
86
86
|
private static POLE_MIN_LAT;
|
|
87
|
+
private getPoint;
|
|
87
88
|
getRectBound(): S2LatLngRect;
|
|
88
|
-
|
|
89
|
+
mayIntersectC(cell: S2Cell): boolean;
|
|
89
90
|
contains(p: S2Point): boolean;
|
|
90
91
|
containsC(cell: S2Cell): boolean;
|
|
91
|
-
private init
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
private init;
|
|
93
|
+
get face(): number;
|
|
94
|
+
get orientation(): number;
|
|
95
|
+
get level(): number;
|
|
94
96
|
toString(): string;
|
|
95
97
|
toGEOJSON(): {
|
|
96
98
|
type: string;
|
package/dist/S2Cell.js
CHANGED
|
@@ -1,96 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function S2Cell(cellID) {
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.S2Cell = void 0;
|
|
4
|
+
const Long = require("long");
|
|
5
|
+
const S2CellId_1 = require("./S2CellId");
|
|
6
|
+
const S2Point_1 = require("./S2Point");
|
|
7
|
+
const S2LatLng_1 = require("./S2LatLng");
|
|
8
|
+
const S2Projections_1 = require("./S2Projections");
|
|
9
|
+
const S2_1 = require("./S2");
|
|
10
|
+
const S2LatLngRect_1 = require("./S2LatLngRect");
|
|
11
|
+
const R1Interval_1 = require("./R1Interval");
|
|
12
|
+
const S1Interval_1 = require("./S1Interval");
|
|
13
|
+
const S2Cap_1 = require("./S2Cap");
|
|
14
|
+
class S2Cell {
|
|
15
|
+
constructor(cellID) {
|
|
17
16
|
this.cellID = cellID;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (cellID != null) {
|
|
18
|
+
this.init(cellID);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get id() {
|
|
22
|
+
return this.cellID;
|
|
23
|
+
}
|
|
24
|
+
static fromFace(face) {
|
|
25
|
+
return new S2Cell(S2CellId_1.S2CellId.fromFace(face));
|
|
22
26
|
}
|
|
23
|
-
Object.defineProperty(S2Cell.prototype, "id", {
|
|
24
|
-
get: function () {
|
|
25
|
-
return this.cellID;
|
|
26
|
-
},
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(S2Cell.prototype, "face", {
|
|
31
|
-
get: function () {
|
|
32
|
-
return this._face;
|
|
33
|
-
},
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(S2Cell.prototype, "level", {
|
|
38
|
-
get: function () {
|
|
39
|
-
return this._level;
|
|
40
|
-
},
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(S2Cell.prototype, "orientation", {
|
|
45
|
-
get: function () {
|
|
46
|
-
return this._orientation;
|
|
47
|
-
},
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true
|
|
50
|
-
});
|
|
51
27
|
// This is a static method in order to provide named parameters.
|
|
52
|
-
|
|
28
|
+
static fromFacePosLevel(face, pos, level) {
|
|
53
29
|
return new S2Cell(S2CellId_1.S2CellId.fromFacePosLevel(face, new Long(pos), level));
|
|
54
|
-
}
|
|
30
|
+
}
|
|
55
31
|
// Convenience methods.
|
|
56
|
-
|
|
32
|
+
static fromPoint(p) {
|
|
57
33
|
return new S2Cell(S2CellId_1.S2CellId.fromPoint(p));
|
|
58
|
-
}
|
|
59
|
-
|
|
34
|
+
}
|
|
35
|
+
static fromLatLng(ll) {
|
|
60
36
|
return new S2Cell(S2CellId_1.S2CellId.fromPoint(ll.toPoint()));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return this.
|
|
64
|
-
}
|
|
65
|
-
|
|
37
|
+
}
|
|
38
|
+
isLeaf() {
|
|
39
|
+
return this._level == S2CellId_1.S2CellId.MAX_LEVEL;
|
|
40
|
+
}
|
|
41
|
+
getVertex(k) {
|
|
66
42
|
return S2Point_1.S2Point.normalize(this.getVertexRaw(k));
|
|
67
|
-
}
|
|
43
|
+
}
|
|
68
44
|
/**
|
|
69
45
|
* Return the k-th vertex of the cell (k = 0,1,2,3). Vertices are returned in
|
|
70
46
|
* CCW order. The points returned by GetVertexRaw are not necessarily unit
|
|
71
47
|
* length.
|
|
72
48
|
*/
|
|
73
|
-
|
|
49
|
+
getVertexRaw(k) {
|
|
74
50
|
// Vertices are returned in the order SW, SE, NE, NW.
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
S2Cell.prototype.getEdge = function (k) {
|
|
51
|
+
return S2Projections_1.S2Projections.faceUvToXyz(this._face, ((k >> 1) ^ (k & 1)) == 0 ? this.uMin : this.uMax, (k >> 1) == 0 ? this.vMin : this.vMax);
|
|
52
|
+
}
|
|
53
|
+
getEdge(k) {
|
|
80
54
|
return S2Point_1.S2Point.normalize(this.getEdgeRaw(k));
|
|
81
|
-
}
|
|
82
|
-
|
|
55
|
+
}
|
|
56
|
+
getEdgeRaw(k) {
|
|
83
57
|
switch (k) {
|
|
84
58
|
case 0:
|
|
85
|
-
return S2Projections_1.S2Projections.getVNorm(this.
|
|
59
|
+
return S2Projections_1.S2Projections.getVNorm(this._face, this.vMin); // South
|
|
86
60
|
case 1:
|
|
87
|
-
return S2Projections_1.S2Projections.getUNorm(this.
|
|
61
|
+
return S2Projections_1.S2Projections.getUNorm(this._face, this.uMax); // East
|
|
88
62
|
case 2:
|
|
89
|
-
return S2Point_1.S2Point.neg(S2Projections_1.S2Projections.getVNorm(this.
|
|
63
|
+
return S2Point_1.S2Point.neg(S2Projections_1.S2Projections.getVNorm(this._face, this.vMax)); // North
|
|
90
64
|
default:
|
|
91
|
-
return S2Point_1.S2Point.neg(S2Projections_1.S2Projections.getUNorm(this.
|
|
65
|
+
return S2Point_1.S2Point.neg(S2Projections_1.S2Projections.getUNorm(this._face, this.uMin)); // West
|
|
92
66
|
}
|
|
93
|
-
}
|
|
67
|
+
}
|
|
94
68
|
/**
|
|
95
69
|
* Return the inward-facing normal of the great circle passing through the
|
|
96
70
|
* edge from vertex k to vertex k+1 (mod 4). The normals returned by
|
|
@@ -105,22 +79,52 @@ var S2Cell = (function () {
|
|
|
105
79
|
*
|
|
106
80
|
* except that it is more than two times faster.
|
|
107
81
|
*/
|
|
108
|
-
|
|
82
|
+
subdivide() {
|
|
109
83
|
// This function is equivalent to just iterating over the child cell ids
|
|
110
84
|
// and calling the S2Cell constructor, but it is about 2.5 times faster.
|
|
111
|
-
if (this.isLeaf()) {
|
|
85
|
+
if (this.id.isLeaf()) {
|
|
112
86
|
return null;
|
|
113
87
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
88
|
+
const children = new Array(4);
|
|
89
|
+
for (let i = 0; i < 4; ++i) {
|
|
90
|
+
children[i] = new S2Cell();
|
|
91
|
+
}
|
|
117
92
|
// Create four children with the appropriate bounds.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
93
|
+
let id = this.id.childBegin();
|
|
94
|
+
const mid = this.getCenterUV();
|
|
95
|
+
const uMid = mid.x;
|
|
96
|
+
const vMid = mid.y;
|
|
97
|
+
for (let pos = 0; pos < 4; ++pos, id = id.next()) {
|
|
98
|
+
const child = children[pos];
|
|
99
|
+
child._face = this.face;
|
|
100
|
+
child._level = this.level + 1;
|
|
101
|
+
child._orientation = this.orientation ^ S2_1.S2.POS_TO_ORIENTATION[pos];
|
|
102
|
+
child.cellID = id;
|
|
103
|
+
// We want to split the cell in half in "u" and "v". To decide which
|
|
104
|
+
// side to set equal to the midpoint value, we look at cell's (i,j)
|
|
105
|
+
// position within its parent. The index for "i" is in bit 1 of ij.
|
|
106
|
+
const ij = S2_1.S2.POS_TO_IJ[this.orientation][pos];
|
|
107
|
+
// The dimension 0 index (i/u) is in bit 1 of ij.
|
|
108
|
+
if ((ij & 0x2) != 0) {
|
|
109
|
+
child.uMin = uMid;
|
|
110
|
+
child.uMax = this.uMax;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
child.uMin = this.uMin;
|
|
114
|
+
child.uMax = uMid;
|
|
115
|
+
}
|
|
116
|
+
// The dimension 1 index (j/v) is in bit 0 of ij.
|
|
117
|
+
if ((ij & 0x1) != 0) {
|
|
118
|
+
child.vMin = vMid;
|
|
119
|
+
child.vMax = this.vMax;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
child.vMin = this.vMin;
|
|
123
|
+
child.vMax = vMid;
|
|
124
|
+
}
|
|
121
125
|
}
|
|
122
126
|
return children;
|
|
123
|
-
}
|
|
127
|
+
}
|
|
124
128
|
/**
|
|
125
129
|
* Return the direction vector corresponding to the center in (s,t)-space of
|
|
126
130
|
* the given cell. This is the point at which the cell is divided into four
|
|
@@ -128,63 +132,52 @@ var S2Cell = (function () {
|
|
|
128
132
|
* (x,y,z)-space. The point returned by GetCenterRaw is not necessarily unit
|
|
129
133
|
* length.
|
|
130
134
|
*/
|
|
131
|
-
|
|
135
|
+
getCenter() {
|
|
132
136
|
return S2Point_1.S2Point.normalize(this.getCenterRaw());
|
|
133
|
-
}
|
|
134
|
-
|
|
137
|
+
}
|
|
138
|
+
getCenterRaw() {
|
|
135
139
|
return this.cellID.toPointRaw();
|
|
136
|
-
}
|
|
140
|
+
}
|
|
137
141
|
/**
|
|
138
142
|
* Return the center of the cell in (u,v) coordinates (see {@code
|
|
139
143
|
* S2Projections}). Note that the center of the cell is defined as the point
|
|
140
144
|
* at which it is recursively subdivided into four children; in general, it is
|
|
141
145
|
* not at the midpoint of the (u,v) rectangle covered by the cell
|
|
142
146
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.cellID.toFaceIJOrientation(i, j, null);
|
|
147
|
-
var cellSize = 1 << (S2CellId_1.S2CellId.MAX_LEVEL - this.level);
|
|
148
|
-
// TODO(dbeaumont): Figure out a better naming of the variables here (and elsewhere).
|
|
149
|
-
var si = (i.val & -cellSize) * 2 + cellSize - S2Cell.MAX_CELL_SIZE;
|
|
150
|
-
var x = R2Vector_1.R2Vector.singleStTOUV(S2_1.S2.toDecimal(1).dividedBy(S2Cell.MAX_CELL_SIZE).times(si));
|
|
151
|
-
// let x = S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * si);
|
|
152
|
-
var sj = (j.val & -cellSize) * 2 + cellSize - S2Cell.MAX_CELL_SIZE;
|
|
153
|
-
var y = R2Vector_1.R2Vector.singleStTOUV(S2_1.S2.toDecimal(1).dividedBy(S2Cell.MAX_CELL_SIZE).times(sj));
|
|
154
|
-
// double y = S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sj);
|
|
155
|
-
return new R2Vector_1.R2Vector(x, y);
|
|
156
|
-
};
|
|
147
|
+
getCenterUV() {
|
|
148
|
+
return this.cellID.getCenterUV();
|
|
149
|
+
}
|
|
157
150
|
/**
|
|
158
151
|
* Return the average area of cells at this level. This is accurate to within
|
|
159
152
|
* a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to
|
|
160
153
|
* compute.
|
|
161
154
|
*/
|
|
162
|
-
|
|
155
|
+
static averageArea(level) {
|
|
163
156
|
return S2Projections_1.S2Projections.AVG_AREA.getValue(level);
|
|
164
|
-
}
|
|
157
|
+
}
|
|
165
158
|
/**
|
|
166
159
|
* Return the average area of cells at this level. This is accurate to within
|
|
167
160
|
* a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to
|
|
168
161
|
* compute.
|
|
169
162
|
*/
|
|
170
|
-
|
|
171
|
-
return S2Projections_1.S2Projections.AVG_AREA.getValue(this.
|
|
172
|
-
}
|
|
163
|
+
averageArea() {
|
|
164
|
+
return S2Projections_1.S2Projections.AVG_AREA.getValue(this._level);
|
|
165
|
+
}
|
|
173
166
|
/**
|
|
174
167
|
* Return the approximate area of this cell. This method is accurate to within
|
|
175
168
|
* 3% percent for all cell sizes and accurate to within 0.1% for cells at
|
|
176
169
|
* level 5 or higher (i.e. 300km square or smaller). It is moderately cheap to
|
|
177
170
|
* compute.
|
|
178
171
|
*/
|
|
179
|
-
|
|
172
|
+
approxArea() {
|
|
180
173
|
// All cells at the first two levels have the same area.
|
|
181
|
-
if (this.
|
|
174
|
+
if (this._level < 2) {
|
|
182
175
|
return this.averageArea();
|
|
183
176
|
}
|
|
184
177
|
// First, compute the approximate area of the cell when projected
|
|
185
178
|
// perpendicular to its normal. The cross product of its diagonals gives
|
|
186
179
|
// the normal, and the length of the normal is twice the projected area.
|
|
187
|
-
|
|
180
|
+
const flatArea = S2Point_1.S2Point.crossProd(S2Point_1.S2Point.sub(this.getVertex(2), this.getVertex(0)), S2Point_1.S2Point.sub(this.getVertex(3), this.getVertex(1))).norm() * 0.5;
|
|
188
181
|
// double flatArea = 0.5 * S2Point.crossProd(
|
|
189
182
|
// S2Point.sub(getVertex(2), getVertex(0)), S2Point.sub(getVertex(3), getVertex(1))).norm();
|
|
190
183
|
// Now, compensate for the curvature of the cell surface by pretending
|
|
@@ -193,30 +186,24 @@ var S2Cell = (function () {
|
|
|
193
186
|
// to be 2 / (1 + sqrt(1 - r*r)) where "r" is the radius of the disc.
|
|
194
187
|
// For example, when r=0 the ratio is 1, and when r=1 the ratio is 2.
|
|
195
188
|
// Here we set Pi*r*r == flat_area to find the equivalent disc.
|
|
196
|
-
return flatArea
|
|
197
|
-
|
|
198
|
-
.dividedBy(decimal_1.Decimal.min(flatArea.times(S2_1.S2.M_1_PI), 1)
|
|
199
|
-
.neg()
|
|
200
|
-
.plus(1)
|
|
201
|
-
.sqrt()
|
|
202
|
-
.plus(1)).toNumber();
|
|
203
|
-
};
|
|
189
|
+
return flatArea * 2 / (Math.sqrt((Math.min(flatArea * S2_1.S2.M_1_PI, 1) * -1) + 1) + 1);
|
|
190
|
+
}
|
|
204
191
|
//
|
|
205
192
|
// /**
|
|
206
193
|
// * Return the area of this cell as accurately as possible. This method is more
|
|
207
194
|
// * expensive but it is accurate to 6 digits of precision even for leaf cells
|
|
208
195
|
// * (whose area is approximately 1e-18).
|
|
209
196
|
// */
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return S2_1.S2.area(v0, v1, v2)
|
|
216
|
-
}
|
|
197
|
+
exactArea() {
|
|
198
|
+
const v0 = this.getVertex(0);
|
|
199
|
+
const v1 = this.getVertex(1);
|
|
200
|
+
const v2 = this.getVertex(2);
|
|
201
|
+
const v3 = this.getVertex(3);
|
|
202
|
+
return S2_1.S2.area(v0, v1, v2) + (S2_1.S2.area(v0, v2, v3));
|
|
203
|
+
}
|
|
217
204
|
// //////////////////////////////////////////////////////////////////////
|
|
218
205
|
// S2Region interface (see {@code S2Region} for details):
|
|
219
|
-
|
|
206
|
+
getCapBound() {
|
|
220
207
|
// Use the cell center in (u,v)-space as the cap axis. This vector is
|
|
221
208
|
// very close to GetCenter() and faster to compute. Neither one of these
|
|
222
209
|
// vectors yields the bounding cap with minimal surface area, but they
|
|
@@ -225,17 +212,20 @@ var S2Cell = (function () {
|
|
|
225
212
|
// It's possible to show that the two vertices that are furthest from
|
|
226
213
|
// the (u,v)-origin never determine the maximum cap size (this is a
|
|
227
214
|
// possible future optimization).
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
for (
|
|
215
|
+
const uv = this.getCenterUV();
|
|
216
|
+
const center = S2Point_1.S2Point.normalize(S2Projections_1.S2Projections.faceUvToXyz(this._face, uv.x, uv.y));
|
|
217
|
+
let cap = S2Cap_1.S2Cap.fromAxisHeight(center, 0);
|
|
218
|
+
for (let k = 0; k < 4; ++k) {
|
|
232
219
|
cap = cap.addPoint(this.getVertex(k));
|
|
233
220
|
}
|
|
234
221
|
return cap;
|
|
235
|
-
}
|
|
222
|
+
}
|
|
236
223
|
// 35.26 degrees
|
|
237
|
-
|
|
238
|
-
|
|
224
|
+
getPoint(i, j) {
|
|
225
|
+
return S2Projections_1.S2Projections.faceUvToXyz(this._face, i == 0 ? this.uMin : this.uMax, j == 0 ? this.vMin : this.vMax);
|
|
226
|
+
}
|
|
227
|
+
getRectBound() {
|
|
228
|
+
if (this._level > 0) {
|
|
239
229
|
// Except for cells at level 0, the latitude and longitude extremes are
|
|
240
230
|
// attained at the vertices. Furthermore, the latitude range is
|
|
241
231
|
// determined by one pair of diagonally opposite vertices and the
|
|
@@ -247,21 +237,20 @@ var S2Cell = (function () {
|
|
|
247
237
|
// absolute x- and y-coordinates. To do this we look at each coordinate
|
|
248
238
|
// (u and v), and determine whether we want to minimize or maximize that
|
|
249
239
|
// coordinate based on the axis direction and the cell's (u,v) quadrant.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return new S2LatLngRect_1.S2LatLngRect(lat, lng.expanded(S2Cell.MAX_ERROR));
|
|
240
|
+
const u = this.uMin + this.uMax;
|
|
241
|
+
const v = this.vMin + this.vMax;
|
|
242
|
+
const i = S2Projections_1.S2Projections.getUAxis(this._face).z == 0 ? (u < 0 ? 1 : 0) : (u > 0 ? 1 : 0);
|
|
243
|
+
const j = S2Projections_1.S2Projections.getVAxis(this._face).z == 0 ? (v < 0 ? 1 : 0) : (v > 0 ? 1 : 0);
|
|
244
|
+
const lat = R1Interval_1.R1Interval.fromPointPair(S2LatLng_1.S2LatLng.latitude(this.getPoint(i, j)).radians, S2LatLng_1.S2LatLng.latitude(this.getPoint(1 - i, 1 - j)).radians);
|
|
245
|
+
const lng = S1Interval_1.S1Interval.fromPointPair(S2LatLng_1.S2LatLng.longitude(this.getPoint(i, 1 - j)).radians, S2LatLng_1.S2LatLng.longitude(this.getPoint(1 - i, j)).radians);
|
|
246
|
+
// DBL_EPSILON
|
|
247
|
+
return new S2LatLngRect_1.S2LatLngRect(lat, lng)
|
|
248
|
+
.expanded(S2LatLng_1.S2LatLng.fromRadians(S2_1.S2.DBL_EPSILON, S2_1.S2.DBL_EPSILON))
|
|
249
|
+
.polarClosure();
|
|
261
250
|
}
|
|
262
251
|
// The face centers are the +X, +Y, +Z, -X, -Y, -Z axes in that order.
|
|
263
252
|
// assert (S2Projections.getNorm(face).get(face % 3) == ((face < 3) ? 1 : -1));
|
|
264
|
-
switch (this.
|
|
253
|
+
switch (this._face) {
|
|
265
254
|
case 0:
|
|
266
255
|
return new S2LatLngRect_1.S2LatLngRect(new R1Interval_1.R1Interval(-S2_1.S2.M_PI_4, S2_1.S2.M_PI_4), new S1Interval_1.S1Interval(-S2_1.S2.M_PI_4, S2_1.S2.M_PI_4));
|
|
267
256
|
case 1:
|
|
@@ -275,68 +264,69 @@ var S2Cell = (function () {
|
|
|
275
264
|
default:
|
|
276
265
|
return new S2LatLngRect_1.S2LatLngRect(new R1Interval_1.R1Interval(-S2_1.S2.M_PI_2, -S2Cell.POLE_MIN_LAT), new S1Interval_1.S1Interval(-S2_1.S2.M_PI, S2_1.S2.M_PI));
|
|
277
266
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
267
|
+
}
|
|
268
|
+
mayIntersectC(cell) {
|
|
280
269
|
return this.cellID.intersects(cell.cellID);
|
|
281
|
-
}
|
|
282
|
-
|
|
270
|
+
}
|
|
271
|
+
contains(p) {
|
|
283
272
|
// We can't just call XYZtoFaceUV, because for points that lie on the
|
|
284
273
|
// boundary between two faces (i.e. u or v is +1/-1) we need to return
|
|
285
274
|
// true for both adjacent cells.
|
|
286
|
-
|
|
287
|
-
// S2Projections.faceXyzToUv(this.face, p);
|
|
275
|
+
const uvPoint = S2Projections_1.S2Projections.faceXyzToUv(this._face, p);
|
|
288
276
|
if (uvPoint == null) {
|
|
289
277
|
return false;
|
|
290
278
|
}
|
|
291
|
-
return (uvPoint.x
|
|
292
|
-
&& uvPoint.
|
|
293
|
-
|
|
279
|
+
return (uvPoint.x >= this.uMin
|
|
280
|
+
&& uvPoint.x <= this.uMax
|
|
281
|
+
&& uvPoint.y >= this.vMin
|
|
282
|
+
&& uvPoint.y <= this.vMax);
|
|
283
|
+
}
|
|
294
284
|
// The point 'p' does not need to be normalized.
|
|
295
|
-
|
|
285
|
+
containsC(cell) {
|
|
296
286
|
return this.cellID.contains(cell.cellID);
|
|
297
|
-
}
|
|
298
|
-
|
|
287
|
+
}
|
|
288
|
+
init(id) {
|
|
299
289
|
this.cellID = id;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
ij[d] = new MutableInteger_1.MutableInteger(0);
|
|
304
|
-
}
|
|
305
|
-
this._face = id.toFaceIJOrientation(ij[0], ij[1], mOrientation);
|
|
306
|
-
this._orientation = mOrientation.val; // Compress int to a byte.
|
|
290
|
+
this._face = id.face;
|
|
291
|
+
const ijo = id.toIJOrientation();
|
|
292
|
+
this._orientation = S2CellId_1.S2CellId.getOrientation(ijo);
|
|
307
293
|
this._level = id.level();
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
//
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
294
|
+
const i = S2CellId_1.S2CellId.getI(ijo);
|
|
295
|
+
const j = S2CellId_1.S2CellId.getJ(ijo);
|
|
296
|
+
const cellSize = id.getSizeIJ();
|
|
297
|
+
this.uMin = S2Projections_1.S2Projections.ijToUV(i, cellSize);
|
|
298
|
+
this.uMax = S2Projections_1.S2Projections.ijToUV(i + cellSize, cellSize);
|
|
299
|
+
this.vMin = S2Projections_1.S2Projections.ijToUV(j, cellSize);
|
|
300
|
+
this.vMax = S2Projections_1.S2Projections.ijToUV(j + cellSize, cellSize);
|
|
301
|
+
// for (let d = 0; d < 2; ++d) {
|
|
302
|
+
// // Compute the cell bounds in scaled (i,j) coordinates.
|
|
303
|
+
// const sijLo = (ij[d].val & -cellSize) * 2 - S2Cell.MAX_CELL_SIZE;
|
|
304
|
+
// const sijHi = sijLo + cellSize * 2;
|
|
305
|
+
// const s = 1/S2Cell.MAX_CELL_SIZE;
|
|
306
|
+
// this._uv[d][0] = R2Vector.singleStTOUV(s * (sijLo))
|
|
307
|
+
// //S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sijLo);
|
|
308
|
+
// this._uv[d][1] = R2Vector.singleStTOUV(s * (sijHi));
|
|
309
|
+
// //S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sijHi);
|
|
310
|
+
// }
|
|
311
|
+
}
|
|
312
|
+
get face() {
|
|
313
|
+
return this._face;
|
|
314
|
+
}
|
|
315
|
+
get orientation() {
|
|
316
|
+
return this._orientation;
|
|
317
|
+
}
|
|
318
|
+
get level() {
|
|
319
|
+
return this._level;
|
|
320
|
+
}
|
|
331
321
|
// Return the latitude or longitude of the cell vertex given by (i,j),
|
|
332
322
|
// where "i" and "j" are either 0 or 1.
|
|
333
|
-
|
|
334
|
-
return "[" + this._face + ", " + this._level + ", " + this.
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
.map(
|
|
339
|
-
.map(
|
|
323
|
+
toString() {
|
|
324
|
+
return "[" + this._face + ", " + this._level + ", " + this.orientation + ", " + this.cellID + "]";
|
|
325
|
+
}
|
|
326
|
+
toGEOJSON() {
|
|
327
|
+
const coords = [this.getVertex(0), this.getVertex(1), this.getVertex(2), this.getVertex(3), this.getVertex(0)]
|
|
328
|
+
.map(v => S2LatLng_1.S2LatLng.fromPoint(v))
|
|
329
|
+
.map(v => ([v.lngDegrees, v.latDegrees]));
|
|
340
330
|
// const rectJSON = this.getRectBound().toGEOJSON();
|
|
341
331
|
return {
|
|
342
332
|
type: 'Feature',
|
|
@@ -345,24 +335,24 @@ var S2Cell = (function () {
|
|
|
345
335
|
coordinates: [coords]
|
|
346
336
|
},
|
|
347
337
|
properties: {},
|
|
348
|
-
title:
|
|
338
|
+
title: `Cell: ${this.id.toToken()} lvl: ${this._level}`
|
|
349
339
|
};
|
|
350
340
|
// rectJSON.title = `Cell: ${this.id.toToken()}`;
|
|
351
341
|
// return rectJSON;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// We grow the bounds slightly to make sure that the bounding rectangle
|
|
355
|
-
// also contains the normalized versions of the vertices. Note that the
|
|
356
|
-
// maximum result magnitude is Pi, with a floating-point exponent of 1.
|
|
357
|
-
// Therefore adding or subtracting 2**-51 will always change the result.
|
|
358
|
-
S2Cell.MAX_ERROR = S2_1.S2.toDecimal(1.0).dividedBy(S2_1.S2.toDecimal(new Long(1).shiftLeft(51).toString()));
|
|
359
|
-
// The 4 cells around the equator extend to +/-45 degrees latitude at the
|
|
360
|
-
// midpoints of their top and bottom edges. The two cells covering the
|
|
361
|
-
// poles extend down to +/-35.26 degrees at their vertices.
|
|
362
|
-
// adding kMaxError (as opposed to the C version) because of asin and atan2
|
|
363
|
-
// roundoff errors
|
|
364
|
-
S2Cell.POLE_MIN_LAT = decimal_1.Decimal.asin(S2_1.S2.toDecimal(1.0).dividedBy(3).sqrt()).minus(S2Cell.MAX_ERROR);
|
|
365
|
-
return S2Cell;
|
|
366
|
-
}());
|
|
342
|
+
}
|
|
343
|
+
}
|
|
367
344
|
exports.S2Cell = S2Cell;
|
|
345
|
+
S2Cell.MAX_CELL_SIZE = 1 << S2CellId_1.S2CellId.MAX_LEVEL;
|
|
346
|
+
// We grow the bounds slightly to make sure that the bounding rectangle
|
|
347
|
+
// also contains the normalized versions of the vertices. Note that the
|
|
348
|
+
// maximum result magnitude is Pi, with a floating-point exponent of 1.
|
|
349
|
+
// Therefore adding or subtracting 2**-51 will always change the result.
|
|
350
|
+
// private static MAX_ERROR = S2.toDecimal(1.0).dividedBy(S2.toDecimal(new Long(1).shiftLeft(51).toString()));
|
|
351
|
+
S2Cell.MAX_ERROR = 1 / new Long(1).shiftLeft(51).toNumber();
|
|
352
|
+
// The 4 cells around the equator extend to +/-45 degrees latitude at the
|
|
353
|
+
// midpoints of their top and bottom edges. The two cells covering the
|
|
354
|
+
// poles extend down to +/-35.26 degrees at their vertices.
|
|
355
|
+
// adding kMaxError (as opposed to the C version) because of asin and atan2
|
|
356
|
+
// roundoff errors
|
|
357
|
+
S2Cell.POLE_MIN_LAT = Math.asin(Math.sqrt(1 / 3)) - S2Cell.MAX_ERROR;
|
|
368
358
|
//# sourceMappingURL=S2Cell.js.map
|