dgeoutils 2.4.2 → 2.4.5
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/{DCircle.d.ts → cjs/DCircle.d.ts} +0 -0
- package/dist/cjs/DCircle.js +102 -0
- package/dist/{DLine.d.ts → cjs/DLine.d.ts} +0 -0
- package/dist/cjs/DLine.js +310 -0
- package/dist/{DNumbers.d.ts → cjs/DNumbers.d.ts} +0 -0
- package/dist/cjs/DNumbers.js +30 -0
- package/dist/{DPlane.d.ts → cjs/DPlane.d.ts} +0 -0
- package/dist/cjs/DPlane.js +132 -0
- package/dist/{DPoint.d.ts → cjs/DPoint.d.ts} +2 -0
- package/dist/cjs/DPoint.js +614 -0
- package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +0 -0
- package/dist/cjs/DPolygon.js +1560 -0
- package/dist/{DPolygonLoop.d.ts → cjs/DPolygonLoop.d.ts} +0 -0
- package/dist/cjs/DPolygonLoop.js +401 -0
- package/dist/{FastSearch.d.ts → cjs/FastSearch.d.ts} +0 -0
- package/dist/cjs/FastSearch.js +53 -0
- package/dist/{TraceMatrix.d.ts → cjs/TraceMatrix.d.ts} +0 -0
- package/dist/cjs/TraceMatrix.js +256 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/{index.js → cjs/index.js} +5 -1
- package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
- package/dist/cjs/utils.js +216 -0
- package/dist/{DCircle.js → es2015/DCircle.js} +14 -18
- package/dist/{DLine.js → es2015/DLine.js} +24 -28
- package/dist/es2015/DNumbers.js +22 -0
- package/dist/{DPlane.js → es2015/DPlane.js} +22 -26
- package/dist/{DPoint.js → es2015/DPoint.js} +91 -56
- package/dist/{DPolygon.js → es2015/DPolygon.js} +41 -45
- package/dist/{DPolygonLoop.js → es2015/DPolygonLoop.js} +1 -5
- package/dist/{FastSearch.js → es2015/FastSearch.js} +1 -5
- package/dist/{TraceMatrix.js → es2015/TraceMatrix.js} +35 -39
- package/dist/es2015/index.js +10 -0
- package/dist/{utils.js → es2015/utils.js} +29 -41
- package/dist/esm/DCircle.js +1 -1
- package/dist/esm/DLine.js +2 -2
- package/dist/esm/DPoint.js +42 -2
- package/dist/esm/DPolygon.js +7 -7
- package/dist/esm/utils.js +6 -6
- package/dist/umd/dgeoutils.js +59 -19
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +9 -13
- package/dist/DNumbers.js +0 -26
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const DNumbers_1 = require("./DNumbers");
|
|
7
|
-
class DLine {
|
|
8
|
-
constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()) {
|
|
1
|
+
import { DPoint } from './DPoint';
|
|
2
|
+
import { checkFunction } from './utils';
|
|
3
|
+
import { DNumbers } from './DNumbers';
|
|
4
|
+
export class DLine {
|
|
5
|
+
constructor(a, b, c, begin = DPoint.zero(), end = DPoint.zero()) {
|
|
9
6
|
this.a = a;
|
|
10
7
|
this.b = b;
|
|
11
8
|
this.c = c;
|
|
@@ -16,7 +13,7 @@ class DLine {
|
|
|
16
13
|
return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
|
|
17
14
|
}
|
|
18
15
|
findPerpendicular(p) {
|
|
19
|
-
|
|
16
|
+
checkFunction('findPerpendicular')
|
|
20
17
|
.checkArgument('this.begin')
|
|
21
18
|
.shouldBeMeters(this.begin)
|
|
22
19
|
.checkArgument('this.end')
|
|
@@ -26,7 +23,7 @@ class DLine {
|
|
|
26
23
|
return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
|
|
27
24
|
}
|
|
28
25
|
perpendicularDistance(p) {
|
|
29
|
-
|
|
26
|
+
checkFunction('perpendicularDistance')
|
|
30
27
|
.checkArgument('this.begin')
|
|
31
28
|
.shouldBeMeters(this.begin)
|
|
32
29
|
.checkArgument('this.end')
|
|
@@ -140,21 +137,21 @@ class DLine {
|
|
|
140
137
|
}
|
|
141
138
|
x(p) {
|
|
142
139
|
if (this.isParallelY) {
|
|
143
|
-
return new
|
|
140
|
+
return new DPoint(-this.c / this.a, p.y);
|
|
144
141
|
}
|
|
145
142
|
if (this.isParallelX) {
|
|
146
|
-
return new
|
|
143
|
+
return new DPoint(p.x, -this.c / this.b);
|
|
147
144
|
}
|
|
148
|
-
return new
|
|
145
|
+
return new DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
|
|
149
146
|
}
|
|
150
147
|
y(p) {
|
|
151
148
|
if (this.isParallelY) {
|
|
152
|
-
return new
|
|
149
|
+
return new DPoint(-this.c / this.a, p.y);
|
|
153
150
|
}
|
|
154
151
|
if (this.isParallelX) {
|
|
155
|
-
return new
|
|
152
|
+
return new DPoint(p.x, -this.c / this.b);
|
|
156
153
|
}
|
|
157
|
-
return new
|
|
154
|
+
return new DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
|
|
158
155
|
}
|
|
159
156
|
findPoint(l) {
|
|
160
157
|
if (this.isParallelY && l.isParallelY) {
|
|
@@ -164,28 +161,28 @@ class DLine {
|
|
|
164
161
|
return null;
|
|
165
162
|
}
|
|
166
163
|
if (this.isParallelX && l.isParallelY) {
|
|
167
|
-
return new
|
|
164
|
+
return new DPoint(-l.c / l.a, -this.c / this.b);
|
|
168
165
|
}
|
|
169
166
|
if (this.isParallelY && l.isParallelX) {
|
|
170
|
-
return new
|
|
167
|
+
return new DPoint(-this.c / this.a, -l.c / l.b);
|
|
171
168
|
}
|
|
172
169
|
if (this.isParallelY) {
|
|
173
170
|
const x = -this.c / this.a;
|
|
174
|
-
return l.y(new
|
|
171
|
+
return l.y(new DPoint(x));
|
|
175
172
|
}
|
|
176
173
|
if (this.isParallelX) {
|
|
177
174
|
const y = -this.c / this.b;
|
|
178
|
-
return l.x(new
|
|
175
|
+
return l.x(new DPoint(0, y));
|
|
179
176
|
}
|
|
180
177
|
if (l.isParallelY) {
|
|
181
178
|
const x = -l.c / l.a;
|
|
182
|
-
return this.y(new
|
|
179
|
+
return this.y(new DPoint(x));
|
|
183
180
|
}
|
|
184
181
|
if (l.isParallelX) {
|
|
185
182
|
const y = -l.c / l.b;
|
|
186
|
-
return this.x(new
|
|
183
|
+
return this.x(new DPoint(0, y));
|
|
187
184
|
}
|
|
188
|
-
const res = this.y(new
|
|
185
|
+
const res = this.y(new DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
|
|
189
186
|
if (!isFinite(res.x) && !isFinite(res.y)) {
|
|
190
187
|
return null;
|
|
191
188
|
}
|
|
@@ -204,7 +201,7 @@ class DLine {
|
|
|
204
201
|
return [this.begin, this.end];
|
|
205
202
|
}
|
|
206
203
|
getFi() {
|
|
207
|
-
|
|
204
|
+
checkFunction('getFi')
|
|
208
205
|
.checkArgument('this.begin')
|
|
209
206
|
.shouldBeMeters(this.begin)
|
|
210
207
|
.checkArgument('this.end')
|
|
@@ -225,13 +222,13 @@ class DLine {
|
|
|
225
222
|
const p = isArray ? i : [i];
|
|
226
223
|
const d = (isArray ? k : [k]);
|
|
227
224
|
const fi = this.findFi(new DLine(1, 0, 0));
|
|
228
|
-
const td = this.x(new
|
|
229
|
-
const sinCos = new
|
|
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));
|
|
230
227
|
const dt = sinCos.clone().scale(td);
|
|
231
228
|
const p1T = p[0].clone().move(dt.clone().minus());
|
|
232
229
|
const p2T = p[0].clone().move(dt);
|
|
233
230
|
let res = [];
|
|
234
|
-
if (
|
|
231
|
+
if (DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers.like(this.y(p2T).y, p2T.y)) {
|
|
235
232
|
res = p.map((t, index) => t.clone()
|
|
236
233
|
.move(sinCos.clone().scale(d[index])));
|
|
237
234
|
}
|
|
@@ -258,4 +255,3 @@ class DLine {
|
|
|
258
255
|
return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
|
-
exports.DLine = DLine;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DEGREE_TO_PI, DOUBLE_PI_IN_DEGREE, PI_IN_DEGREE, PI_TO_DEGREE } from './DPoint';
|
|
2
|
+
const delta = 0.001;
|
|
3
|
+
export class DNumbers {
|
|
4
|
+
static like(v, s, d = delta) {
|
|
5
|
+
return Math.abs(v - s) < d;
|
|
6
|
+
}
|
|
7
|
+
static likeZero(v) {
|
|
8
|
+
return DNumbers.like(v, 0);
|
|
9
|
+
}
|
|
10
|
+
static like2PI(v) {
|
|
11
|
+
return DNumbers.like(DNumbers.rad2Deg(v), DOUBLE_PI_IN_DEGREE);
|
|
12
|
+
}
|
|
13
|
+
static likePI(v) {
|
|
14
|
+
return DNumbers.like(DNumbers.rad2Deg(v), PI_IN_DEGREE);
|
|
15
|
+
}
|
|
16
|
+
static rad2Deg(v) {
|
|
17
|
+
return v * DEGREE_TO_PI;
|
|
18
|
+
}
|
|
19
|
+
static deg2Rad(v) {
|
|
20
|
+
return v * PI_TO_DEGREE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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()) {
|
|
1
|
+
import { DPoint } from './DPoint';
|
|
2
|
+
import { gaussianElimination } from './utils';
|
|
3
|
+
import { DNumbers } from './DNumbers';
|
|
4
|
+
export class DPlane {
|
|
5
|
+
constructor(a, b, c, d, p1 = DPoint.zero(), p2 = DPoint.zero(), p3 = DPoint.zero()) {
|
|
9
6
|
this.a = a;
|
|
10
7
|
this.b = b;
|
|
11
8
|
this.c = c;
|
|
@@ -25,7 +22,7 @@ class DPlane {
|
|
|
25
22
|
return new DPlane(0, 0, 1, -p1.z, p1, p2, p3);
|
|
26
23
|
}
|
|
27
24
|
const d = 1;
|
|
28
|
-
const [a, b, c] =
|
|
25
|
+
const [a, b, c] = gaussianElimination([
|
|
29
26
|
[p1.x, p1.y, p1.z, -d],
|
|
30
27
|
[p2.x, p2.y, p2.z, -d],
|
|
31
28
|
[p3.x, p3.y, p3.z, -d]
|
|
@@ -33,7 +30,7 @@ class DPlane {
|
|
|
33
30
|
return new DPlane(a, b, c, d, p1, p2, p3);
|
|
34
31
|
}
|
|
35
32
|
x(p) {
|
|
36
|
-
if (p instanceof
|
|
33
|
+
if (p instanceof DPoint) {
|
|
37
34
|
const { a, b, c, d } = this;
|
|
38
35
|
const { y, z } = p;
|
|
39
36
|
p.x = -(b * y + c * z + d) / a;
|
|
@@ -42,7 +39,7 @@ class DPlane {
|
|
|
42
39
|
return p.map((t) => this.x(t));
|
|
43
40
|
}
|
|
44
41
|
y(p) {
|
|
45
|
-
if (p instanceof
|
|
42
|
+
if (p instanceof DPoint) {
|
|
46
43
|
const { a, b, c, d } = this;
|
|
47
44
|
const { x, z } = p;
|
|
48
45
|
p.y = -(a * x + c * z + d) / b;
|
|
@@ -51,7 +48,7 @@ class DPlane {
|
|
|
51
48
|
return p.map((t) => this.y(t));
|
|
52
49
|
}
|
|
53
50
|
z(p) {
|
|
54
|
-
if (p instanceof
|
|
51
|
+
if (p instanceof DPoint) {
|
|
55
52
|
const { a, b, c, d } = this;
|
|
56
53
|
const { x, y } = p;
|
|
57
54
|
p.z = -(a * x + b * y + d) / c;
|
|
@@ -64,7 +61,7 @@ class DPlane {
|
|
|
64
61
|
return new DPlane(a, b, c, d, p1, p2, p3);
|
|
65
62
|
}
|
|
66
63
|
distance(p) {
|
|
67
|
-
if (p instanceof
|
|
64
|
+
if (p instanceof DPoint) {
|
|
68
65
|
const { x, y, z } = p;
|
|
69
66
|
const { a, b, c, d } = this;
|
|
70
67
|
return Math.abs(a * x + b * y + c * z + d) / Math.sqrt(a * a + b * b + c * c);
|
|
@@ -76,10 +73,10 @@ class DPlane {
|
|
|
76
73
|
equal(p) {
|
|
77
74
|
const { a, b, c, d } = p;
|
|
78
75
|
const { a: q, b: w, c: e, d: r } = this;
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
return DNumbers.like(a, q) &&
|
|
77
|
+
DNumbers.like(b, w) &&
|
|
78
|
+
DNumbers.like(c, e) &&
|
|
79
|
+
DNumbers.like(d, r);
|
|
83
80
|
}
|
|
84
81
|
same(p) {
|
|
85
82
|
const { a, b, c, d } = p;
|
|
@@ -88,10 +85,10 @@ class DPlane {
|
|
|
88
85
|
const y = b / w;
|
|
89
86
|
const u = c / e;
|
|
90
87
|
const i = d / r;
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
return DNumbers.like(t, y) &&
|
|
89
|
+
DNumbers.like(t, u) &&
|
|
90
|
+
DNumbers.like(t, c) &&
|
|
91
|
+
DNumbers.like(t, i);
|
|
95
92
|
}
|
|
96
93
|
parallel(p) {
|
|
97
94
|
const { a, b, c, d } = p;
|
|
@@ -100,10 +97,9 @@ class DPlane {
|
|
|
100
97
|
const y = b / w;
|
|
101
98
|
const u = c / e;
|
|
102
99
|
const i = d / r;
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
!
|
|
100
|
+
return DNumbers.like(t, y) &&
|
|
101
|
+
DNumbers.like(t, u) &&
|
|
102
|
+
DNumbers.like(t, c) &&
|
|
103
|
+
!DNumbers.like(t, i);
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
|
-
exports.DPlane = DPlane;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const DLine_1 = require("./DLine");
|
|
5
|
-
const DPolygon_1 = require("./DPolygon");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { DLine } from './DLine';
|
|
2
|
+
import { DPolygon } from './DPolygon';
|
|
3
|
+
import { checkFunction, createArray, isDefAndNotNull } from './utils';
|
|
7
4
|
const diff = 0;
|
|
8
|
-
const radiansPolygon = new
|
|
9
|
-
const pseudoMercatorPolygon = new
|
|
10
|
-
const worldGeodeticPolygon = new
|
|
11
|
-
|
|
5
|
+
const radiansPolygon = new DPolygon();
|
|
6
|
+
const pseudoMercatorPolygon = new DPolygon();
|
|
7
|
+
const worldGeodeticPolygon = new DPolygon();
|
|
8
|
+
export const EARTH_RADIUS_IN_METERS = 6371008.8;
|
|
12
9
|
const EARTH_IN_MITERS = 20037508.34;
|
|
13
10
|
const DEGREES_IN_EARTH = 180;
|
|
14
11
|
const MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
|
|
15
12
|
const DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class DPoint {
|
|
13
|
+
export const HALF_PI_IN_DEGREE = 90;
|
|
14
|
+
export const PI_IN_DEGREE = 180;
|
|
15
|
+
export const DOUBLE_PI_IN_DEGREE = 360;
|
|
16
|
+
export const PI_TO_DEGREE = Math.PI / PI_IN_DEGREE;
|
|
17
|
+
export const DEGREE_TO_PI = PI_IN_DEGREE / Math.PI;
|
|
18
|
+
export class DPoint {
|
|
22
19
|
constructor(x = 0, y = x, z) {
|
|
23
20
|
this.x = x;
|
|
24
21
|
this.y = y;
|
|
@@ -46,21 +43,60 @@ class DPoint {
|
|
|
46
43
|
static random() {
|
|
47
44
|
return new DPoint(Math.random(), Math.random());
|
|
48
45
|
}
|
|
46
|
+
static getTileFromQuadKey(quadKey) {
|
|
47
|
+
const p = new DPoint(0, 0, quadKey.length);
|
|
48
|
+
for (let i = p.z; i > 0; i--) {
|
|
49
|
+
const mask = 1 << (i - 1);
|
|
50
|
+
switch (quadKey[p.z - i]) {
|
|
51
|
+
case '0':
|
|
52
|
+
break;
|
|
53
|
+
case '1':
|
|
54
|
+
p.x |= mask;
|
|
55
|
+
break;
|
|
56
|
+
case '2':
|
|
57
|
+
p.y |= mask;
|
|
58
|
+
break;
|
|
59
|
+
case '3':
|
|
60
|
+
p.x |= mask;
|
|
61
|
+
p.y |= mask;
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
throw new Error('Invalid QuadKey digit sequence.');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return p;
|
|
68
|
+
}
|
|
49
69
|
getTileFromCoords(zoom = this.z) {
|
|
50
|
-
|
|
70
|
+
checkFunction('getTileFromCoords')
|
|
51
71
|
.checkArgument('this')
|
|
52
72
|
.shouldBeDegree(this);
|
|
53
|
-
const x = Math.floor((this.x +
|
|
54
|
-
const y = Math.floor((1 - Math.log(Math.tan(this.y *
|
|
73
|
+
const x = Math.floor((this.x + PI_IN_DEGREE) / DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
|
|
74
|
+
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)));
|
|
55
75
|
return new DPoint(x, y, zoom);
|
|
56
76
|
}
|
|
77
|
+
getQuadKeyFromTile(zoom = this.z) {
|
|
78
|
+
const quadKey = [];
|
|
79
|
+
for (let i = zoom; i > 0; i--) {
|
|
80
|
+
let digit = 0;
|
|
81
|
+
const mask = 1 << (i - 1);
|
|
82
|
+
if ((this.x & mask) !== 0) {
|
|
83
|
+
digit++;
|
|
84
|
+
}
|
|
85
|
+
if ((this.y & mask) !== 0) {
|
|
86
|
+
digit++;
|
|
87
|
+
digit++;
|
|
88
|
+
}
|
|
89
|
+
quadKey.push(digit);
|
|
90
|
+
}
|
|
91
|
+
return quadKey.join('');
|
|
92
|
+
}
|
|
57
93
|
getCoordsFromTile(zoom = this.z) {
|
|
58
|
-
|
|
94
|
+
checkFunction('getCoordsFromTile')
|
|
59
95
|
.checkArgument('this')
|
|
60
96
|
.shouldBeUInt(this);
|
|
61
97
|
const n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
|
|
62
|
-
const x = this.x / (Math.pow(2, zoom)) *
|
|
63
|
-
const y =
|
|
98
|
+
const x = this.x / (Math.pow(2, zoom)) * DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE;
|
|
99
|
+
const y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
64
100
|
return new DPoint(x, y, zoom);
|
|
65
101
|
}
|
|
66
102
|
toCoords() {
|
|
@@ -70,7 +106,7 @@ class DPoint {
|
|
|
70
106
|
return [this.x, this.y, this.z];
|
|
71
107
|
}
|
|
72
108
|
findLine(p) {
|
|
73
|
-
|
|
109
|
+
checkFunction('findLine')
|
|
74
110
|
.checkArgument('this')
|
|
75
111
|
.shouldBeMeters(this)
|
|
76
112
|
.checkArgument('p')
|
|
@@ -82,15 +118,15 @@ class DPoint {
|
|
|
82
118
|
const b = p.x - this.x - diff;
|
|
83
119
|
const c = this.x * p.y - p.x * this.y - diff;
|
|
84
120
|
if (a === 0) {
|
|
85
|
-
return new
|
|
121
|
+
return new DLine(0, 1, c / b, this, p);
|
|
86
122
|
}
|
|
87
123
|
if (b === 0) {
|
|
88
|
-
return new
|
|
124
|
+
return new DLine(1, 0, c / a, this, p);
|
|
89
125
|
}
|
|
90
|
-
return new
|
|
126
|
+
return new DLine(a, b, c, this, p);
|
|
91
127
|
}
|
|
92
128
|
findInnerAngle(p1, p3) {
|
|
93
|
-
|
|
129
|
+
checkFunction('findInnerAngle')
|
|
94
130
|
.checkArgument('this')
|
|
95
131
|
.shouldBeMeters(this)
|
|
96
132
|
.checkArgument('p1')
|
|
@@ -119,7 +155,7 @@ class DPoint {
|
|
|
119
155
|
return `POINT (${x} ${y})`;
|
|
120
156
|
}
|
|
121
157
|
distance(p) {
|
|
122
|
-
|
|
158
|
+
checkFunction('distance')
|
|
123
159
|
.checkArgument('this')
|
|
124
160
|
.shouldBeMeters(this)
|
|
125
161
|
.checkArgument('p')
|
|
@@ -129,7 +165,7 @@ class DPoint {
|
|
|
129
165
|
return Math.sqrt(dx * dx + dy * dy);
|
|
130
166
|
}
|
|
131
167
|
distance3d(p) {
|
|
132
|
-
|
|
168
|
+
checkFunction('distance3d')
|
|
133
169
|
.checkArgument('this')
|
|
134
170
|
.shouldBeMeters(this)
|
|
135
171
|
.checkArgument('p')
|
|
@@ -204,66 +240,66 @@ class DPoint {
|
|
|
204
240
|
if (x instanceof DPoint) {
|
|
205
241
|
xV = this.x + x.x;
|
|
206
242
|
yV = this.y + x.y;
|
|
207
|
-
if (
|
|
243
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
208
244
|
zV = this.z + x.z;
|
|
209
245
|
}
|
|
210
246
|
}
|
|
211
247
|
else {
|
|
212
248
|
xV = this.x + x;
|
|
213
249
|
yV = this.y + y;
|
|
214
|
-
if (
|
|
250
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
215
251
|
zV = this.z + z;
|
|
216
252
|
}
|
|
217
253
|
}
|
|
218
254
|
this.x = xV;
|
|
219
255
|
this.y = yV;
|
|
220
|
-
if (
|
|
256
|
+
if (isDefAndNotNull(zV)) {
|
|
221
257
|
this.z = zV;
|
|
222
258
|
}
|
|
223
259
|
return this;
|
|
224
260
|
}
|
|
225
261
|
degreeToMeters() {
|
|
226
|
-
|
|
262
|
+
checkFunction('degreeToMeters')
|
|
227
263
|
.checkArgument('this')
|
|
228
264
|
.shouldBeDegree(this);
|
|
229
|
-
const x = ((this.x +
|
|
230
|
-
const y = (Math.log(Math.tan(((this.y +
|
|
231
|
-
(Math.PI /
|
|
265
|
+
const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
266
|
+
const y = (Math.log(Math.tan(((this.y + HALF_PI_IN_DEGREE) % PI_IN_DEGREE) *
|
|
267
|
+
(Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
232
268
|
this.x = x;
|
|
233
269
|
this.y = y;
|
|
234
270
|
return this;
|
|
235
271
|
}
|
|
236
272
|
metersToDegree() {
|
|
237
|
-
|
|
273
|
+
checkFunction('metersToDegree')
|
|
238
274
|
.checkArgument('this')
|
|
239
275
|
.shouldBeMeters(this);
|
|
240
276
|
const lon = this.x * DEGREES_IN_ONE_MITER;
|
|
241
|
-
const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) *
|
|
242
|
-
(
|
|
277
|
+
const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * PI_TO_DEGREE))) *
|
|
278
|
+
(DOUBLE_PI_IN_DEGREE / Math.PI) - HALF_PI_IN_DEGREE;
|
|
243
279
|
this.x = lon;
|
|
244
280
|
this.y = lat;
|
|
245
281
|
return this;
|
|
246
282
|
}
|
|
247
283
|
degreeToRadians() {
|
|
248
|
-
|
|
284
|
+
checkFunction('degreeToRadians')
|
|
249
285
|
.checkArgument('this')
|
|
250
286
|
.shouldBeDegree(this);
|
|
251
|
-
return this.scale(
|
|
287
|
+
return this.scale(PI_TO_DEGREE);
|
|
252
288
|
}
|
|
253
289
|
radiansToDegrees() {
|
|
254
|
-
|
|
290
|
+
checkFunction('radiansToDegrees')
|
|
255
291
|
.checkArgument('this')
|
|
256
292
|
.shouldBeRadians(this);
|
|
257
|
-
return this.scale(
|
|
293
|
+
return this.scale(DEGREE_TO_PI);
|
|
258
294
|
}
|
|
259
295
|
radiansToMeters() {
|
|
260
|
-
|
|
296
|
+
checkFunction('radiansToMeters')
|
|
261
297
|
.checkArgument('this')
|
|
262
298
|
.shouldBeRadians(this);
|
|
263
299
|
return this.radiansToDegrees().degreeToMeters();
|
|
264
300
|
}
|
|
265
301
|
metersToRadians() {
|
|
266
|
-
|
|
302
|
+
checkFunction('metersToRadians')
|
|
267
303
|
.checkArgument('this')
|
|
268
304
|
.shouldBeMeters(this);
|
|
269
305
|
return this.metersToDegree().degreeToRadians();
|
|
@@ -300,20 +336,20 @@ class DPoint {
|
|
|
300
336
|
if (x instanceof DPoint) {
|
|
301
337
|
xV = this.x * x.x;
|
|
302
338
|
yV = this.y * x.y;
|
|
303
|
-
if (
|
|
339
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
304
340
|
zV = this.z * x.z;
|
|
305
341
|
}
|
|
306
342
|
}
|
|
307
343
|
else {
|
|
308
344
|
xV = this.x * x;
|
|
309
345
|
yV = this.y * y;
|
|
310
|
-
if (
|
|
346
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
311
347
|
zV = this.z * z;
|
|
312
348
|
}
|
|
313
349
|
}
|
|
314
350
|
this.x = xV;
|
|
315
351
|
this.y = yV;
|
|
316
|
-
if (
|
|
352
|
+
if (isDefAndNotNull(zV)) {
|
|
317
353
|
this.z = zV;
|
|
318
354
|
}
|
|
319
355
|
return this;
|
|
@@ -325,20 +361,20 @@ class DPoint {
|
|
|
325
361
|
if (x instanceof DPoint) {
|
|
326
362
|
xV = this.x / x.x;
|
|
327
363
|
yV = this.y / x.y;
|
|
328
|
-
if (
|
|
364
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
329
365
|
zV = this.z / x.z;
|
|
330
366
|
}
|
|
331
367
|
}
|
|
332
368
|
else {
|
|
333
369
|
xV = this.x / x;
|
|
334
370
|
yV = this.y / y;
|
|
335
|
-
if (
|
|
371
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
336
372
|
zV = this.z / z;
|
|
337
373
|
}
|
|
338
374
|
}
|
|
339
375
|
this.x = xV;
|
|
340
376
|
this.y = yV;
|
|
341
|
-
if (
|
|
377
|
+
if (isDefAndNotNull(zV)) {
|
|
342
378
|
this.z = zV;
|
|
343
379
|
}
|
|
344
380
|
return this;
|
|
@@ -395,13 +431,13 @@ class DPoint {
|
|
|
395
431
|
this.y = y;
|
|
396
432
|
}
|
|
397
433
|
get area() {
|
|
398
|
-
|
|
434
|
+
checkFunction('area')
|
|
399
435
|
.checkArgument('this')
|
|
400
436
|
.shouldBeMeters(this);
|
|
401
437
|
return this.w * this.h;
|
|
402
438
|
}
|
|
403
439
|
get hip() {
|
|
404
|
-
|
|
440
|
+
checkFunction('hip')
|
|
405
441
|
.checkArgument('this')
|
|
406
442
|
.shouldBeMeters(this);
|
|
407
443
|
return Math.sqrt(this.w * this.w + this.h * this.h);
|
|
@@ -445,7 +481,7 @@ class DPoint {
|
|
|
445
481
|
return this.scale(-1);
|
|
446
482
|
}
|
|
447
483
|
orthodromicPath(point, pointsCount = 360) {
|
|
448
|
-
|
|
484
|
+
checkFunction('orthodromicPath')
|
|
449
485
|
.checkArgument('this')
|
|
450
486
|
.shouldBeDegree(this)
|
|
451
487
|
.checkArgument('point')
|
|
@@ -454,7 +490,7 @@ class DPoint {
|
|
|
454
490
|
const p = point.clone().degreeToRadians();
|
|
455
491
|
const d = Math.sin(p.x - t.x);
|
|
456
492
|
const step = (p.x - t.x) / (pointsCount - 1);
|
|
457
|
-
return new
|
|
493
|
+
return new DPolygon(createArray(pointsCount)
|
|
458
494
|
.map((v, i) => {
|
|
459
495
|
const x = t.x + step * i;
|
|
460
496
|
const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
|
|
@@ -473,4 +509,3 @@ class DPoint {
|
|
|
473
509
|
.sort((a, b) => a.properties.distance - b.properties.distance);
|
|
474
510
|
}
|
|
475
511
|
}
|
|
476
|
-
exports.DPoint = DPoint;
|