dgeoutils 2.3.7 → 2.4.2
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/dist/{cjs/DCircle.d.ts → DCircle.d.ts} +0 -0
- package/dist/{es2015/DCircle.js → DCircle.js} +18 -14
- package/dist/{cjs/DLine.d.ts → DLine.d.ts} +0 -0
- package/dist/{es2015/DLine.js → DLine.js} +28 -24
- package/dist/{cjs/DNumbers.d.ts → DNumbers.d.ts} +0 -0
- package/dist/DNumbers.js +26 -0
- package/dist/{cjs/DPlane.d.ts → DPlane.d.ts} +0 -0
- package/dist/{es2015/DPlane.js → DPlane.js} +26 -22
- package/dist/{cjs/DPoint.d.ts → DPoint.d.ts} +0 -0
- package/dist/{es2015/DPoint.js → DPoint.js} +56 -52
- package/dist/{cjs/DPolygon.d.ts → DPolygon.d.ts} +1 -1
- package/dist/{es2015/DPolygon.js → DPolygon.js} +50 -42
- package/dist/{cjs/DPolygonLoop.d.ts → DPolygonLoop.d.ts} +0 -0
- package/dist/{es2015/DPolygonLoop.js → DPolygonLoop.js} +5 -1
- package/dist/{cjs/FastSearch.d.ts → FastSearch.d.ts} +0 -0
- package/dist/{es2015/FastSearch.js → FastSearch.js} +5 -1
- package/dist/{cjs/TraceMatrix.d.ts → TraceMatrix.d.ts} +0 -0
- package/dist/{es2015/TraceMatrix.js → TraceMatrix.js} +39 -35
- package/dist/esm/DPolygon.js +6 -1
- package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- package/dist/{cjs/index.js → index.js} +0 -0
- package/dist/umd/dgeoutils.js +7 -2
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
- package/dist/{es2015/utils.js → utils.js} +41 -29
- package/package.json +5 -6
- package/dist/cjs/DCircle.js +0 -102
- package/dist/cjs/DLine.js +0 -310
- package/dist/cjs/DNumbers.js +0 -30
- package/dist/cjs/DPlane.js +0 -132
- package/dist/cjs/DPoint.js +0 -574
- package/dist/cjs/DPolygon.js +0 -1555
- package/dist/cjs/DPolygonLoop.js +0 -401
- package/dist/cjs/FastSearch.js +0 -53
- package/dist/cjs/TraceMatrix.js +0 -256
- package/dist/cjs/utils.js +0 -216
- package/dist/es2015/DNumbers.js +0 -22
- package/dist/es2015/index.js +0 -10
|
File without changes
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DCircle = void 0;
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const DPolygon_1 = require("./DPolygon");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
class DCircle {
|
|
8
|
+
constructor(center = DPoint_1.DPoint.zero(), r = 0) {
|
|
6
9
|
this.center = center;
|
|
7
10
|
this.r = r;
|
|
8
11
|
}
|
|
@@ -37,10 +40,10 @@ export class DCircle {
|
|
|
37
40
|
const y32 = y2 + hd * dx;
|
|
38
41
|
const res = [];
|
|
39
42
|
if (!isNaN(x31) && !isNaN(y31)) {
|
|
40
|
-
res.push(new DPoint(x31, y31));
|
|
43
|
+
res.push(new DPoint_1.DPoint(x31, y31));
|
|
41
44
|
}
|
|
42
45
|
if (!isNaN(x32) && !isNaN(y32) && !(x31 === x32 && y31 === y32)) {
|
|
43
|
-
res.push(new DPoint(x32, y32));
|
|
46
|
+
res.push(new DPoint_1.DPoint(x32, y32));
|
|
44
47
|
}
|
|
45
48
|
return res;
|
|
46
49
|
}
|
|
@@ -52,17 +55,17 @@ export class DCircle {
|
|
|
52
55
|
const points = [];
|
|
53
56
|
let angle = startAngle;
|
|
54
57
|
while (angle < stopAngle - step) {
|
|
55
|
-
points.push(new DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
|
|
58
|
+
points.push(new DPoint_1.DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
|
|
56
59
|
.move(this.center));
|
|
57
60
|
angle += step;
|
|
58
61
|
}
|
|
59
62
|
const x = this.r * Math.cos(stopAngle) + this.center.x;
|
|
60
63
|
const y = this.r * Math.sin(stopAngle) + this.center.y;
|
|
61
|
-
points.push(new DPoint(x, y));
|
|
62
|
-
return new DPolygon(points);
|
|
64
|
+
points.push(new DPoint_1.DPoint(x, y));
|
|
65
|
+
return new DPolygon_1.DPolygon(points);
|
|
63
66
|
}
|
|
64
67
|
findPolygonInsideOnSphere(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
|
|
65
|
-
checkFunction('findPolygonInsideOnSphere')
|
|
68
|
+
(0, utils_1.checkFunction)('findPolygonInsideOnSphere')
|
|
66
69
|
.checkArgument('center')
|
|
67
70
|
.shouldBeDegree(this.center);
|
|
68
71
|
const step = 2 * Math.PI / pointCount;
|
|
@@ -73,15 +76,16 @@ export class DCircle {
|
|
|
73
76
|
angle += step;
|
|
74
77
|
}
|
|
75
78
|
points.push(this.sphereOffset(stopAngle));
|
|
76
|
-
return new DPolygon(points);
|
|
79
|
+
return new DPolygon_1.DPolygon(points);
|
|
77
80
|
}
|
|
78
|
-
sphereOffset(bearing, earthRadius = EARTH_RADIUS_IN_METERS) {
|
|
81
|
+
sphereOffset(bearing, earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS) {
|
|
79
82
|
const { x: lon1, y: lat1 } = this.center.clone().degreeToRadians();
|
|
80
83
|
const dByR = this.r / earthRadius;
|
|
81
84
|
const lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
|
|
82
85
|
Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
|
|
83
86
|
const lon = lon1 +
|
|
84
87
|
Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
|
|
85
|
-
return new DPoint(lon, lat).radiansToDegrees();
|
|
88
|
+
return new DPoint_1.DPoint(lon, lat).radiansToDegrees();
|
|
86
89
|
}
|
|
87
90
|
}
|
|
91
|
+
exports.DCircle = DCircle;
|
|
File without changes
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DLine = void 0;
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const DNumbers_1 = require("./DNumbers");
|
|
7
|
+
class DLine {
|
|
8
|
+
constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()) {
|
|
6
9
|
this.a = a;
|
|
7
10
|
this.b = b;
|
|
8
11
|
this.c = c;
|
|
@@ -13,7 +16,7 @@ export class DLine {
|
|
|
13
16
|
return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
|
|
14
17
|
}
|
|
15
18
|
findPerpendicular(p) {
|
|
16
|
-
checkFunction('findPerpendicular')
|
|
19
|
+
(0, utils_1.checkFunction)('findPerpendicular')
|
|
17
20
|
.checkArgument('this.begin')
|
|
18
21
|
.shouldBeMeters(this.begin)
|
|
19
22
|
.checkArgument('this.end')
|
|
@@ -23,7 +26,7 @@ export class DLine {
|
|
|
23
26
|
return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
|
|
24
27
|
}
|
|
25
28
|
perpendicularDistance(p) {
|
|
26
|
-
checkFunction('perpendicularDistance')
|
|
29
|
+
(0, utils_1.checkFunction)('perpendicularDistance')
|
|
27
30
|
.checkArgument('this.begin')
|
|
28
31
|
.shouldBeMeters(this.begin)
|
|
29
32
|
.checkArgument('this.end')
|
|
@@ -137,21 +140,21 @@ export class DLine {
|
|
|
137
140
|
}
|
|
138
141
|
x(p) {
|
|
139
142
|
if (this.isParallelY) {
|
|
140
|
-
return new DPoint(-this.c / this.a, p.y);
|
|
143
|
+
return new DPoint_1.DPoint(-this.c / this.a, p.y);
|
|
141
144
|
}
|
|
142
145
|
if (this.isParallelX) {
|
|
143
|
-
return new DPoint(p.x, -this.c / this.b);
|
|
146
|
+
return new DPoint_1.DPoint(p.x, -this.c / this.b);
|
|
144
147
|
}
|
|
145
|
-
return new DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
|
|
148
|
+
return new DPoint_1.DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
|
|
146
149
|
}
|
|
147
150
|
y(p) {
|
|
148
151
|
if (this.isParallelY) {
|
|
149
|
-
return new DPoint(-this.c / this.a, p.y);
|
|
152
|
+
return new DPoint_1.DPoint(-this.c / this.a, p.y);
|
|
150
153
|
}
|
|
151
154
|
if (this.isParallelX) {
|
|
152
|
-
return new DPoint(p.x, -this.c / this.b);
|
|
155
|
+
return new DPoint_1.DPoint(p.x, -this.c / this.b);
|
|
153
156
|
}
|
|
154
|
-
return new DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
|
|
157
|
+
return new DPoint_1.DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
|
|
155
158
|
}
|
|
156
159
|
findPoint(l) {
|
|
157
160
|
if (this.isParallelY && l.isParallelY) {
|
|
@@ -161,28 +164,28 @@ export class DLine {
|
|
|
161
164
|
return null;
|
|
162
165
|
}
|
|
163
166
|
if (this.isParallelX && l.isParallelY) {
|
|
164
|
-
return new DPoint(-l.c / l.a, -this.c / this.b);
|
|
167
|
+
return new DPoint_1.DPoint(-l.c / l.a, -this.c / this.b);
|
|
165
168
|
}
|
|
166
169
|
if (this.isParallelY && l.isParallelX) {
|
|
167
|
-
return new DPoint(-this.c / this.a, -l.c / l.b);
|
|
170
|
+
return new DPoint_1.DPoint(-this.c / this.a, -l.c / l.b);
|
|
168
171
|
}
|
|
169
172
|
if (this.isParallelY) {
|
|
170
173
|
const x = -this.c / this.a;
|
|
171
|
-
return l.y(new DPoint(x));
|
|
174
|
+
return l.y(new DPoint_1.DPoint(x));
|
|
172
175
|
}
|
|
173
176
|
if (this.isParallelX) {
|
|
174
177
|
const y = -this.c / this.b;
|
|
175
|
-
return l.x(new DPoint(0, y));
|
|
178
|
+
return l.x(new DPoint_1.DPoint(0, y));
|
|
176
179
|
}
|
|
177
180
|
if (l.isParallelY) {
|
|
178
181
|
const x = -l.c / l.a;
|
|
179
|
-
return this.y(new DPoint(x));
|
|
182
|
+
return this.y(new DPoint_1.DPoint(x));
|
|
180
183
|
}
|
|
181
184
|
if (l.isParallelX) {
|
|
182
185
|
const y = -l.c / l.b;
|
|
183
|
-
return this.x(new DPoint(0, y));
|
|
186
|
+
return this.x(new DPoint_1.DPoint(0, y));
|
|
184
187
|
}
|
|
185
|
-
const res = this.y(new DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
|
|
188
|
+
const res = this.y(new DPoint_1.DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
|
|
186
189
|
if (!isFinite(res.x) && !isFinite(res.y)) {
|
|
187
190
|
return null;
|
|
188
191
|
}
|
|
@@ -201,7 +204,7 @@ export class DLine {
|
|
|
201
204
|
return [this.begin, this.end];
|
|
202
205
|
}
|
|
203
206
|
getFi() {
|
|
204
|
-
checkFunction('getFi')
|
|
207
|
+
(0, utils_1.checkFunction)('getFi')
|
|
205
208
|
.checkArgument('this.begin')
|
|
206
209
|
.shouldBeMeters(this.begin)
|
|
207
210
|
.checkArgument('this.end')
|
|
@@ -222,13 +225,13 @@ export class DLine {
|
|
|
222
225
|
const p = isArray ? i : [i];
|
|
223
226
|
const d = (isArray ? k : [k]);
|
|
224
227
|
const fi = this.findFi(new DLine(1, 0, 0));
|
|
225
|
-
const td = this.x(new DPoint(1, 1)).distance(this.x(new DPoint(2, 2))) / 2;
|
|
226
|
-
const sinCos = new DPoint(Math.sin(fi), Math.cos(fi));
|
|
228
|
+
const td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
|
|
229
|
+
const sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
|
|
227
230
|
const dt = sinCos.clone().scale(td);
|
|
228
231
|
const p1T = p[0].clone().move(dt.clone().minus());
|
|
229
232
|
const p2T = p[0].clone().move(dt);
|
|
230
233
|
let res = [];
|
|
231
|
-
if (DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers.like(this.y(p2T).y, p2T.y)) {
|
|
234
|
+
if (DNumbers_1.DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers_1.DNumbers.like(this.y(p2T).y, p2T.y)) {
|
|
232
235
|
res = p.map((t, index) => t.clone()
|
|
233
236
|
.move(sinCos.clone().scale(d[index])));
|
|
234
237
|
}
|
|
@@ -255,3 +258,4 @@ export class DLine {
|
|
|
255
258
|
return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
|
|
256
259
|
}
|
|
257
260
|
}
|
|
261
|
+
exports.DLine = DLine;
|
|
File without changes
|
package/dist/DNumbers.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DNumbers = void 0;
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const delta = 0.001;
|
|
6
|
+
class DNumbers {
|
|
7
|
+
static like(v, s, d = delta) {
|
|
8
|
+
return Math.abs(v - s) < d;
|
|
9
|
+
}
|
|
10
|
+
static likeZero(v) {
|
|
11
|
+
return DNumbers.like(v, 0);
|
|
12
|
+
}
|
|
13
|
+
static like2PI(v) {
|
|
14
|
+
return DNumbers.like(DNumbers.rad2Deg(v), DPoint_1.DOUBLE_PI_IN_DEGREE);
|
|
15
|
+
}
|
|
16
|
+
static likePI(v) {
|
|
17
|
+
return DNumbers.like(DNumbers.rad2Deg(v), DPoint_1.PI_IN_DEGREE);
|
|
18
|
+
}
|
|
19
|
+
static rad2Deg(v) {
|
|
20
|
+
return v * DPoint_1.DEGREE_TO_PI;
|
|
21
|
+
}
|
|
22
|
+
static deg2Rad(v) {
|
|
23
|
+
return v * DPoint_1.PI_TO_DEGREE;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.DNumbers = DNumbers;
|
|
File without changes
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DPlane = void 0;
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const DNumbers_1 = require("./DNumbers");
|
|
7
|
+
class DPlane {
|
|
8
|
+
constructor(a, b, c, d, p1 = DPoint_1.DPoint.zero(), p2 = DPoint_1.DPoint.zero(), p3 = DPoint_1.DPoint.zero()) {
|
|
6
9
|
this.a = a;
|
|
7
10
|
this.b = b;
|
|
8
11
|
this.c = c;
|
|
@@ -22,7 +25,7 @@ export class DPlane {
|
|
|
22
25
|
return new DPlane(0, 0, 1, -p1.z, p1, p2, p3);
|
|
23
26
|
}
|
|
24
27
|
const d = 1;
|
|
25
|
-
const [a, b, c] = gaussianElimination([
|
|
28
|
+
const [a, b, c] = (0, utils_1.gaussianElimination)([
|
|
26
29
|
[p1.x, p1.y, p1.z, -d],
|
|
27
30
|
[p2.x, p2.y, p2.z, -d],
|
|
28
31
|
[p3.x, p3.y, p3.z, -d]
|
|
@@ -30,7 +33,7 @@ export class DPlane {
|
|
|
30
33
|
return new DPlane(a, b, c, d, p1, p2, p3);
|
|
31
34
|
}
|
|
32
35
|
x(p) {
|
|
33
|
-
if (p instanceof DPoint) {
|
|
36
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
34
37
|
const { a, b, c, d } = this;
|
|
35
38
|
const { y, z } = p;
|
|
36
39
|
p.x = -(b * y + c * z + d) / a;
|
|
@@ -39,7 +42,7 @@ export class DPlane {
|
|
|
39
42
|
return p.map((t) => this.x(t));
|
|
40
43
|
}
|
|
41
44
|
y(p) {
|
|
42
|
-
if (p instanceof DPoint) {
|
|
45
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
43
46
|
const { a, b, c, d } = this;
|
|
44
47
|
const { x, z } = p;
|
|
45
48
|
p.y = -(a * x + c * z + d) / b;
|
|
@@ -48,7 +51,7 @@ export class DPlane {
|
|
|
48
51
|
return p.map((t) => this.y(t));
|
|
49
52
|
}
|
|
50
53
|
z(p) {
|
|
51
|
-
if (p instanceof DPoint) {
|
|
54
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
52
55
|
const { a, b, c, d } = this;
|
|
53
56
|
const { x, y } = p;
|
|
54
57
|
p.z = -(a * x + b * y + d) / c;
|
|
@@ -61,7 +64,7 @@ export class DPlane {
|
|
|
61
64
|
return new DPlane(a, b, c, d, p1, p2, p3);
|
|
62
65
|
}
|
|
63
66
|
distance(p) {
|
|
64
|
-
if (p instanceof DPoint) {
|
|
67
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
65
68
|
const { x, y, z } = p;
|
|
66
69
|
const { a, b, c, d } = this;
|
|
67
70
|
return Math.abs(a * x + b * y + c * z + d) / Math.sqrt(a * a + b * b + c * c);
|
|
@@ -73,10 +76,10 @@ export class DPlane {
|
|
|
73
76
|
equal(p) {
|
|
74
77
|
const { a, b, c, d } = p;
|
|
75
78
|
const { a: q, b: w, c: e, d: r } = this;
|
|
76
|
-
return DNumbers.like(a, q) &&
|
|
77
|
-
DNumbers.like(b, w) &&
|
|
78
|
-
DNumbers.like(c, e) &&
|
|
79
|
-
DNumbers.like(d, r);
|
|
79
|
+
return DNumbers_1.DNumbers.like(a, q) &&
|
|
80
|
+
DNumbers_1.DNumbers.like(b, w) &&
|
|
81
|
+
DNumbers_1.DNumbers.like(c, e) &&
|
|
82
|
+
DNumbers_1.DNumbers.like(d, r);
|
|
80
83
|
}
|
|
81
84
|
same(p) {
|
|
82
85
|
const { a, b, c, d } = p;
|
|
@@ -85,10 +88,10 @@ export class DPlane {
|
|
|
85
88
|
const y = b / w;
|
|
86
89
|
const u = c / e;
|
|
87
90
|
const i = d / r;
|
|
88
|
-
return DNumbers.like(t, y) &&
|
|
89
|
-
DNumbers.like(t, u) &&
|
|
90
|
-
DNumbers.like(t, c) &&
|
|
91
|
-
DNumbers.like(t, i);
|
|
91
|
+
return DNumbers_1.DNumbers.like(t, y) &&
|
|
92
|
+
DNumbers_1.DNumbers.like(t, u) &&
|
|
93
|
+
DNumbers_1.DNumbers.like(t, c) &&
|
|
94
|
+
DNumbers_1.DNumbers.like(t, i);
|
|
92
95
|
}
|
|
93
96
|
parallel(p) {
|
|
94
97
|
const { a, b, c, d } = p;
|
|
@@ -97,9 +100,10 @@ export class DPlane {
|
|
|
97
100
|
const y = b / w;
|
|
98
101
|
const u = c / e;
|
|
99
102
|
const i = d / r;
|
|
100
|
-
return DNumbers.like(t, y) &&
|
|
101
|
-
DNumbers.like(t, u) &&
|
|
102
|
-
DNumbers.like(t, c) &&
|
|
103
|
-
!DNumbers.like(t, i);
|
|
103
|
+
return DNumbers_1.DNumbers.like(t, y) &&
|
|
104
|
+
DNumbers_1.DNumbers.like(t, u) &&
|
|
105
|
+
DNumbers_1.DNumbers.like(t, c) &&
|
|
106
|
+
!DNumbers_1.DNumbers.like(t, i);
|
|
104
107
|
}
|
|
105
108
|
}
|
|
109
|
+
exports.DPlane = DPlane;
|
|
File without changes
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DPoint = exports.DEGREE_TO_PI = exports.PI_TO_DEGREE = exports.DOUBLE_PI_IN_DEGREE = exports.PI_IN_DEGREE = exports.HALF_PI_IN_DEGREE = exports.EARTH_RADIUS_IN_METERS = void 0;
|
|
4
|
+
const DLine_1 = require("./DLine");
|
|
5
|
+
const DPolygon_1 = require("./DPolygon");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
4
7
|
const diff = 0;
|
|
5
|
-
const radiansPolygon = new DPolygon();
|
|
6
|
-
const pseudoMercatorPolygon = new DPolygon();
|
|
7
|
-
const worldGeodeticPolygon = new DPolygon();
|
|
8
|
-
|
|
8
|
+
const radiansPolygon = new DPolygon_1.DPolygon();
|
|
9
|
+
const pseudoMercatorPolygon = new DPolygon_1.DPolygon();
|
|
10
|
+
const worldGeodeticPolygon = new DPolygon_1.DPolygon();
|
|
11
|
+
exports.EARTH_RADIUS_IN_METERS = 6371008.8;
|
|
9
12
|
const EARTH_IN_MITERS = 20037508.34;
|
|
10
13
|
const DEGREES_IN_EARTH = 180;
|
|
11
14
|
const MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
|
|
12
15
|
const DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
exports.HALF_PI_IN_DEGREE = 90;
|
|
17
|
+
exports.PI_IN_DEGREE = 180;
|
|
18
|
+
exports.DOUBLE_PI_IN_DEGREE = 360;
|
|
19
|
+
exports.PI_TO_DEGREE = Math.PI / exports.PI_IN_DEGREE;
|
|
20
|
+
exports.DEGREE_TO_PI = exports.PI_IN_DEGREE / Math.PI;
|
|
21
|
+
class DPoint {
|
|
19
22
|
constructor(x = 0, y = x, z) {
|
|
20
23
|
this.x = x;
|
|
21
24
|
this.y = y;
|
|
@@ -44,20 +47,20 @@ export class DPoint {
|
|
|
44
47
|
return new DPoint(Math.random(), Math.random());
|
|
45
48
|
}
|
|
46
49
|
getTileFromCoords(zoom = this.z) {
|
|
47
|
-
checkFunction('getTileFromCoords')
|
|
50
|
+
(0, utils_1.checkFunction)('getTileFromCoords')
|
|
48
51
|
.checkArgument('this')
|
|
49
52
|
.shouldBeDegree(this);
|
|
50
|
-
const x = Math.floor((this.x + PI_IN_DEGREE) / DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
|
|
51
|
-
const y = Math.floor((1 - Math.log(Math.tan(this.y * PI_TO_DEGREE) + 1 / Math.cos(this.y * PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
|
|
53
|
+
const x = Math.floor((this.x + exports.PI_IN_DEGREE) / exports.DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
|
|
54
|
+
const y = Math.floor((1 - Math.log(Math.tan(this.y * exports.PI_TO_DEGREE) + 1 / Math.cos(this.y * exports.PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
|
|
52
55
|
return new DPoint(x, y, zoom);
|
|
53
56
|
}
|
|
54
57
|
getCoordsFromTile(zoom = this.z) {
|
|
55
|
-
checkFunction('getCoordsFromTile')
|
|
58
|
+
(0, utils_1.checkFunction)('getCoordsFromTile')
|
|
56
59
|
.checkArgument('this')
|
|
57
60
|
.shouldBeUInt(this);
|
|
58
61
|
const n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
|
|
59
|
-
const x = this.x / (Math.pow(2, zoom)) * DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE;
|
|
60
|
-
const y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
62
|
+
const x = this.x / (Math.pow(2, zoom)) * exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE;
|
|
63
|
+
const y = exports.PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
61
64
|
return new DPoint(x, y, zoom);
|
|
62
65
|
}
|
|
63
66
|
toCoords() {
|
|
@@ -67,7 +70,7 @@ export class DPoint {
|
|
|
67
70
|
return [this.x, this.y, this.z];
|
|
68
71
|
}
|
|
69
72
|
findLine(p) {
|
|
70
|
-
checkFunction('findLine')
|
|
73
|
+
(0, utils_1.checkFunction)('findLine')
|
|
71
74
|
.checkArgument('this')
|
|
72
75
|
.shouldBeMeters(this)
|
|
73
76
|
.checkArgument('p')
|
|
@@ -79,15 +82,15 @@ export class DPoint {
|
|
|
79
82
|
const b = p.x - this.x - diff;
|
|
80
83
|
const c = this.x * p.y - p.x * this.y - diff;
|
|
81
84
|
if (a === 0) {
|
|
82
|
-
return new DLine(0, 1, c / b, this, p);
|
|
85
|
+
return new DLine_1.DLine(0, 1, c / b, this, p);
|
|
83
86
|
}
|
|
84
87
|
if (b === 0) {
|
|
85
|
-
return new DLine(1, 0, c / a, this, p);
|
|
88
|
+
return new DLine_1.DLine(1, 0, c / a, this, p);
|
|
86
89
|
}
|
|
87
|
-
return new DLine(a, b, c, this, p);
|
|
90
|
+
return new DLine_1.DLine(a, b, c, this, p);
|
|
88
91
|
}
|
|
89
92
|
findInnerAngle(p1, p3) {
|
|
90
|
-
checkFunction('findInnerAngle')
|
|
93
|
+
(0, utils_1.checkFunction)('findInnerAngle')
|
|
91
94
|
.checkArgument('this')
|
|
92
95
|
.shouldBeMeters(this)
|
|
93
96
|
.checkArgument('p1')
|
|
@@ -116,7 +119,7 @@ export class DPoint {
|
|
|
116
119
|
return `POINT (${x} ${y})`;
|
|
117
120
|
}
|
|
118
121
|
distance(p) {
|
|
119
|
-
checkFunction('distance')
|
|
122
|
+
(0, utils_1.checkFunction)('distance')
|
|
120
123
|
.checkArgument('this')
|
|
121
124
|
.shouldBeMeters(this)
|
|
122
125
|
.checkArgument('p')
|
|
@@ -126,7 +129,7 @@ export class DPoint {
|
|
|
126
129
|
return Math.sqrt(dx * dx + dy * dy);
|
|
127
130
|
}
|
|
128
131
|
distance3d(p) {
|
|
129
|
-
checkFunction('distance3d')
|
|
132
|
+
(0, utils_1.checkFunction)('distance3d')
|
|
130
133
|
.checkArgument('this')
|
|
131
134
|
.shouldBeMeters(this)
|
|
132
135
|
.checkArgument('p')
|
|
@@ -201,66 +204,66 @@ export class DPoint {
|
|
|
201
204
|
if (x instanceof DPoint) {
|
|
202
205
|
xV = this.x + x.x;
|
|
203
206
|
yV = this.y + x.y;
|
|
204
|
-
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
207
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
205
208
|
zV = this.z + x.z;
|
|
206
209
|
}
|
|
207
210
|
}
|
|
208
211
|
else {
|
|
209
212
|
xV = this.x + x;
|
|
210
213
|
yV = this.y + y;
|
|
211
|
-
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
214
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
212
215
|
zV = this.z + z;
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
218
|
this.x = xV;
|
|
216
219
|
this.y = yV;
|
|
217
|
-
if (isDefAndNotNull(zV)) {
|
|
220
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
218
221
|
this.z = zV;
|
|
219
222
|
}
|
|
220
223
|
return this;
|
|
221
224
|
}
|
|
222
225
|
degreeToMeters() {
|
|
223
|
-
checkFunction('degreeToMeters')
|
|
226
|
+
(0, utils_1.checkFunction)('degreeToMeters')
|
|
224
227
|
.checkArgument('this')
|
|
225
228
|
.shouldBeDegree(this);
|
|
226
|
-
const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
227
|
-
const y = (Math.log(Math.tan(((this.y + HALF_PI_IN_DEGREE) % PI_IN_DEGREE) *
|
|
228
|
-
(Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
229
|
+
const x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
230
|
+
const y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
|
|
231
|
+
(Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
229
232
|
this.x = x;
|
|
230
233
|
this.y = y;
|
|
231
234
|
return this;
|
|
232
235
|
}
|
|
233
236
|
metersToDegree() {
|
|
234
|
-
checkFunction('metersToDegree')
|
|
237
|
+
(0, utils_1.checkFunction)('metersToDegree')
|
|
235
238
|
.checkArgument('this')
|
|
236
239
|
.shouldBeMeters(this);
|
|
237
240
|
const lon = this.x * DEGREES_IN_ONE_MITER;
|
|
238
|
-
const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * PI_TO_DEGREE))) *
|
|
239
|
-
(DOUBLE_PI_IN_DEGREE / Math.PI) - HALF_PI_IN_DEGREE;
|
|
241
|
+
const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
|
|
242
|
+
(exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
|
|
240
243
|
this.x = lon;
|
|
241
244
|
this.y = lat;
|
|
242
245
|
return this;
|
|
243
246
|
}
|
|
244
247
|
degreeToRadians() {
|
|
245
|
-
checkFunction('degreeToRadians')
|
|
248
|
+
(0, utils_1.checkFunction)('degreeToRadians')
|
|
246
249
|
.checkArgument('this')
|
|
247
250
|
.shouldBeDegree(this);
|
|
248
|
-
return this.scale(PI_TO_DEGREE);
|
|
251
|
+
return this.scale(exports.PI_TO_DEGREE);
|
|
249
252
|
}
|
|
250
253
|
radiansToDegrees() {
|
|
251
|
-
checkFunction('radiansToDegrees')
|
|
254
|
+
(0, utils_1.checkFunction)('radiansToDegrees')
|
|
252
255
|
.checkArgument('this')
|
|
253
256
|
.shouldBeRadians(this);
|
|
254
|
-
return this.scale(DEGREE_TO_PI);
|
|
257
|
+
return this.scale(exports.DEGREE_TO_PI);
|
|
255
258
|
}
|
|
256
259
|
radiansToMeters() {
|
|
257
|
-
checkFunction('radiansToMeters')
|
|
260
|
+
(0, utils_1.checkFunction)('radiansToMeters')
|
|
258
261
|
.checkArgument('this')
|
|
259
262
|
.shouldBeRadians(this);
|
|
260
263
|
return this.radiansToDegrees().degreeToMeters();
|
|
261
264
|
}
|
|
262
265
|
metersToRadians() {
|
|
263
|
-
checkFunction('metersToRadians')
|
|
266
|
+
(0, utils_1.checkFunction)('metersToRadians')
|
|
264
267
|
.checkArgument('this')
|
|
265
268
|
.shouldBeMeters(this);
|
|
266
269
|
return this.metersToDegree().degreeToRadians();
|
|
@@ -297,20 +300,20 @@ export class DPoint {
|
|
|
297
300
|
if (x instanceof DPoint) {
|
|
298
301
|
xV = this.x * x.x;
|
|
299
302
|
yV = this.y * x.y;
|
|
300
|
-
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
303
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
301
304
|
zV = this.z * x.z;
|
|
302
305
|
}
|
|
303
306
|
}
|
|
304
307
|
else {
|
|
305
308
|
xV = this.x * x;
|
|
306
309
|
yV = this.y * y;
|
|
307
|
-
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
310
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
308
311
|
zV = this.z * z;
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
314
|
this.x = xV;
|
|
312
315
|
this.y = yV;
|
|
313
|
-
if (isDefAndNotNull(zV)) {
|
|
316
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
314
317
|
this.z = zV;
|
|
315
318
|
}
|
|
316
319
|
return this;
|
|
@@ -322,20 +325,20 @@ export class DPoint {
|
|
|
322
325
|
if (x instanceof DPoint) {
|
|
323
326
|
xV = this.x / x.x;
|
|
324
327
|
yV = this.y / x.y;
|
|
325
|
-
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
328
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
326
329
|
zV = this.z / x.z;
|
|
327
330
|
}
|
|
328
331
|
}
|
|
329
332
|
else {
|
|
330
333
|
xV = this.x / x;
|
|
331
334
|
yV = this.y / y;
|
|
332
|
-
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
335
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
333
336
|
zV = this.z / z;
|
|
334
337
|
}
|
|
335
338
|
}
|
|
336
339
|
this.x = xV;
|
|
337
340
|
this.y = yV;
|
|
338
|
-
if (isDefAndNotNull(zV)) {
|
|
341
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
339
342
|
this.z = zV;
|
|
340
343
|
}
|
|
341
344
|
return this;
|
|
@@ -392,13 +395,13 @@ export class DPoint {
|
|
|
392
395
|
this.y = y;
|
|
393
396
|
}
|
|
394
397
|
get area() {
|
|
395
|
-
checkFunction('area')
|
|
398
|
+
(0, utils_1.checkFunction)('area')
|
|
396
399
|
.checkArgument('this')
|
|
397
400
|
.shouldBeMeters(this);
|
|
398
401
|
return this.w * this.h;
|
|
399
402
|
}
|
|
400
403
|
get hip() {
|
|
401
|
-
checkFunction('hip')
|
|
404
|
+
(0, utils_1.checkFunction)('hip')
|
|
402
405
|
.checkArgument('this')
|
|
403
406
|
.shouldBeMeters(this);
|
|
404
407
|
return Math.sqrt(this.w * this.w + this.h * this.h);
|
|
@@ -442,7 +445,7 @@ export class DPoint {
|
|
|
442
445
|
return this.scale(-1);
|
|
443
446
|
}
|
|
444
447
|
orthodromicPath(point, pointsCount = 360) {
|
|
445
|
-
checkFunction('orthodromicPath')
|
|
448
|
+
(0, utils_1.checkFunction)('orthodromicPath')
|
|
446
449
|
.checkArgument('this')
|
|
447
450
|
.shouldBeDegree(this)
|
|
448
451
|
.checkArgument('point')
|
|
@@ -451,7 +454,7 @@ export class DPoint {
|
|
|
451
454
|
const p = point.clone().degreeToRadians();
|
|
452
455
|
const d = Math.sin(p.x - t.x);
|
|
453
456
|
const step = (p.x - t.x) / (pointsCount - 1);
|
|
454
|
-
return new DPolygon(createArray(pointsCount)
|
|
457
|
+
return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
|
|
455
458
|
.map((v, i) => {
|
|
456
459
|
const x = t.x + step * i;
|
|
457
460
|
const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
|
|
@@ -470,3 +473,4 @@ export class DPoint {
|
|
|
470
473
|
.sort((a, b) => a.properties.distance - b.properties.distance);
|
|
471
474
|
}
|
|
472
475
|
}
|
|
476
|
+
exports.DPoint = DPoint;
|
|
@@ -97,7 +97,7 @@ export declare class DPolygon {
|
|
|
97
97
|
static parse(a: number[][]): DPolygon;
|
|
98
98
|
static parse(a: DCoord[]): DPolygon;
|
|
99
99
|
toArrayOfCoords(): DCoord[];
|
|
100
|
-
divideToPieces(piecesCount: number): DPolygon;
|
|
100
|
+
divideToPieces(piecesCount: number, withAltitude?: boolean): DPolygon;
|
|
101
101
|
prepareToFastSearch(): void;
|
|
102
102
|
fastHas({ x, y, z }: DPoint): boolean;
|
|
103
103
|
get growingPiecesGenerator(): () => Generator<DPolygon, DPolygon>;
|