dgeoutils 2.2.7 → 2.2.11
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 +0 -28
- package/dist/DCircle.js +0 -30
- package/dist/DLine.d.ts +0 -60
- package/dist/DLine.js +1 -67
- package/dist/DPlane.d.ts +25 -0
- package/dist/DPlane.js +109 -0
- package/dist/DPoint.d.ts +4 -137
- package/dist/DPoint.js +31 -52
- package/dist/DPolygon.d.ts +2 -212
- package/dist/DPolygon.js +27 -255
- package/dist/DPolygonLoop.d.ts +3 -80
- package/dist/DPolygonLoop.js +58 -34
- package/dist/TraceMatrix.js +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +47 -4
- package/package.json +1 -1
package/dist/DPolygon.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DPolygon = exports.MIN_POINTS_IN_VALID_POLYGON = void 0;
|
|
4
|
-
/* eslint-disable max-lines */
|
|
5
4
|
const DPoint_1 = require("./DPoint");
|
|
6
5
|
const DLine_1 = require("./DLine");
|
|
7
6
|
const DCircle_1 = require("./DCircle");
|
|
@@ -14,34 +13,12 @@ const APPROXIMATION_VALUE = 0.1;
|
|
|
14
13
|
const MAX_CONVEX_ITERATIONS = 100;
|
|
15
14
|
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
16
15
|
class DPolygon {
|
|
17
|
-
// eslint-disable-next-line no-useless-constructor,no-empty-function
|
|
18
16
|
constructor(pPoints = []) {
|
|
19
17
|
this.pPoints = pPoints;
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
18
|
this.properties = {};
|
|
22
19
|
this.holes = [];
|
|
23
20
|
this.searchStore = {};
|
|
24
21
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Transform array of triangles to Three.JS vertices
|
|
27
|
-
*
|
|
28
|
-
* ```
|
|
29
|
-
* const geometry = new THREE.BufferGeometry();
|
|
30
|
-
* // create a simple square shape. We duplicate the top left and bottom right
|
|
31
|
-
* // vertices because each vertex needs to appear once per triangle.
|
|
32
|
-
* const vertices = new Float32Array( DPolygon.arrayOfTrianglesToVertices(triangles, 10) );
|
|
33
|
-
*
|
|
34
|
-
* // itemSize = 3 because there are 3 values (components) per vertex
|
|
35
|
-
* geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
|
|
36
|
-
* const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
|
|
37
|
-
* mesh = new THREE.Mesh( geometry, material );
|
|
38
|
-
*
|
|
39
|
-
* scene.add( mesh );
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @param triangles
|
|
43
|
-
* @param [height=0]
|
|
44
|
-
*/
|
|
45
22
|
static arrayOfTrianglesToVertices(triangles, height = 0) {
|
|
46
23
|
return triangles.map((v) => v
|
|
47
24
|
.loop()
|
|
@@ -50,18 +27,10 @@ class DPolygon {
|
|
|
50
27
|
.toArrayOfCoords())
|
|
51
28
|
.flat(2);
|
|
52
29
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Get size of min area rectangle.
|
|
55
|
-
* @param poly should be `minAreaRectangle`
|
|
56
|
-
*/
|
|
57
30
|
static minAreaRectangleSize(poly) {
|
|
58
31
|
const { first, second, last } = poly.clone().open();
|
|
59
32
|
return new DPoint_1.DPoint(first.distance(second), first.distance(last));
|
|
60
33
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Slice line string to dashes.
|
|
63
|
-
* @param poly should be `divideToPieces` at first
|
|
64
|
-
*/
|
|
65
34
|
static toDash(poly) {
|
|
66
35
|
let p = new DPolygon();
|
|
67
36
|
const result = [p];
|
|
@@ -81,10 +50,6 @@ class DPolygon {
|
|
|
81
50
|
}
|
|
82
51
|
return result;
|
|
83
52
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Get min area rectangle direction
|
|
86
|
-
* @param poly should be `minAreaRectangle`
|
|
87
|
-
*/
|
|
88
53
|
static minAreaRectangleDirection(poly) {
|
|
89
54
|
const { first, second, last } = poly.clone().open();
|
|
90
55
|
if (!first || !second || !last) {
|
|
@@ -145,39 +110,21 @@ class DPolygon {
|
|
|
145
110
|
get minY() {
|
|
146
111
|
return this.pPoints.reduce((a, r) => Math.min(a, r.y), Infinity);
|
|
147
112
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Get center coordinates
|
|
150
|
-
*/
|
|
151
113
|
get center() {
|
|
152
114
|
return this.leftTop.move(this.size.divide(2));
|
|
153
115
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Difference between `maxY` and `minY`. Equal `ΔY` (`dY`)
|
|
156
|
-
*/
|
|
157
116
|
get h() {
|
|
158
117
|
return this.maxY - this.minY;
|
|
159
118
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Difference between `maxX` and `minX`. Equal `ΔX` (`dX`)
|
|
162
|
-
*/
|
|
163
119
|
get w() {
|
|
164
120
|
return this.maxX - this.minX;
|
|
165
121
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Difference between `maxY` and `minY`. Equal `height` (`h`)
|
|
168
|
-
*/
|
|
169
122
|
get dY() {
|
|
170
123
|
return this.h;
|
|
171
124
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Difference between `maxX` and `minX`. Equal `width` (`w`)
|
|
174
|
-
*/
|
|
175
125
|
get dX() {
|
|
176
126
|
return this.w;
|
|
177
127
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Get closed extend polygon
|
|
180
|
-
*/
|
|
181
128
|
get extend() {
|
|
182
129
|
const { minX, minY, maxX, maxY } = this;
|
|
183
130
|
return new DPolygon([
|
|
@@ -188,42 +135,24 @@ class DPolygon {
|
|
|
188
135
|
new DPoint_1.DPoint(minX, minY)
|
|
189
136
|
]);
|
|
190
137
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Point with `width` value as `x` and `height` value as `y`
|
|
193
|
-
*/
|
|
194
138
|
get size() {
|
|
195
139
|
const { w, h } = this;
|
|
196
140
|
return new DPoint_1.DPoint(w, h);
|
|
197
141
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Point with minimal `x` and `y`
|
|
200
|
-
*/
|
|
201
142
|
get leftTop() {
|
|
202
143
|
const { minX, minY } = this;
|
|
203
144
|
return new DPoint_1.DPoint(minX, minY);
|
|
204
145
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Point with maximal `x` and `y`
|
|
207
|
-
*/
|
|
208
146
|
get rightBottom() {
|
|
209
147
|
const { maxX, maxY } = this;
|
|
210
148
|
return new DPoint_1.DPoint(maxX, maxY);
|
|
211
149
|
}
|
|
212
|
-
/**
|
|
213
|
-
* Next point index
|
|
214
|
-
*/
|
|
215
150
|
get length() {
|
|
216
151
|
return this.pPoints.length;
|
|
217
152
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Get length of line string.
|
|
220
|
-
*/
|
|
221
153
|
get fullLength() {
|
|
222
154
|
return this.clone().open().perimeter;
|
|
223
155
|
}
|
|
224
|
-
/**
|
|
225
|
-
* Get perimeter.
|
|
226
|
-
*/
|
|
227
156
|
get perimeter() {
|
|
228
157
|
let p = 0;
|
|
229
158
|
for (let i = 1; i < this.pPoints.length; i++) {
|
|
@@ -231,9 +160,6 @@ class DPolygon {
|
|
|
231
160
|
}
|
|
232
161
|
return p;
|
|
233
162
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Get polygon area
|
|
236
|
-
*/
|
|
237
163
|
get area() {
|
|
238
164
|
const closed = this.deintersection;
|
|
239
165
|
let sum = 0;
|
|
@@ -244,9 +170,6 @@ class DPolygon {
|
|
|
244
170
|
}
|
|
245
171
|
return Math.abs(sum / 2) - this.holes.reduce((a, hole) => a + hole.area, 0);
|
|
246
172
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Get deintesected polygon.
|
|
249
|
-
*/
|
|
250
173
|
get deintersection() {
|
|
251
174
|
const p = this.clone().close();
|
|
252
175
|
for (let i = 0; i < p.length - 1; i++) {
|
|
@@ -265,33 +188,18 @@ class DPolygon {
|
|
|
265
188
|
}
|
|
266
189
|
return p;
|
|
267
190
|
}
|
|
268
|
-
/**
|
|
269
|
-
* Check if polygon contain more than three points
|
|
270
|
-
*/
|
|
271
191
|
get valid() {
|
|
272
192
|
return this.length > exports.MIN_POINTS_IN_VALID_POLYGON;
|
|
273
193
|
}
|
|
274
|
-
/**
|
|
275
|
-
* Get first point
|
|
276
|
-
*/
|
|
277
194
|
get first() {
|
|
278
195
|
return this.at(0);
|
|
279
196
|
}
|
|
280
|
-
/**
|
|
281
|
-
* Get second point
|
|
282
|
-
*/
|
|
283
197
|
get second() {
|
|
284
198
|
return this.at(1);
|
|
285
199
|
}
|
|
286
|
-
/**
|
|
287
|
-
* Get last point
|
|
288
|
-
*/
|
|
289
200
|
get last() {
|
|
290
201
|
return this.at(this.length - 1);
|
|
291
202
|
}
|
|
292
|
-
/**
|
|
293
|
-
* Get min area rectangle
|
|
294
|
-
*/
|
|
295
203
|
get minAreaRectangle() {
|
|
296
204
|
const p = this.convex;
|
|
297
205
|
let resultPolygon = new DPolygon();
|
|
@@ -339,9 +247,6 @@ class DPolygon {
|
|
|
339
247
|
}
|
|
340
248
|
return resultPolygon;
|
|
341
249
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Get convex polygon
|
|
344
|
-
*/
|
|
345
250
|
get convex() {
|
|
346
251
|
let p = this.clone().open();
|
|
347
252
|
const { isClockwise } = p;
|
|
@@ -382,9 +287,6 @@ class DPolygon {
|
|
|
382
287
|
}
|
|
383
288
|
return p;
|
|
384
289
|
}
|
|
385
|
-
/**
|
|
386
|
-
* Check polygon direction
|
|
387
|
-
*/
|
|
388
290
|
get isClockwise() {
|
|
389
291
|
let sum = 0;
|
|
390
292
|
const p = this.clone().close();
|
|
@@ -395,28 +297,17 @@ class DPolygon {
|
|
|
395
297
|
}
|
|
396
298
|
return sum < 0;
|
|
397
299
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Get clockwise polygon
|
|
400
|
-
*/
|
|
401
300
|
get clockWise() {
|
|
402
301
|
if (this.isClockwise) {
|
|
403
302
|
return this.clone();
|
|
404
303
|
}
|
|
405
304
|
return this.clone().reverse();
|
|
406
305
|
}
|
|
407
|
-
/**
|
|
408
|
-
* Get polygon clone without holes
|
|
409
|
-
*/
|
|
410
306
|
get noHoles() {
|
|
411
307
|
const res = this.clone();
|
|
412
308
|
res.holes = [];
|
|
413
309
|
return res;
|
|
414
310
|
}
|
|
415
|
-
/**
|
|
416
|
-
* Check polygon intersection with line
|
|
417
|
-
* @param l
|
|
418
|
-
* @param [includeOnly=false]
|
|
419
|
-
*/
|
|
420
311
|
intersection(l, includeOnly = false) {
|
|
421
312
|
const res = [];
|
|
422
313
|
for (let i = 0; i < this.pPoints.length - 1; i++) {
|
|
@@ -430,35 +321,24 @@ class DPolygon {
|
|
|
430
321
|
}
|
|
431
322
|
return res;
|
|
432
323
|
}
|
|
433
|
-
/**
|
|
434
|
-
* Set polygon center
|
|
435
|
-
* @param newCenter
|
|
436
|
-
*/
|
|
437
324
|
setCenter(newCenter) {
|
|
438
325
|
return this.loop()
|
|
439
326
|
.move(newCenter.clone().move(this.center.minus()))
|
|
440
327
|
.run();
|
|
441
328
|
}
|
|
442
|
-
|
|
443
|
-
* @param [type = DPolygon.WKT_POLYGON] Available values `DPolygon.WKT_POLYGON`, `DPolygon.WKT_LINESTRING`
|
|
444
|
-
*/
|
|
445
|
-
toWKT(type = DPolygon.WKT_POLYGON) {
|
|
329
|
+
toWKT(type = DPolygon.WKT_POLYGON, withZ = false) {
|
|
446
330
|
if (type === DPolygon.WKT_POLYGON) {
|
|
447
331
|
let h = '';
|
|
448
332
|
if (this.holes && this.holes.length) {
|
|
449
333
|
h = `, ${this.holes.map((hole) => hole.toString())
|
|
450
334
|
.join(', ')}`;
|
|
451
335
|
}
|
|
452
|
-
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}`)
|
|
336
|
+
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
453
337
|
.join(', ')})${h})`;
|
|
454
338
|
}
|
|
455
|
-
return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}`)
|
|
339
|
+
return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
456
340
|
.join(', ')})`;
|
|
457
341
|
}
|
|
458
|
-
/**
|
|
459
|
-
* Filter points
|
|
460
|
-
* @param f
|
|
461
|
-
*/
|
|
462
342
|
filter(f) {
|
|
463
343
|
this.pPoints = this.pPoints.filter(f);
|
|
464
344
|
return this;
|
|
@@ -496,9 +376,6 @@ class DPolygon {
|
|
|
496
376
|
toString() {
|
|
497
377
|
return `(${this.pPoints.map((r) => r.toString()).join(', ')})`;
|
|
498
378
|
}
|
|
499
|
-
/**
|
|
500
|
-
* Add to the end of polygon point equal to first point if it not exist
|
|
501
|
-
*/
|
|
502
379
|
close() {
|
|
503
380
|
const p0 = this.first;
|
|
504
381
|
if (p0 && !this.closed) {
|
|
@@ -506,9 +383,6 @@ class DPolygon {
|
|
|
506
383
|
}
|
|
507
384
|
return this;
|
|
508
385
|
}
|
|
509
|
-
/**
|
|
510
|
-
* Remove from the end of polygon point equal to first point if it exist
|
|
511
|
-
*/
|
|
512
386
|
open() {
|
|
513
387
|
const p = this.first;
|
|
514
388
|
if (this.length > 2 && p && this.closed) {
|
|
@@ -521,10 +395,6 @@ class DPolygon {
|
|
|
521
395
|
res.holes = [...this.holes, ...poly.holes].map((h) => h.clone());
|
|
522
396
|
return res;
|
|
523
397
|
}
|
|
524
|
-
/**
|
|
525
|
-
* Check if has point in list of points
|
|
526
|
-
* @param p
|
|
527
|
-
*/
|
|
528
398
|
has(p) {
|
|
529
399
|
return this.pPoints.some((q) => q.equal(p));
|
|
530
400
|
}
|
|
@@ -534,10 +404,6 @@ class DPolygon {
|
|
|
534
404
|
res.properties = this.properties;
|
|
535
405
|
return res;
|
|
536
406
|
}
|
|
537
|
-
/**
|
|
538
|
-
* Check is it fully equal.
|
|
539
|
-
* @param p
|
|
540
|
-
*/
|
|
541
407
|
equal(p) {
|
|
542
408
|
if (!(p instanceof DPolygon)) {
|
|
543
409
|
return false;
|
|
@@ -548,10 +414,6 @@ class DPolygon {
|
|
|
548
414
|
return (this.same(p) &&
|
|
549
415
|
this.holes.reduce((a, hole) => a && p.holes.some((pHoles) => pHoles.same(hole)), true));
|
|
550
416
|
}
|
|
551
|
-
/**
|
|
552
|
-
* Check is polygons are same. They can be with different directions and different start points.
|
|
553
|
-
* @param p
|
|
554
|
-
*/
|
|
555
417
|
same(p) {
|
|
556
418
|
const pClone = p.clone().close();
|
|
557
419
|
const thisAsString = this.clone()
|
|
@@ -569,11 +431,6 @@ class DPolygon {
|
|
|
569
431
|
findIndex(p) {
|
|
570
432
|
return this.points.findIndex((t) => t.equal(p));
|
|
571
433
|
}
|
|
572
|
-
/**
|
|
573
|
-
* Get polygon approximation by
|
|
574
|
-
* [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
|
|
575
|
-
* @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
|
|
576
|
-
*/
|
|
577
434
|
approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
|
|
578
435
|
return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
|
|
579
436
|
}
|
|
@@ -583,10 +440,6 @@ class DPolygon {
|
|
|
583
440
|
removePart(index, count) {
|
|
584
441
|
return this.pPoints.splice(index + 1, count);
|
|
585
442
|
}
|
|
586
|
-
/**
|
|
587
|
-
* Check intersection with other polygon
|
|
588
|
-
* @param p
|
|
589
|
-
*/
|
|
590
443
|
hasSimpleIntersection(p) {
|
|
591
444
|
const extend1 = this.extend;
|
|
592
445
|
const extend2 = p.extend;
|
|
@@ -596,10 +449,6 @@ class DPolygon {
|
|
|
596
449
|
const in2 = extend2points.some((t) => extend1.simpleInclude(t));
|
|
597
450
|
return in1 || in2;
|
|
598
451
|
}
|
|
599
|
-
/**
|
|
600
|
-
* Check if it possible to include point
|
|
601
|
-
* @param p
|
|
602
|
-
*/
|
|
603
452
|
simpleInclude(p) {
|
|
604
453
|
return this.simpleIncludeX(p) && this.simpleIncludeY(p);
|
|
605
454
|
}
|
|
@@ -643,13 +492,7 @@ class DPolygon {
|
|
|
643
492
|
ctx.fill();
|
|
644
493
|
ctx.globalCompositeOperation = old;
|
|
645
494
|
}
|
|
646
|
-
|
|
647
|
-
* Check if contain point
|
|
648
|
-
* @param p
|
|
649
|
-
* @param [isBorderInside=false]
|
|
650
|
-
* @param [move=(0,0)] Ignore this parameter
|
|
651
|
-
*/
|
|
652
|
-
contain(p, isBorderInside = false, move = DPoint_1.DPoint.zero()) {
|
|
495
|
+
contain(p, isBorderInside = false) {
|
|
653
496
|
const simpleInclude = this.simpleInclude(p);
|
|
654
497
|
if (!simpleInclude) {
|
|
655
498
|
return false;
|
|
@@ -658,26 +501,35 @@ class DPolygon {
|
|
|
658
501
|
if (onBorder) {
|
|
659
502
|
return isBorderInside;
|
|
660
503
|
}
|
|
661
|
-
const line = p.findLine(this.leftTop.move(move));
|
|
662
504
|
const poly = this.deintersection;
|
|
663
|
-
|
|
505
|
+
let totalFi = 0;
|
|
664
506
|
for (let i = 0; i < poly.length - 1; i++) {
|
|
665
|
-
const
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
507
|
+
const p1 = poly.at(i);
|
|
508
|
+
const p2 = poly.at(i + 1);
|
|
509
|
+
const line1 = new DLine_1.DLine(p1.x - p.x, p1.y - p.y, 0);
|
|
510
|
+
const line2 = new DLine_1.DLine(p2.x - p.x, p2.y - p.y, 0);
|
|
511
|
+
const fiDif = line1.findFi(line2);
|
|
512
|
+
if (line1.vectorProduct(line2).c > 0) {
|
|
513
|
+
totalFi += fiDif;
|
|
669
514
|
}
|
|
515
|
+
else {
|
|
516
|
+
totalFi -= fiDif;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const eps = Math.PI / 10000;
|
|
520
|
+
let result = false;
|
|
521
|
+
const absTotalFi = Math.abs(totalFi);
|
|
522
|
+
if (absTotalFi < eps) {
|
|
523
|
+
result = false;
|
|
524
|
+
}
|
|
525
|
+
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
526
|
+
result = true;
|
|
670
527
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
return this.contain2(p, isBorderInside);
|
|
528
|
+
else {
|
|
529
|
+
throw new Error('contains2 faild');
|
|
674
530
|
}
|
|
675
|
-
return
|
|
531
|
+
return result;
|
|
676
532
|
}
|
|
677
|
-
/**
|
|
678
|
-
* Check if point on border
|
|
679
|
-
* @param p
|
|
680
|
-
*/
|
|
681
533
|
onBorder(p) {
|
|
682
534
|
const simpleInclude = this.simpleInclude(p);
|
|
683
535
|
if (simpleInclude) {
|
|
@@ -698,18 +550,12 @@ class DPolygon {
|
|
|
698
550
|
}
|
|
699
551
|
return false;
|
|
700
552
|
}
|
|
701
|
-
/**
|
|
702
|
-
* Change start point to second point
|
|
703
|
-
*/
|
|
704
553
|
nextStart() {
|
|
705
554
|
this.open();
|
|
706
555
|
this.push(this.shift());
|
|
707
556
|
this.close();
|
|
708
557
|
return this;
|
|
709
558
|
}
|
|
710
|
-
/**
|
|
711
|
-
* Remove duplicates points
|
|
712
|
-
*/
|
|
713
559
|
removeDuplicates() {
|
|
714
560
|
for (let i = 0; i < this.length - 1; i++) {
|
|
715
561
|
const p1 = this.at(i);
|
|
@@ -724,17 +570,9 @@ class DPolygon {
|
|
|
724
570
|
static parse(a) {
|
|
725
571
|
return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
|
|
726
572
|
}
|
|
727
|
-
/**
|
|
728
|
-
* Transform to array of coordinates for [OpenLayers](https://openlayers.org/) or
|
|
729
|
-
* [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON)
|
|
730
|
-
*/
|
|
731
573
|
toArrayOfCoords() {
|
|
732
574
|
return this.pPoints.map((r) => r.toCoords());
|
|
733
575
|
}
|
|
734
|
-
/**
|
|
735
|
-
* Divide line string to pieces by length
|
|
736
|
-
* @param piecesCount
|
|
737
|
-
*/
|
|
738
576
|
divideToPieces(piecesCount) {
|
|
739
577
|
const { fullLength } = this;
|
|
740
578
|
const pieceLength = fullLength / piecesCount;
|
|
@@ -787,13 +625,8 @@ class DPolygon {
|
|
|
787
625
|
}
|
|
788
626
|
return this.searchStore[x][y][z || 'undefined'];
|
|
789
627
|
}
|
|
790
|
-
/**
|
|
791
|
-
* Get line string as line string with growing length. For animation.
|
|
792
|
-
*/
|
|
793
628
|
get growingPiecesGenerator() {
|
|
794
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias,consistent-this
|
|
795
629
|
const polygon = this;
|
|
796
|
-
// eslint-disable-next-line func-names
|
|
797
630
|
return function* () {
|
|
798
631
|
const r = new DPolygon();
|
|
799
632
|
for (const p of polygon.pPoints) {
|
|
@@ -846,11 +679,6 @@ class DPolygon {
|
|
|
846
679
|
}
|
|
847
680
|
return res;
|
|
848
681
|
}
|
|
849
|
-
/**
|
|
850
|
-
* Divide polygon to triangles
|
|
851
|
-
*
|
|
852
|
-
* 
|
|
853
|
-
*/
|
|
854
682
|
toTriangles() {
|
|
855
683
|
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
856
684
|
const l = p1.findLine(p2);
|
|
@@ -904,9 +732,6 @@ class DPolygon {
|
|
|
904
732
|
res.push(p);
|
|
905
733
|
return res;
|
|
906
734
|
}
|
|
907
|
-
/**
|
|
908
|
-
* Divide polygon to triangles and return points indexes
|
|
909
|
-
*/
|
|
910
735
|
getTrianglesPointIndexes() {
|
|
911
736
|
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
912
737
|
const l = p1.findLine(p2);
|
|
@@ -973,11 +798,6 @@ class DPolygon {
|
|
|
973
798
|
get closed() {
|
|
974
799
|
return this.first.equal(this.last);
|
|
975
800
|
}
|
|
976
|
-
/**
|
|
977
|
-
* @param v
|
|
978
|
-
* @param [quadrantSegments=64]
|
|
979
|
-
* @param [type=DPolygon.CAP_ROUND] DPolygon.CAP_ROUND || DPolygon.CAP_FLAT || DPolygon.CAP_SQUARE
|
|
980
|
-
*/
|
|
981
801
|
buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
|
|
982
802
|
const reader = new jsts_1.io.WKTReader();
|
|
983
803
|
const { noHoles, closed } = this;
|
|
@@ -1023,45 +843,6 @@ class DPolygon {
|
|
|
1023
843
|
ctx.lineTo(x, y);
|
|
1024
844
|
}
|
|
1025
845
|
}
|
|
1026
|
-
contain2(p, isBorderInside = false) {
|
|
1027
|
-
const simpleInclude = this.simpleInclude(p);
|
|
1028
|
-
if (!simpleInclude) {
|
|
1029
|
-
return false;
|
|
1030
|
-
}
|
|
1031
|
-
const onBorder = this.onBorder(p);
|
|
1032
|
-
if (onBorder) {
|
|
1033
|
-
return isBorderInside;
|
|
1034
|
-
}
|
|
1035
|
-
const poly = this.deintersection;
|
|
1036
|
-
let totalFi = 0;
|
|
1037
|
-
for (let i = 0; i < poly.length - 1; i++) {
|
|
1038
|
-
const p1 = poly.at(i);
|
|
1039
|
-
const p2 = poly.at(i + 1);
|
|
1040
|
-
const line1 = new DLine_1.DLine(p1.x - p.x, p1.y - p.y, 0);
|
|
1041
|
-
const line2 = new DLine_1.DLine(p2.x - p.x, p2.y - p.y, 0);
|
|
1042
|
-
const fiDif = line1.findFi(line2);
|
|
1043
|
-
if (line1.vectorProduct(line2).c > 0) {
|
|
1044
|
-
totalFi += fiDif;
|
|
1045
|
-
}
|
|
1046
|
-
else {
|
|
1047
|
-
totalFi -= fiDif;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
// eslint-disable-next-line no-magic-numbers
|
|
1051
|
-
const eps = Math.PI / 10000;
|
|
1052
|
-
let result = false;
|
|
1053
|
-
const absTotalFi = Math.abs(totalFi);
|
|
1054
|
-
if (absTotalFi < eps) {
|
|
1055
|
-
result = false;
|
|
1056
|
-
}
|
|
1057
|
-
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
1058
|
-
result = true;
|
|
1059
|
-
}
|
|
1060
|
-
else {
|
|
1061
|
-
throw new Error('contains2 faild');
|
|
1062
|
-
}
|
|
1063
|
-
return result;
|
|
1064
|
-
}
|
|
1065
846
|
getJSTSGeometry(p, unionThis, unionThat) {
|
|
1066
847
|
const unionOrIntersection = unionThat === unionThis;
|
|
1067
848
|
const reader = new jsts_1.io.WKTReader();
|
|
@@ -1148,17 +929,8 @@ class DPolygon {
|
|
|
1148
929
|
}
|
|
1149
930
|
}
|
|
1150
931
|
exports.DPolygon = DPolygon;
|
|
1151
|
-
/**
|
|
1152
|
-
* Specifies a round line buffer end cap style.
|
|
1153
|
-
*/
|
|
1154
932
|
DPolygon.CAP_ROUND = CAP_ROUND;
|
|
1155
|
-
/**
|
|
1156
|
-
* Specifies a flat line buffer end cap style.
|
|
1157
|
-
*/
|
|
1158
933
|
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1159
|
-
/**
|
|
1160
|
-
* Specifies a square line buffer end cap style.
|
|
1161
|
-
*/
|
|
1162
934
|
DPolygon.CAP_SQUARE = CAP_SQUARE;
|
|
1163
935
|
DPolygon.WKT_LINESTRING = 'LINESTRING';
|
|
1164
936
|
DPolygon.WKT_POLYGON = 'POLYGON';
|
package/dist/DPolygonLoop.d.ts
CHANGED
|
@@ -6,102 +6,33 @@ export declare class DPolygonLoop {
|
|
|
6
6
|
private pool;
|
|
7
7
|
constructor(parent: DPolygon);
|
|
8
8
|
private getLoopFunction;
|
|
9
|
-
/**
|
|
10
|
-
* Run loop
|
|
11
|
-
*/
|
|
12
9
|
run(): DPolygon;
|
|
13
|
-
/**
|
|
14
|
-
* @param zoom default value would be `z` of point
|
|
15
|
-
*/
|
|
16
10
|
getTileFromCoords(zoom?: number): DPolygonLoop;
|
|
17
|
-
/**
|
|
18
|
-
* @param zoom default value would be `z` of point
|
|
19
|
-
*/
|
|
20
11
|
getCoordsFromTile(zoom?: number): DPolygonLoop;
|
|
21
12
|
height(z: number): DPolygonLoop;
|
|
22
|
-
/**
|
|
23
|
-
* Set `x` value
|
|
24
|
-
* @param x
|
|
25
|
-
*/
|
|
26
13
|
setX(x: number): DPolygonLoop;
|
|
27
|
-
/**
|
|
28
|
-
* Transform `x` value by function
|
|
29
|
-
* @param f
|
|
30
|
-
*/
|
|
31
14
|
setX(f: SetterFunction): DPolygonLoop;
|
|
32
|
-
/**
|
|
33
|
-
* Set `y` value
|
|
34
|
-
* @param y
|
|
35
|
-
*/
|
|
36
15
|
setY(y: number): DPolygonLoop;
|
|
37
|
-
/**
|
|
38
|
-
* Transform `y` value by function
|
|
39
|
-
* @param f
|
|
40
|
-
*/
|
|
41
16
|
setY(f: SetterFunction): DPolygonLoop;
|
|
42
|
-
/**
|
|
43
|
-
* Set `z` value
|
|
44
|
-
* @param z
|
|
45
|
-
*/
|
|
46
17
|
setZ(z: number): DPolygonLoop;
|
|
47
|
-
/**
|
|
48
|
-
* Transform `z` value by function
|
|
49
|
-
* @param f
|
|
50
|
-
*/
|
|
51
18
|
setZ(f: SetterFunction): DPolygonLoop;
|
|
52
19
|
rotate(a: number): DPolygonLoop;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*/
|
|
20
|
+
rotate3dX(a: number): DPolygonLoop;
|
|
21
|
+
rotate3dY(a: number): DPolygonLoop;
|
|
22
|
+
rotate3dZ(a: number): DPolygonLoop;
|
|
57
23
|
move(v: number): DPolygonLoop;
|
|
58
|
-
/**
|
|
59
|
-
* Add `p.x` to `x` field and `p.y` to `y` field.
|
|
60
|
-
* @param p
|
|
61
|
-
*/
|
|
62
24
|
move(p: DPoint): DPolygonLoop;
|
|
63
|
-
/**
|
|
64
|
-
* Add `x` to `x` field and `y` to `y` field.
|
|
65
|
-
* @param x
|
|
66
|
-
* @param y
|
|
67
|
-
*/
|
|
68
25
|
move(x: number, y: number): DPolygonLoop;
|
|
69
26
|
round(): DPolygonLoop;
|
|
70
27
|
ceil(): DPolygonLoop;
|
|
71
28
|
floor(): DPolygonLoop;
|
|
72
29
|
toFixed(n?: number): DPolygonLoop;
|
|
73
30
|
abs(): DPolygonLoop;
|
|
74
|
-
/**
|
|
75
|
-
* Multiply `v` to `x` and `y`
|
|
76
|
-
* @param v
|
|
77
|
-
*/
|
|
78
31
|
scale(v: number): DPolygonLoop;
|
|
79
|
-
/**
|
|
80
|
-
* Multiply `p.x` to `x` field and `p.y` to `y` field.
|
|
81
|
-
* @param p
|
|
82
|
-
*/
|
|
83
32
|
scale(p: DPoint): DPolygonLoop;
|
|
84
|
-
/**
|
|
85
|
-
* Multiply `x` to `x` field and `y` to `y` field.
|
|
86
|
-
* @param x
|
|
87
|
-
* @param y
|
|
88
|
-
*/
|
|
89
33
|
scale(x: number, y: number): DPolygonLoop;
|
|
90
|
-
/**
|
|
91
|
-
* Divide `x` and `y` to `v`
|
|
92
|
-
* @param v
|
|
93
|
-
*/
|
|
94
34
|
divide(v: number): DPolygonLoop;
|
|
95
|
-
/**
|
|
96
|
-
* Divide `x` field to `p.x` and `y` field to `p.y`.
|
|
97
|
-
* @param p
|
|
98
|
-
*/
|
|
99
35
|
divide(p: DPoint): DPolygonLoop;
|
|
100
|
-
/**
|
|
101
|
-
* Divide `x` field to `x` and `y` field to `y`.
|
|
102
|
-
* @param x
|
|
103
|
-
* @param y
|
|
104
|
-
*/
|
|
105
36
|
divide(x: number, y: number): DPolygonLoop;
|
|
106
37
|
degreeToRadians(): DPolygonLoop;
|
|
107
38
|
radiansToDegrees(): DPolygonLoop;
|
|
@@ -116,14 +47,6 @@ export declare class DPolygonLoop {
|
|
|
116
47
|
minus(): DPolygonLoop;
|
|
117
48
|
degreeToMeters(): DPolygonLoop;
|
|
118
49
|
metersToDegree(): DPolygonLoop;
|
|
119
|
-
/**
|
|
120
|
-
* Flip vertically
|
|
121
|
-
* @param size canvas size
|
|
122
|
-
*/
|
|
123
50
|
flipVertically(size: DPoint): DPolygonLoop;
|
|
124
|
-
/**
|
|
125
|
-
* Flip vertically
|
|
126
|
-
* @param height canvas height
|
|
127
|
-
*/
|
|
128
51
|
flipVertically(height: number): DPolygonLoop;
|
|
129
52
|
}
|