dgeoutils 2.2.24 → 2.3.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/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 +300 -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} +0 -0
- package/dist/cjs/DPoint.js +574 -0
- package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +0 -0
- package/dist/cjs/DPolygon.js +1555 -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} +0 -0
- package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
- package/dist/cjs/utils.js +191 -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} +52 -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 +13 -0
- package/dist/{utils.js → es2015/utils.js} +26 -36
- package/dist/esm/DCircle.js +99 -0
- package/dist/esm/DLine.js +297 -0
- package/dist/esm/DNumbers.js +27 -0
- package/dist/esm/DPlane.js +129 -0
- package/dist/esm/DPoint.js +571 -0
- package/dist/esm/DPolygon.js +1552 -0
- package/dist/esm/DPolygonLoop.js +398 -0
- package/dist/esm/FastSearch.js +50 -0
- package/dist/esm/TraceMatrix.js +253 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/utils.js +181 -0
- package/dist/umd/dgeoutils.js +3569 -0
- package/dist/umd/dgeoutils.min.js +1 -0
- package/dist/umd/dgeoutils.min.js.map +1 -0
- package/package.json +17 -10
- package/dist/DNumbers.js +0 -26
|
@@ -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;
|
|
@@ -47,20 +44,20 @@ class DPoint {
|
|
|
47
44
|
return new DPoint(Math.random(), Math.random());
|
|
48
45
|
}
|
|
49
46
|
getTileFromCoords(zoom = this.z) {
|
|
50
|
-
|
|
47
|
+
checkFunction('getTileFromCoords')
|
|
51
48
|
.checkArgument('this')
|
|
52
49
|
.shouldBeDegree(this);
|
|
53
|
-
const x = Math.floor((this.x +
|
|
54
|
-
const y = Math.floor((1 - Math.log(Math.tan(this.y *
|
|
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)));
|
|
55
52
|
return new DPoint(x, y, zoom);
|
|
56
53
|
}
|
|
57
54
|
getCoordsFromTile(zoom = this.z) {
|
|
58
|
-
|
|
55
|
+
checkFunction('getCoordsFromTile')
|
|
59
56
|
.checkArgument('this')
|
|
60
57
|
.shouldBeUInt(this);
|
|
61
58
|
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 =
|
|
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);
|
|
64
61
|
return new DPoint(x, y, zoom);
|
|
65
62
|
}
|
|
66
63
|
toCoords() {
|
|
@@ -70,7 +67,7 @@ class DPoint {
|
|
|
70
67
|
return [this.x, this.y, this.z];
|
|
71
68
|
}
|
|
72
69
|
findLine(p) {
|
|
73
|
-
|
|
70
|
+
checkFunction('findLine')
|
|
74
71
|
.checkArgument('this')
|
|
75
72
|
.shouldBeMeters(this)
|
|
76
73
|
.checkArgument('p')
|
|
@@ -82,15 +79,15 @@ class DPoint {
|
|
|
82
79
|
const b = p.x - this.x - diff;
|
|
83
80
|
const c = this.x * p.y - p.x * this.y - diff;
|
|
84
81
|
if (a === 0) {
|
|
85
|
-
return new
|
|
82
|
+
return new DLine(0, 1, c / b, this, p);
|
|
86
83
|
}
|
|
87
84
|
if (b === 0) {
|
|
88
|
-
return new
|
|
85
|
+
return new DLine(1, 0, c / a, this, p);
|
|
89
86
|
}
|
|
90
|
-
return new
|
|
87
|
+
return new DLine(a, b, c, this, p);
|
|
91
88
|
}
|
|
92
89
|
findInnerAngle(p1, p3) {
|
|
93
|
-
|
|
90
|
+
checkFunction('findInnerAngle')
|
|
94
91
|
.checkArgument('this')
|
|
95
92
|
.shouldBeMeters(this)
|
|
96
93
|
.checkArgument('p1')
|
|
@@ -119,7 +116,7 @@ class DPoint {
|
|
|
119
116
|
return `POINT (${x} ${y})`;
|
|
120
117
|
}
|
|
121
118
|
distance(p) {
|
|
122
|
-
|
|
119
|
+
checkFunction('distance')
|
|
123
120
|
.checkArgument('this')
|
|
124
121
|
.shouldBeMeters(this)
|
|
125
122
|
.checkArgument('p')
|
|
@@ -129,7 +126,7 @@ class DPoint {
|
|
|
129
126
|
return Math.sqrt(dx * dx + dy * dy);
|
|
130
127
|
}
|
|
131
128
|
distance3d(p) {
|
|
132
|
-
|
|
129
|
+
checkFunction('distance3d')
|
|
133
130
|
.checkArgument('this')
|
|
134
131
|
.shouldBeMeters(this)
|
|
135
132
|
.checkArgument('p')
|
|
@@ -204,66 +201,66 @@ class DPoint {
|
|
|
204
201
|
if (x instanceof DPoint) {
|
|
205
202
|
xV = this.x + x.x;
|
|
206
203
|
yV = this.y + x.y;
|
|
207
|
-
if (
|
|
204
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
208
205
|
zV = this.z + x.z;
|
|
209
206
|
}
|
|
210
207
|
}
|
|
211
208
|
else {
|
|
212
209
|
xV = this.x + x;
|
|
213
210
|
yV = this.y + y;
|
|
214
|
-
if (
|
|
211
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
215
212
|
zV = this.z + z;
|
|
216
213
|
}
|
|
217
214
|
}
|
|
218
215
|
this.x = xV;
|
|
219
216
|
this.y = yV;
|
|
220
|
-
if (
|
|
217
|
+
if (isDefAndNotNull(zV)) {
|
|
221
218
|
this.z = zV;
|
|
222
219
|
}
|
|
223
220
|
return this;
|
|
224
221
|
}
|
|
225
222
|
degreeToMeters() {
|
|
226
|
-
|
|
223
|
+
checkFunction('degreeToMeters')
|
|
227
224
|
.checkArgument('this')
|
|
228
225
|
.shouldBeDegree(this);
|
|
229
|
-
const x = ((this.x +
|
|
230
|
-
const y = (Math.log(Math.tan(((this.y +
|
|
231
|
-
(Math.PI /
|
|
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;
|
|
232
229
|
this.x = x;
|
|
233
230
|
this.y = y;
|
|
234
231
|
return this;
|
|
235
232
|
}
|
|
236
233
|
metersToDegree() {
|
|
237
|
-
|
|
234
|
+
checkFunction('metersToDegree')
|
|
238
235
|
.checkArgument('this')
|
|
239
236
|
.shouldBeMeters(this);
|
|
240
237
|
const lon = this.x * DEGREES_IN_ONE_MITER;
|
|
241
|
-
const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) *
|
|
242
|
-
(
|
|
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;
|
|
243
240
|
this.x = lon;
|
|
244
241
|
this.y = lat;
|
|
245
242
|
return this;
|
|
246
243
|
}
|
|
247
244
|
degreeToRadians() {
|
|
248
|
-
|
|
245
|
+
checkFunction('degreeToRadians')
|
|
249
246
|
.checkArgument('this')
|
|
250
247
|
.shouldBeDegree(this);
|
|
251
|
-
return this.scale(
|
|
248
|
+
return this.scale(PI_TO_DEGREE);
|
|
252
249
|
}
|
|
253
250
|
radiansToDegrees() {
|
|
254
|
-
|
|
251
|
+
checkFunction('radiansToDegrees')
|
|
255
252
|
.checkArgument('this')
|
|
256
253
|
.shouldBeRadians(this);
|
|
257
|
-
return this.scale(
|
|
254
|
+
return this.scale(DEGREE_TO_PI);
|
|
258
255
|
}
|
|
259
256
|
radiansToMeters() {
|
|
260
|
-
|
|
257
|
+
checkFunction('radiansToMeters')
|
|
261
258
|
.checkArgument('this')
|
|
262
259
|
.shouldBeRadians(this);
|
|
263
260
|
return this.radiansToDegrees().degreeToMeters();
|
|
264
261
|
}
|
|
265
262
|
metersToRadians() {
|
|
266
|
-
|
|
263
|
+
checkFunction('metersToRadians')
|
|
267
264
|
.checkArgument('this')
|
|
268
265
|
.shouldBeMeters(this);
|
|
269
266
|
return this.metersToDegree().degreeToRadians();
|
|
@@ -300,20 +297,20 @@ class DPoint {
|
|
|
300
297
|
if (x instanceof DPoint) {
|
|
301
298
|
xV = this.x * x.x;
|
|
302
299
|
yV = this.y * x.y;
|
|
303
|
-
if (
|
|
300
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
304
301
|
zV = this.z * x.z;
|
|
305
302
|
}
|
|
306
303
|
}
|
|
307
304
|
else {
|
|
308
305
|
xV = this.x * x;
|
|
309
306
|
yV = this.y * y;
|
|
310
|
-
if (
|
|
307
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
311
308
|
zV = this.z * z;
|
|
312
309
|
}
|
|
313
310
|
}
|
|
314
311
|
this.x = xV;
|
|
315
312
|
this.y = yV;
|
|
316
|
-
if (
|
|
313
|
+
if (isDefAndNotNull(zV)) {
|
|
317
314
|
this.z = zV;
|
|
318
315
|
}
|
|
319
316
|
return this;
|
|
@@ -325,20 +322,20 @@ class DPoint {
|
|
|
325
322
|
if (x instanceof DPoint) {
|
|
326
323
|
xV = this.x / x.x;
|
|
327
324
|
yV = this.y / x.y;
|
|
328
|
-
if (
|
|
325
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
|
|
329
326
|
zV = this.z / x.z;
|
|
330
327
|
}
|
|
331
328
|
}
|
|
332
329
|
else {
|
|
333
330
|
xV = this.x / x;
|
|
334
331
|
yV = this.y / y;
|
|
335
|
-
if (
|
|
332
|
+
if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
|
|
336
333
|
zV = this.z / z;
|
|
337
334
|
}
|
|
338
335
|
}
|
|
339
336
|
this.x = xV;
|
|
340
337
|
this.y = yV;
|
|
341
|
-
if (
|
|
338
|
+
if (isDefAndNotNull(zV)) {
|
|
342
339
|
this.z = zV;
|
|
343
340
|
}
|
|
344
341
|
return this;
|
|
@@ -395,13 +392,13 @@ class DPoint {
|
|
|
395
392
|
this.y = y;
|
|
396
393
|
}
|
|
397
394
|
get area() {
|
|
398
|
-
|
|
395
|
+
checkFunction('area')
|
|
399
396
|
.checkArgument('this')
|
|
400
397
|
.shouldBeMeters(this);
|
|
401
398
|
return this.w * this.h;
|
|
402
399
|
}
|
|
403
400
|
get hip() {
|
|
404
|
-
|
|
401
|
+
checkFunction('hip')
|
|
405
402
|
.checkArgument('this')
|
|
406
403
|
.shouldBeMeters(this);
|
|
407
404
|
return Math.sqrt(this.w * this.w + this.h * this.h);
|
|
@@ -445,7 +442,7 @@ class DPoint {
|
|
|
445
442
|
return this.scale(-1);
|
|
446
443
|
}
|
|
447
444
|
orthodromicPath(point, pointsCount = 360) {
|
|
448
|
-
|
|
445
|
+
checkFunction('orthodromicPath')
|
|
449
446
|
.checkArgument('this')
|
|
450
447
|
.shouldBeDegree(this)
|
|
451
448
|
.checkArgument('point')
|
|
@@ -454,7 +451,7 @@ class DPoint {
|
|
|
454
451
|
const p = point.clone().degreeToRadians();
|
|
455
452
|
const d = Math.sin(p.x - t.x);
|
|
456
453
|
const step = (p.x - t.x) / (pointsCount - 1);
|
|
457
|
-
return new
|
|
454
|
+
return new DPolygon(createArray(pointsCount)
|
|
458
455
|
.map((v, i) => {
|
|
459
456
|
const x = t.x + step * i;
|
|
460
457
|
const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
|
|
@@ -473,4 +470,3 @@ class DPoint {
|
|
|
473
470
|
.sort((a, b) => a.properties.distance - b.properties.distance);
|
|
474
471
|
}
|
|
475
472
|
}
|
|
476
|
-
exports.DPoint = DPoint;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = jsts_1.operation;
|
|
12
|
-
exports.MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
1
|
+
import { DPoint } from './DPoint';
|
|
2
|
+
import { DLine } from './DLine';
|
|
3
|
+
import { DCircle } from './DCircle';
|
|
4
|
+
import { DNumbers } from './DNumbers';
|
|
5
|
+
import { io as jstsIo, operation } from 'jsts';
|
|
6
|
+
import { DPolygonLoop } from './DPolygonLoop';
|
|
7
|
+
import { isDefAndNotNull } from './utils';
|
|
8
|
+
const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = operation;
|
|
9
|
+
export const MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
13
10
|
const APPROXIMATION_VALUE = 0.1;
|
|
14
11
|
const MAX_CONVEX_ITERATIONS = 100;
|
|
15
12
|
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
@@ -26,8 +23,8 @@ const containCalculator = (poly, p) => {
|
|
|
26
23
|
}
|
|
27
24
|
let totalFi = 0;
|
|
28
25
|
for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
|
|
29
|
-
const line1 = new
|
|
30
|
-
const line2 = new
|
|
26
|
+
const line1 = new DLine(x - p.x, y - p.y, 0);
|
|
27
|
+
const line2 = new DLine(a - p.x, b - p.y, 0);
|
|
31
28
|
const fiDif = line1.findFi(line2);
|
|
32
29
|
if (line1.vectorProduct(line2).c > 0) {
|
|
33
30
|
totalFi += fiDif;
|
|
@@ -50,7 +47,7 @@ const containCalculator = (poly, p) => {
|
|
|
50
47
|
}
|
|
51
48
|
return result;
|
|
52
49
|
};
|
|
53
|
-
class DPolygon {
|
|
50
|
+
export class DPolygon {
|
|
54
51
|
constructor(pPoints = []) {
|
|
55
52
|
this.pPoints = pPoints;
|
|
56
53
|
this.properties = {};
|
|
@@ -58,7 +55,7 @@ class DPolygon {
|
|
|
58
55
|
this.searchStore = {};
|
|
59
56
|
}
|
|
60
57
|
static arrayOfTrianglesToVertices(triangles, height) {
|
|
61
|
-
return triangles.map((v) => (
|
|
58
|
+
return triangles.map((v) => (isDefAndNotNull(height) ? v
|
|
62
59
|
.loop()
|
|
63
60
|
.height(height)
|
|
64
61
|
.run() : v)
|
|
@@ -67,7 +64,7 @@ class DPolygon {
|
|
|
67
64
|
}
|
|
68
65
|
static minAreaRectangleSize(poly) {
|
|
69
66
|
const { first, second, last } = poly.clone().open();
|
|
70
|
-
return new
|
|
67
|
+
return new DPoint(first.distance(second), first.distance(last));
|
|
71
68
|
}
|
|
72
69
|
static toDash(poly) {
|
|
73
70
|
let p = new DPolygon();
|
|
@@ -107,7 +104,7 @@ class DPolygon {
|
|
|
107
104
|
const [path, ...holes] = reg.groups.data
|
|
108
105
|
.split('), (')
|
|
109
106
|
.map((p) => new DPolygon(p.split(', ')
|
|
110
|
-
.map((pares) =>
|
|
107
|
+
.map((pares) => DPoint.parse(pares.split(' ').map(Number)))));
|
|
111
108
|
if (holes && holes.length) {
|
|
112
109
|
path.holes = holes;
|
|
113
110
|
}
|
|
@@ -117,18 +114,18 @@ class DPolygon {
|
|
|
117
114
|
const regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
|
|
118
115
|
const reg = regexp.exec(data);
|
|
119
116
|
res = new DPolygon(reg.groups.data
|
|
120
|
-
.split(', ').map((t) =>
|
|
117
|
+
.split(', ').map((t) => DPoint.parse(t.split(' ').map(Number))));
|
|
121
118
|
}
|
|
122
119
|
if (data.indexOf('POINT') === 0) {
|
|
123
|
-
res = new DPolygon([
|
|
120
|
+
res = new DPolygon([DPoint.parseFromWKT(data)]);
|
|
124
121
|
}
|
|
125
122
|
return res;
|
|
126
123
|
}
|
|
127
124
|
static createSquareBySize(size) {
|
|
128
|
-
return new DPolygon([
|
|
125
|
+
return new DPolygon([DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
|
|
129
126
|
}
|
|
130
127
|
loop() {
|
|
131
|
-
return new
|
|
128
|
+
return new DPolygonLoop(this);
|
|
132
129
|
}
|
|
133
130
|
set points(p) {
|
|
134
131
|
this.pPoints = p;
|
|
@@ -166,24 +163,24 @@ class DPolygon {
|
|
|
166
163
|
get extend() {
|
|
167
164
|
const { minX, minY, maxX, maxY } = this;
|
|
168
165
|
return new DPolygon([
|
|
169
|
-
new
|
|
170
|
-
new
|
|
171
|
-
new
|
|
172
|
-
new
|
|
173
|
-
new
|
|
166
|
+
new DPoint(minX, minY),
|
|
167
|
+
new DPoint(maxX, minY),
|
|
168
|
+
new DPoint(maxX, maxY),
|
|
169
|
+
new DPoint(minX, maxY),
|
|
170
|
+
new DPoint(minX, minY)
|
|
174
171
|
]);
|
|
175
172
|
}
|
|
176
173
|
get size() {
|
|
177
174
|
const { w, h } = this;
|
|
178
|
-
return new
|
|
175
|
+
return new DPoint(w, h);
|
|
179
176
|
}
|
|
180
177
|
get leftTop() {
|
|
181
178
|
const { minX, minY } = this;
|
|
182
|
-
return new
|
|
179
|
+
return new DPoint(minX, minY);
|
|
183
180
|
}
|
|
184
181
|
get rightBottom() {
|
|
185
182
|
const { maxX, maxY } = this;
|
|
186
|
-
return new
|
|
183
|
+
return new DPoint(maxX, maxY);
|
|
187
184
|
}
|
|
188
185
|
get length() {
|
|
189
186
|
return this.pPoints.length;
|
|
@@ -245,7 +242,7 @@ class DPolygon {
|
|
|
245
242
|
return p;
|
|
246
243
|
}
|
|
247
244
|
get valid() {
|
|
248
|
-
return this.length >
|
|
245
|
+
return this.length > MIN_POINTS_IN_VALID_POLYGON;
|
|
249
246
|
}
|
|
250
247
|
get first() {
|
|
251
248
|
return this.at(0);
|
|
@@ -314,7 +311,7 @@ class DPolygon {
|
|
|
314
311
|
const p2 = p.first;
|
|
315
312
|
const p3 = p.second;
|
|
316
313
|
const d = p2.findInnerAngle(p1, p3);
|
|
317
|
-
if (d > Math.PI ||
|
|
314
|
+
if (d > Math.PI || DNumbers.likeZero(DNumbers.rad2Deg(d)) || DNumbers.likePI(d) || DNumbers.like2PI(d)) {
|
|
318
315
|
p.removePart(-1, 1);
|
|
319
316
|
}
|
|
320
317
|
else {
|
|
@@ -331,7 +328,7 @@ class DPolygon {
|
|
|
331
328
|
const p2 = p.at(i);
|
|
332
329
|
const p3 = p.at(i + 1);
|
|
333
330
|
const d = p2.findInnerAngle(p1, p3);
|
|
334
|
-
if (d > Math.PI ||
|
|
331
|
+
if (d > Math.PI || DNumbers.likeZero(DNumbers.rad2Deg(d)) || DNumbers.likePI(d) || DNumbers.like2PI(d)) {
|
|
335
332
|
p.removePart(--i, 1);
|
|
336
333
|
}
|
|
337
334
|
}
|
|
@@ -489,7 +486,7 @@ class DPolygon {
|
|
|
489
486
|
return false;
|
|
490
487
|
}
|
|
491
488
|
findIndex(a) {
|
|
492
|
-
if (a instanceof
|
|
489
|
+
if (a instanceof DPoint) {
|
|
493
490
|
return this.points.findIndex((t) => t.equal(a));
|
|
494
491
|
}
|
|
495
492
|
return this.points.findIndex(a);
|
|
@@ -567,8 +564,8 @@ class DPolygon {
|
|
|
567
564
|
const poly = this.deintersection;
|
|
568
565
|
let totalFi = 0;
|
|
569
566
|
for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
|
|
570
|
-
const line1 = new
|
|
571
|
-
const line2 = new
|
|
567
|
+
const line1 = new DLine(x - p.x, y - p.y, 0);
|
|
568
|
+
const line2 = new DLine(a - p.x, b - p.y, 0);
|
|
572
569
|
const fiDif = line1.findFi(line2);
|
|
573
570
|
if (line1.vectorProduct(line2).c > 0) {
|
|
574
571
|
totalFi += fiDif;
|
|
@@ -622,7 +619,7 @@ class DPolygon {
|
|
|
622
619
|
return this;
|
|
623
620
|
}
|
|
624
621
|
static parse(a) {
|
|
625
|
-
return new DPolygon(a.map((r) =>
|
|
622
|
+
return new DPolygon(a.map((r) => DPoint.parse(r)));
|
|
626
623
|
}
|
|
627
624
|
toArrayOfCoords() {
|
|
628
625
|
return this.mapArray((r) => r.toCoords());
|
|
@@ -638,7 +635,7 @@ class DPolygon {
|
|
|
638
635
|
currentPieceLength = pieceLength;
|
|
639
636
|
}
|
|
640
637
|
else if (d - currentPieceLength > 0) {
|
|
641
|
-
const circle = new
|
|
638
|
+
const circle = new DCircle(p1, currentPieceLength);
|
|
642
639
|
const line = p1.findLine(p2);
|
|
643
640
|
const intersectionPoint = line.intersectionWithCircle(circle)
|
|
644
641
|
.filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
|
|
@@ -850,13 +847,13 @@ class DPolygon {
|
|
|
850
847
|
return this.first.equal(this.last);
|
|
851
848
|
}
|
|
852
849
|
buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
|
|
853
|
-
const reader = new
|
|
850
|
+
const reader = new jstsIo.WKTReader();
|
|
854
851
|
const { noHoles, closed } = this;
|
|
855
852
|
const points = reader
|
|
856
853
|
.read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
|
|
857
854
|
.buffer(v, quadrantSegments, type)
|
|
858
855
|
.getCoordinates();
|
|
859
|
-
return new DPolygon(points.map(({ x, y }) => new
|
|
856
|
+
return new DPolygon(points.map(({ x, y }) => new DPoint(x, y)));
|
|
860
857
|
}
|
|
861
858
|
sideBuffers(v, quadrantSegments = 64) {
|
|
862
859
|
const { first, last } = this;
|
|
@@ -949,7 +946,7 @@ class DPolygon {
|
|
|
949
946
|
}
|
|
950
947
|
getJSTSGeometry(p, unionThis, unionThat) {
|
|
951
948
|
const unionOrIntersection = unionThat === unionThis;
|
|
952
|
-
const reader = new
|
|
949
|
+
const reader = new jstsIo.WKTReader();
|
|
953
950
|
const a = reader.read(this.noHoles.toWKT());
|
|
954
951
|
const b = reader.read(p.noHoles.toWKT());
|
|
955
952
|
if (!unionOrIntersection) {
|
|
@@ -970,11 +967,11 @@ class DPolygon {
|
|
|
970
967
|
if (coordinates.length) {
|
|
971
968
|
let result = coordinates.reduce((ak, { x, y }, index) => {
|
|
972
969
|
const lastIndex = ak.length - 1;
|
|
973
|
-
const t = new
|
|
970
|
+
const t = new DPoint(x, y);
|
|
974
971
|
const { first } = ak[lastIndex];
|
|
975
972
|
if (t.equal(first)) {
|
|
976
973
|
if (coordinates[index + 1]) {
|
|
977
|
-
const nextPoint = new
|
|
974
|
+
const nextPoint = new DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
|
|
978
975
|
if (ak[lastIndex].length > 1) {
|
|
979
976
|
ak.push(new DPolygon([nextPoint]));
|
|
980
977
|
}
|
|
@@ -984,7 +981,7 @@ class DPolygon {
|
|
|
984
981
|
ak[lastIndex].push(t);
|
|
985
982
|
}
|
|
986
983
|
return ak;
|
|
987
|
-
}, [new DPolygon([new
|
|
984
|
+
}, [new DPolygon([new DPoint(coordinates[0].x, coordinates[0].y)])]);
|
|
988
985
|
if (unionThat && unionThis && result.length > 1) {
|
|
989
986
|
for (const q of result) {
|
|
990
987
|
for (const r of result) {
|
|
@@ -1032,7 +1029,6 @@ class DPolygon {
|
|
|
1032
1029
|
return null;
|
|
1033
1030
|
}
|
|
1034
1031
|
}
|
|
1035
|
-
exports.DPolygon = DPolygon;
|
|
1036
1032
|
DPolygon.CAP_ROUND = CAP_ROUND;
|
|
1037
1033
|
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1038
1034
|
DPolygon.CAP_SQUARE = CAP_SQUARE;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DPolygonLoop = void 0;
|
|
4
1
|
var LoopFunctions;
|
|
5
2
|
(function (LoopFunctions) {
|
|
6
3
|
LoopFunctions[LoopFunctions["getTileFromCoords"] = 0] = "getTileFromCoords";
|
|
@@ -170,7 +167,7 @@ const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg
|
|
|
170
167
|
}
|
|
171
168
|
return res;
|
|
172
169
|
};
|
|
173
|
-
class DPolygonLoop {
|
|
170
|
+
export class DPolygonLoop {
|
|
174
171
|
constructor(parent) {
|
|
175
172
|
this.parent = parent;
|
|
176
173
|
this.pool = [];
|
|
@@ -393,4 +390,3 @@ class DPolygonLoop {
|
|
|
393
390
|
return this;
|
|
394
391
|
}
|
|
395
392
|
}
|
|
396
|
-
exports.DPolygonLoop = DPolygonLoop;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FastSearch = void 0;
|
|
4
|
-
class FastSearch {
|
|
1
|
+
export class FastSearch {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.searchStore = {};
|
|
7
4
|
}
|
|
@@ -26,4 +23,3 @@ class FastSearch {
|
|
|
26
23
|
return this.searchStore[x][y][z || 'undefined'];
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
exports.FastSearch = FastSearch;
|