dgeoutils 2.2.2 → 2.2.6
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 +5 -1
- package/dist/DCircle.js +8 -4
- package/dist/DLine.d.ts +14 -7
- package/dist/DLine.js +61 -77
- package/dist/DPoint.d.ts +105 -12
- package/dist/DPoint.js +18 -21
- package/dist/DPolygon.d.ts +67 -76
- package/dist/DPolygon.js +151 -123
- package/dist/DPolygonLoop.d.ts +84 -6
- package/dist/DPolygonLoop.js +11 -4
- package/dist/TraceMatrix.d.ts +1 -1
- package/dist/TraceMatrix.js +4 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +4 -2
- package/package.json +2 -2
package/dist/DPolygon.d.ts
CHANGED
|
@@ -4,13 +4,46 @@ import { DLine } from './DLine';
|
|
|
4
4
|
import { DPolygonLoop } from './DPolygonLoop';
|
|
5
5
|
export declare const MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
6
6
|
export declare class DPolygon {
|
|
7
|
+
private pPoints;
|
|
7
8
|
properties: {
|
|
8
9
|
[key: string]: any;
|
|
9
10
|
};
|
|
10
11
|
holes: DPolygon[];
|
|
11
|
-
private pPoints;
|
|
12
12
|
private searchStore;
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(pPoints?: DPoint[]);
|
|
14
|
+
/**
|
|
15
|
+
* Specifies a round line buffer end cap style.
|
|
16
|
+
*/
|
|
17
|
+
static CAP_ROUND: number;
|
|
18
|
+
/**
|
|
19
|
+
* Specifies a flat line buffer end cap style.
|
|
20
|
+
*/
|
|
21
|
+
static CAP_FLAT: number;
|
|
22
|
+
/**
|
|
23
|
+
* Specifies a square line buffer end cap style.
|
|
24
|
+
*/
|
|
25
|
+
static CAP_SQUARE: number;
|
|
26
|
+
/**
|
|
27
|
+
* Transform array of triangles to Three.JS vertices
|
|
28
|
+
*
|
|
29
|
+
* ```
|
|
30
|
+
* const geometry = new THREE.BufferGeometry();
|
|
31
|
+
* // create a simple square shape. We duplicate the top left and bottom right
|
|
32
|
+
* // vertices because each vertex needs to appear once per triangle.
|
|
33
|
+
* const vertices = new Float32Array( DPolygon.arrayOfTrianglesToVertices(triangles, 10) );
|
|
34
|
+
*
|
|
35
|
+
* // itemSize = 3 because there are 3 values (components) per vertex
|
|
36
|
+
* geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
|
|
37
|
+
* const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
|
|
38
|
+
* mesh = new THREE.Mesh( geometry, material );
|
|
39
|
+
*
|
|
40
|
+
* scene.add( mesh );
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param triangles
|
|
44
|
+
* @param [height=0]
|
|
45
|
+
*/
|
|
46
|
+
static arrayOfTrianglesToVertices(triangles: DPolygon[], height?: number): number[];
|
|
14
47
|
/**
|
|
15
48
|
* Get size of min area rectangle.
|
|
16
49
|
* @param poly should be `minAreaRectangle`
|
|
@@ -138,59 +171,19 @@ export declare class DPolygon {
|
|
|
138
171
|
* @param newCenter
|
|
139
172
|
*/
|
|
140
173
|
setCenter(newCenter: DPoint): DPolygon;
|
|
141
|
-
|
|
174
|
+
static WKT_LINESTRING: string;
|
|
175
|
+
static WKT_POLYGON: string;
|
|
142
176
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param a Radians
|
|
145
|
-
* @deprecated Better to use loop
|
|
177
|
+
* @param [type = DPolygon.WKT_POLYGON] Available values `DPolygon.WKT_POLYGON`, `DPolygon.WKT_LINESTRING`
|
|
146
178
|
*/
|
|
147
|
-
|
|
179
|
+
toWKT(type?: string): string;
|
|
148
180
|
/**
|
|
149
181
|
* Filter points
|
|
150
182
|
* @param f
|
|
151
183
|
*/
|
|
152
184
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* @param [x=0]
|
|
156
|
-
* @param [y=x]
|
|
157
|
-
*/
|
|
158
|
-
move(x?: number | DPoint, y?: number): DPolygon;
|
|
159
|
-
/**
|
|
160
|
-
* @deprecated Better to use loop
|
|
161
|
-
* @param [x=0]
|
|
162
|
-
* @param [y=x]
|
|
163
|
-
*/
|
|
164
|
-
scale(x?: number | DPoint, y?: number): DPolygon;
|
|
165
|
-
/**
|
|
166
|
-
* @deprecated Better to use loop
|
|
167
|
-
* @param [x=0]
|
|
168
|
-
* @param [y=x]
|
|
169
|
-
*/
|
|
170
|
-
divide(x?: number | DPoint, y?: number): DPolygon;
|
|
171
|
-
/**
|
|
172
|
-
* @deprecated Better to use loop
|
|
173
|
-
*/
|
|
174
|
-
round(): DPolygon;
|
|
175
|
-
/**
|
|
176
|
-
* @deprecated Better to use loop
|
|
177
|
-
*/
|
|
178
|
-
floor(): DPolygon;
|
|
179
|
-
/**
|
|
180
|
-
* @deprecated Better to use loop
|
|
181
|
-
*/
|
|
182
|
-
ceil(): DPolygon;
|
|
183
|
-
/**
|
|
184
|
-
* @deprecated Better to use loop
|
|
185
|
-
* @param size
|
|
186
|
-
*/
|
|
187
|
-
flipVertically(size: DPoint | number): DPolygon;
|
|
188
|
-
/**
|
|
189
|
-
* @deprecated Better to use loop
|
|
190
|
-
* @param [n=2]
|
|
191
|
-
*/
|
|
192
|
-
toFixed(n?: number): DPolygon;
|
|
193
|
-
map(f: (r: DPoint, index?: number) => DPoint): DPolygon;
|
|
185
|
+
map(f: (r: DPoint) => DPoint): DPolygon;
|
|
186
|
+
map(f: (r: DPoint, index: number) => DPoint): DPolygon;
|
|
194
187
|
at(index: number): DPoint;
|
|
195
188
|
pop(): DPoint;
|
|
196
189
|
push(...args: DPoint[]): number;
|
|
@@ -198,22 +191,6 @@ export declare class DPolygon {
|
|
|
198
191
|
unshift(...args: DPoint[]): number;
|
|
199
192
|
reverse(): DPolygon;
|
|
200
193
|
getValue(): string;
|
|
201
|
-
/**
|
|
202
|
-
* @deprecated Better to use loop
|
|
203
|
-
*/
|
|
204
|
-
degreeToMeters(): DPolygon;
|
|
205
|
-
/**
|
|
206
|
-
* @deprecated Better to use loop
|
|
207
|
-
*/
|
|
208
|
-
metersToDegree(): DPolygon;
|
|
209
|
-
/**
|
|
210
|
-
* @deprecated Better to use loop
|
|
211
|
-
*/
|
|
212
|
-
radiansToMeters(): DPolygon;
|
|
213
|
-
/**
|
|
214
|
-
* @deprecated Better to use loop
|
|
215
|
-
*/
|
|
216
|
-
metersToRadians(): DPolygon;
|
|
217
194
|
toString(): string;
|
|
218
195
|
/**
|
|
219
196
|
* Add to the end of polygon point equal to first point if it not exist
|
|
@@ -223,12 +200,6 @@ export declare class DPolygon {
|
|
|
223
200
|
* Remove from the end of polygon point equal to first point if it exist
|
|
224
201
|
*/
|
|
225
202
|
open(): DPolygon;
|
|
226
|
-
/**
|
|
227
|
-
* Set `height` (`z`)
|
|
228
|
-
* @param z
|
|
229
|
-
* @deprecated Better to use loop
|
|
230
|
-
*/
|
|
231
|
-
height(z: number): DPolygon;
|
|
232
203
|
add(poly: DPolygon): DPolygon;
|
|
233
204
|
/**
|
|
234
205
|
* Check if has point in list of points
|
|
@@ -250,7 +221,7 @@ export declare class DPolygon {
|
|
|
250
221
|
/**
|
|
251
222
|
* Get polygon approximation by
|
|
252
223
|
* [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
|
|
253
|
-
* @param e
|
|
224
|
+
* @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
|
|
254
225
|
*/
|
|
255
226
|
approximation(e?: number): DPolygon;
|
|
256
227
|
insertAfter(index: number, ...points: DPoint[]): void;
|
|
@@ -270,8 +241,8 @@ export declare class DPolygon {
|
|
|
270
241
|
/**
|
|
271
242
|
* Check if contain point
|
|
272
243
|
* @param p
|
|
273
|
-
* @param isBorderInside
|
|
274
|
-
* @param move Ignore this parameter
|
|
244
|
+
* @param [isBorderInside=false]
|
|
245
|
+
* @param [move=(0,0)] Ignore this parameter
|
|
275
246
|
*/
|
|
276
247
|
contain(p: DPoint, isBorderInside?: boolean, move?: DPoint): boolean;
|
|
277
248
|
/**
|
|
@@ -288,11 +259,20 @@ export declare class DPolygon {
|
|
|
288
259
|
*/
|
|
289
260
|
removeDuplicates(): DPolygon;
|
|
290
261
|
/**
|
|
291
|
-
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
292
|
-
*
|
|
262
|
+
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
263
|
+
* @param a
|
|
264
|
+
*/
|
|
265
|
+
static parse(a: LatLng[]): DPolygon;
|
|
266
|
+
/**
|
|
267
|
+
* Parse from [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) coordinates
|
|
268
|
+
* @param a
|
|
269
|
+
*/
|
|
270
|
+
static parse(a: number[][]): DPolygon;
|
|
271
|
+
/**
|
|
272
|
+
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
293
273
|
* @param a
|
|
294
274
|
*/
|
|
295
|
-
static parse(a:
|
|
275
|
+
static parse(a: DCoord[]): DPolygon;
|
|
296
276
|
/**
|
|
297
277
|
* Transform to array of coordinates for [OpenLayers](https://openlayers.org/) or
|
|
298
278
|
* [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON)
|
|
@@ -319,6 +299,17 @@ export declare class DPolygon {
|
|
|
319
299
|
* 
|
|
320
300
|
*/
|
|
321
301
|
toTriangles(): DPolygon[];
|
|
302
|
+
/**
|
|
303
|
+
* Divide polygon to triangles and return points indexes
|
|
304
|
+
*/
|
|
305
|
+
getTrianglesPointIndexes(): number[];
|
|
306
|
+
get closed(): boolean;
|
|
307
|
+
/**
|
|
308
|
+
* @param v
|
|
309
|
+
* @param [quadrantSegments=64]
|
|
310
|
+
* @param [type=DPolygon.CAP_ROUND] DPolygon.CAP_ROUND || DPolygon.CAP_FLAT || DPolygon.CAP_SQUARE
|
|
311
|
+
*/
|
|
312
|
+
buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
|
|
322
313
|
private simpleIncludeX;
|
|
323
314
|
private simpleIncludeY;
|
|
324
315
|
private douglasPeucker;
|
package/dist/DPolygon.js
CHANGED
|
@@ -8,18 +8,47 @@ const DCircle_1 = require("./DCircle");
|
|
|
8
8
|
const DNumbers_1 = require("./DNumbers");
|
|
9
9
|
const jsts_1 = require("jsts");
|
|
10
10
|
const DPolygonLoop_1 = require("./DPolygonLoop");
|
|
11
|
+
const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = jsts_1.operation;
|
|
11
12
|
exports.MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
12
13
|
const APPROXIMATION_VALUE = 0.1;
|
|
13
14
|
const MAX_CONVEX_ITERATIONS = 100;
|
|
14
15
|
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
15
16
|
class DPolygon {
|
|
16
|
-
|
|
17
|
+
// eslint-disable-next-line no-useless-constructor,no-empty-function
|
|
18
|
+
constructor(pPoints = []) {
|
|
19
|
+
this.pPoints = pPoints;
|
|
17
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
21
|
this.properties = {};
|
|
19
22
|
this.holes = [];
|
|
20
|
-
this.pPoints = [];
|
|
21
23
|
this.searchStore = {};
|
|
22
|
-
|
|
24
|
+
}
|
|
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
|
+
static arrayOfTrianglesToVertices(triangles, height = 0) {
|
|
46
|
+
return triangles.map((v) => v
|
|
47
|
+
.loop()
|
|
48
|
+
.height(height)
|
|
49
|
+
.run()
|
|
50
|
+
.toArrayOfCoords())
|
|
51
|
+
.flat(2);
|
|
23
52
|
}
|
|
24
53
|
/**
|
|
25
54
|
* Get size of min area rectangle.
|
|
@@ -93,7 +122,7 @@ class DPolygon {
|
|
|
93
122
|
return res;
|
|
94
123
|
}
|
|
95
124
|
static createSquareBySize(size) {
|
|
96
|
-
return new DPolygon([DPoint_1.DPoint.
|
|
125
|
+
return new DPolygon([DPoint_1.DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
|
|
97
126
|
}
|
|
98
127
|
loop() {
|
|
99
128
|
return new DPolygonLoop_1.DPolygonLoop(this);
|
|
@@ -410,20 +439,21 @@ class DPolygon {
|
|
|
410
439
|
.move(newCenter.clone().move(this.center.minus()))
|
|
411
440
|
.run();
|
|
412
441
|
}
|
|
413
|
-
toWKT() {
|
|
414
|
-
let h = '';
|
|
415
|
-
if (this.holes && this.holes.length) {
|
|
416
|
-
h = `, ${this.holes.map((hole) => hole.toString()).join(', ')}`;
|
|
417
|
-
}
|
|
418
|
-
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}`).join(', ')})${h})`;
|
|
419
|
-
}
|
|
420
442
|
/**
|
|
421
|
-
*
|
|
422
|
-
* @param a Radians
|
|
423
|
-
* @deprecated Better to use loop
|
|
443
|
+
* @param [type = DPolygon.WKT_POLYGON] Available values `DPolygon.WKT_POLYGON`, `DPolygon.WKT_LINESTRING`
|
|
424
444
|
*/
|
|
425
|
-
|
|
426
|
-
|
|
445
|
+
toWKT(type = DPolygon.WKT_POLYGON) {
|
|
446
|
+
if (type === DPolygon.WKT_POLYGON) {
|
|
447
|
+
let h = '';
|
|
448
|
+
if (this.holes && this.holes.length) {
|
|
449
|
+
h = `, ${this.holes.map((hole) => hole.toString())
|
|
450
|
+
.join(', ')}`;
|
|
451
|
+
}
|
|
452
|
+
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}`)
|
|
453
|
+
.join(', ')})${h})`;
|
|
454
|
+
}
|
|
455
|
+
return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}`)
|
|
456
|
+
.join(', ')})`;
|
|
427
457
|
}
|
|
428
458
|
/**
|
|
429
459
|
* Filter points
|
|
@@ -433,62 +463,6 @@ class DPolygon {
|
|
|
433
463
|
this.pPoints = this.pPoints.filter(f);
|
|
434
464
|
return this;
|
|
435
465
|
}
|
|
436
|
-
/**
|
|
437
|
-
* @deprecated Better to use loop
|
|
438
|
-
* @param [x=0]
|
|
439
|
-
* @param [y=x]
|
|
440
|
-
*/
|
|
441
|
-
move(x = 0, y) {
|
|
442
|
-
return this.map((h) => h.move(x, y));
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* @deprecated Better to use loop
|
|
446
|
-
* @param [x=0]
|
|
447
|
-
* @param [y=x]
|
|
448
|
-
*/
|
|
449
|
-
scale(x = 0, y) {
|
|
450
|
-
return this.map((h) => h.scale(x, y));
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* @deprecated Better to use loop
|
|
454
|
-
* @param [x=0]
|
|
455
|
-
* @param [y=x]
|
|
456
|
-
*/
|
|
457
|
-
divide(x = 0, y) {
|
|
458
|
-
return this.map((h) => h.divide(x, y));
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* @deprecated Better to use loop
|
|
462
|
-
*/
|
|
463
|
-
round() {
|
|
464
|
-
return this.map((h) => h.round());
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* @deprecated Better to use loop
|
|
468
|
-
*/
|
|
469
|
-
floor() {
|
|
470
|
-
return this.map((h) => h.floor());
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* @deprecated Better to use loop
|
|
474
|
-
*/
|
|
475
|
-
ceil() {
|
|
476
|
-
return this.map((h) => h.ceil());
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* @deprecated Better to use loop
|
|
480
|
-
* @param size
|
|
481
|
-
*/
|
|
482
|
-
flipVertically(size) {
|
|
483
|
-
return this.map((h) => h.flipVertically(size));
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* @deprecated Better to use loop
|
|
487
|
-
* @param [n=2]
|
|
488
|
-
*/
|
|
489
|
-
toFixed(n = 2) {
|
|
490
|
-
return this.map((h) => h.toFixed(n));
|
|
491
|
-
}
|
|
492
466
|
map(f) {
|
|
493
467
|
this.pPoints = this.pPoints.map(f);
|
|
494
468
|
this.holes = this.holes.map((h) => h.map(f));
|
|
@@ -519,30 +493,6 @@ class DPolygon {
|
|
|
519
493
|
return (this.pPoints.map((r) => r.getValue()) + this.holes
|
|
520
494
|
.reduce((a, h) => a + h.getValue(), ''));
|
|
521
495
|
}
|
|
522
|
-
/**
|
|
523
|
-
* @deprecated Better to use loop
|
|
524
|
-
*/
|
|
525
|
-
degreeToMeters() {
|
|
526
|
-
return this.map((r) => r.degreeToMeters());
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* @deprecated Better to use loop
|
|
530
|
-
*/
|
|
531
|
-
metersToDegree() {
|
|
532
|
-
return this.map((r) => r.metersToDegree());
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* @deprecated Better to use loop
|
|
536
|
-
*/
|
|
537
|
-
radiansToMeters() {
|
|
538
|
-
return this.map((r) => r.radiansToMeters());
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* @deprecated Better to use loop
|
|
542
|
-
*/
|
|
543
|
-
metersToRadians() {
|
|
544
|
-
return this.map((r) => r.metersToRadians());
|
|
545
|
-
}
|
|
546
496
|
toString() {
|
|
547
497
|
return `(${this.pPoints.map((r) => r.toString()).join(', ')})`;
|
|
548
498
|
}
|
|
@@ -551,7 +501,7 @@ class DPolygon {
|
|
|
551
501
|
*/
|
|
552
502
|
close() {
|
|
553
503
|
const p0 = this.first;
|
|
554
|
-
if (p0 && !
|
|
504
|
+
if (p0 && !this.closed) {
|
|
555
505
|
this.push(p0.clone());
|
|
556
506
|
}
|
|
557
507
|
return this;
|
|
@@ -561,19 +511,11 @@ class DPolygon {
|
|
|
561
511
|
*/
|
|
562
512
|
open() {
|
|
563
513
|
const p = this.first;
|
|
564
|
-
if (this.length > 2 && p &&
|
|
514
|
+
if (this.length > 2 && p && this.closed) {
|
|
565
515
|
this.pop();
|
|
566
516
|
}
|
|
567
517
|
return this;
|
|
568
518
|
}
|
|
569
|
-
/**
|
|
570
|
-
* Set `height` (`z`)
|
|
571
|
-
* @param z
|
|
572
|
-
* @deprecated Better to use loop
|
|
573
|
-
*/
|
|
574
|
-
height(z) {
|
|
575
|
-
return this.map((p) => p.height(z));
|
|
576
|
-
}
|
|
577
519
|
add(poly) {
|
|
578
520
|
const res = new DPolygon([...this.points, ...poly.points]).close();
|
|
579
521
|
res.holes = [...this.holes, ...poly.holes].map((h) => h.clone());
|
|
@@ -630,7 +572,7 @@ class DPolygon {
|
|
|
630
572
|
/**
|
|
631
573
|
* Get polygon approximation by
|
|
632
574
|
* [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
|
|
633
|
-
* @param e
|
|
575
|
+
* @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
|
|
634
576
|
*/
|
|
635
577
|
approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
|
|
636
578
|
return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
|
|
@@ -704,10 +646,10 @@ class DPolygon {
|
|
|
704
646
|
/**
|
|
705
647
|
* Check if contain point
|
|
706
648
|
* @param p
|
|
707
|
-
* @param isBorderInside
|
|
708
|
-
* @param move Ignore this parameter
|
|
649
|
+
* @param [isBorderInside=false]
|
|
650
|
+
* @param [move=(0,0)] Ignore this parameter
|
|
709
651
|
*/
|
|
710
|
-
contain(p, isBorderInside = false, move = DPoint_1.DPoint.
|
|
652
|
+
contain(p, isBorderInside = false, move = DPoint_1.DPoint.zero()) {
|
|
711
653
|
const simpleInclude = this.simpleInclude(p);
|
|
712
654
|
if (!simpleInclude) {
|
|
713
655
|
return false;
|
|
@@ -779,11 +721,6 @@ class DPolygon {
|
|
|
779
721
|
}
|
|
780
722
|
return this;
|
|
781
723
|
}
|
|
782
|
-
/**
|
|
783
|
-
* Parse from [OpenLayers](https://openlayers.org/) coordinates or
|
|
784
|
-
* [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) coordinates
|
|
785
|
-
* @param a
|
|
786
|
-
*/
|
|
787
724
|
static parse(a) {
|
|
788
725
|
return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
|
|
789
726
|
}
|
|
@@ -890,10 +827,9 @@ class DPolygon {
|
|
|
890
827
|
return this.simpleLogicFunction(p, true, false);
|
|
891
828
|
}
|
|
892
829
|
smartUnion(p) {
|
|
893
|
-
var _a;
|
|
894
830
|
const res = this.clone().simpleUnion(p);
|
|
895
831
|
if (res) {
|
|
896
|
-
let allHoles = [...this.holes, ...p.holes, ...
|
|
832
|
+
let allHoles = [...this.holes, ...p.holes, ...res.holes].map((h) => h.clone());
|
|
897
833
|
for (const a of allHoles) {
|
|
898
834
|
for (const b of allHoles) {
|
|
899
835
|
if (a.equal(b)) {
|
|
@@ -902,12 +838,7 @@ class DPolygon {
|
|
|
902
838
|
const r = a.simpleUnion(b);
|
|
903
839
|
if (r) {
|
|
904
840
|
allHoles = allHoles.filter((v) => !v.equal(a) && !v.equal(b));
|
|
905
|
-
|
|
906
|
-
allHoles = [...allHoles, ...r];
|
|
907
|
-
}
|
|
908
|
-
else {
|
|
909
|
-
allHoles.push(r);
|
|
910
|
-
}
|
|
841
|
+
allHoles.push(r);
|
|
911
842
|
}
|
|
912
843
|
}
|
|
913
844
|
}
|
|
@@ -973,6 +904,89 @@ class DPolygon {
|
|
|
973
904
|
res.push(p);
|
|
974
905
|
return res;
|
|
975
906
|
}
|
|
907
|
+
/**
|
|
908
|
+
* Divide polygon to triangles and return points indexes
|
|
909
|
+
*/
|
|
910
|
+
getTrianglesPointIndexes() {
|
|
911
|
+
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
912
|
+
const l = p1.findLine(p2);
|
|
913
|
+
const { center } = l;
|
|
914
|
+
const intersections = poly.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
|
|
915
|
+
.intersection(l, true).length), Boolean(poly.clone().close()
|
|
916
|
+
.intersection(l, true).length));
|
|
917
|
+
const contain = poly.holes.reduce((a, hole) => a && !hole
|
|
918
|
+
.contain(center), poly.contain(center));
|
|
919
|
+
return !intersections && contain;
|
|
920
|
+
};
|
|
921
|
+
const getTriangle = (poly) => {
|
|
922
|
+
for (let i = 0; i < poly.length; i++) {
|
|
923
|
+
const p0 = poly.at(0);
|
|
924
|
+
const p1 = poly.at(1);
|
|
925
|
+
const p2 = poly.at(2);
|
|
926
|
+
if (innerAndNotIntersect(poly, p0, p2)) {
|
|
927
|
+
poly.removePart(0, 1);
|
|
928
|
+
return [
|
|
929
|
+
p0.properties.index,
|
|
930
|
+
p1.properties.index,
|
|
931
|
+
p2.properties.index
|
|
932
|
+
];
|
|
933
|
+
}
|
|
934
|
+
poly.push(poly.shift());
|
|
935
|
+
}
|
|
936
|
+
return undefined;
|
|
937
|
+
};
|
|
938
|
+
let p = this.clone();
|
|
939
|
+
let index = 0;
|
|
940
|
+
p.points.forEach((f) => {
|
|
941
|
+
f.properties.index = index++;
|
|
942
|
+
});
|
|
943
|
+
p.holes.forEach((h) => {
|
|
944
|
+
h.pPoints.forEach((f) => {
|
|
945
|
+
f.properties.index = index++;
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
p = p.clockWise.open();
|
|
949
|
+
while (p.holes.length) {
|
|
950
|
+
const h = p.holes.shift()
|
|
951
|
+
.clone()
|
|
952
|
+
.clockWise
|
|
953
|
+
.reverse()
|
|
954
|
+
.close();
|
|
955
|
+
for (let i = 0; i < p.length; i++) {
|
|
956
|
+
if (innerAndNotIntersect(p, p.first, h.first)) {
|
|
957
|
+
p.insertAfter(0, ...h.points, p.first);
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
p.push(p.shift());
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
const res = [];
|
|
964
|
+
while (p.length > 3) {
|
|
965
|
+
const triangle = getTriangle(p);
|
|
966
|
+
if (triangle) {
|
|
967
|
+
res.push(...triangle);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
res.push(...p.points.map((f) => f.properties.index));
|
|
971
|
+
return res;
|
|
972
|
+
}
|
|
973
|
+
get closed() {
|
|
974
|
+
return this.first.equal(this.last);
|
|
975
|
+
}
|
|
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
|
+
buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
|
|
982
|
+
const reader = new jsts_1.io.WKTReader();
|
|
983
|
+
const { noHoles, closed } = this;
|
|
984
|
+
const points = reader
|
|
985
|
+
.read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
|
|
986
|
+
.buffer(v, quadrantSegments, type)
|
|
987
|
+
.getCoordinates();
|
|
988
|
+
return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
|
|
989
|
+
}
|
|
976
990
|
simpleIncludeX(p) {
|
|
977
991
|
const { x } = p;
|
|
978
992
|
return this.minX <= x && this.maxX >= x;
|
|
@@ -1134,3 +1148,17 @@ class DPolygon {
|
|
|
1134
1148
|
}
|
|
1135
1149
|
}
|
|
1136
1150
|
exports.DPolygon = DPolygon;
|
|
1151
|
+
/**
|
|
1152
|
+
* Specifies a round line buffer end cap style.
|
|
1153
|
+
*/
|
|
1154
|
+
DPolygon.CAP_ROUND = CAP_ROUND;
|
|
1155
|
+
/**
|
|
1156
|
+
* Specifies a flat line buffer end cap style.
|
|
1157
|
+
*/
|
|
1158
|
+
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1159
|
+
/**
|
|
1160
|
+
* Specifies a square line buffer end cap style.
|
|
1161
|
+
*/
|
|
1162
|
+
DPolygon.CAP_SQUARE = CAP_SQUARE;
|
|
1163
|
+
DPolygon.WKT_LINESTRING = 'LINESTRING';
|
|
1164
|
+
DPolygon.WKT_POLYGON = 'POLYGON';
|
package/dist/DPolygonLoop.d.ts
CHANGED
|
@@ -10,20 +10,89 @@ export declare class DPolygonLoop {
|
|
|
10
10
|
* Run loop
|
|
11
11
|
*/
|
|
12
12
|
run(): DPolygon;
|
|
13
|
+
/**
|
|
14
|
+
* @param zoom default value would be `z` of point
|
|
15
|
+
*/
|
|
13
16
|
getTileFromCoords(zoom?: number): DPolygonLoop;
|
|
17
|
+
/**
|
|
18
|
+
* @param zoom default value would be `z` of point
|
|
19
|
+
*/
|
|
14
20
|
getCoordsFromTile(zoom?: number): DPolygonLoop;
|
|
15
21
|
height(z: number): DPolygonLoop;
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Set `x` value
|
|
24
|
+
* @param x
|
|
25
|
+
*/
|
|
26
|
+
setX(x: number): DPolygonLoop;
|
|
27
|
+
/**
|
|
28
|
+
* Transform `x` value by function
|
|
29
|
+
* @param f
|
|
30
|
+
*/
|
|
31
|
+
setX(f: SetterFunction): DPolygonLoop;
|
|
32
|
+
/**
|
|
33
|
+
* Set `y` value
|
|
34
|
+
* @param y
|
|
35
|
+
*/
|
|
36
|
+
setY(y: number): DPolygonLoop;
|
|
37
|
+
/**
|
|
38
|
+
* Transform `y` value by function
|
|
39
|
+
* @param f
|
|
40
|
+
*/
|
|
41
|
+
setY(f: SetterFunction): DPolygonLoop;
|
|
18
42
|
rotate(a: number): DPolygonLoop;
|
|
19
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Add `v` to `x` and `y`
|
|
45
|
+
* @param v
|
|
46
|
+
*/
|
|
47
|
+
move(v: number): DPolygonLoop;
|
|
48
|
+
/**
|
|
49
|
+
* Add `p.x` to `x` field and `p.y` to `y` field.
|
|
50
|
+
* @param p
|
|
51
|
+
*/
|
|
52
|
+
move(p: DPoint): DPolygonLoop;
|
|
53
|
+
/**
|
|
54
|
+
* Add `x` to `x` field and `y` to `y` field.
|
|
55
|
+
* @param x
|
|
56
|
+
* @param y
|
|
57
|
+
*/
|
|
58
|
+
move(x: number, y: number): DPolygonLoop;
|
|
20
59
|
round(): DPolygonLoop;
|
|
21
60
|
ceil(): DPolygonLoop;
|
|
22
61
|
floor(): DPolygonLoop;
|
|
23
62
|
toFixed(n?: number): DPolygonLoop;
|
|
24
63
|
abs(): DPolygonLoop;
|
|
25
|
-
|
|
26
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Multiply `v` to `x` and `y`
|
|
66
|
+
* @param v
|
|
67
|
+
*/
|
|
68
|
+
scale(v: number): DPolygonLoop;
|
|
69
|
+
/**
|
|
70
|
+
* Multiply `p.x` to `x` field and `p.y` to `y` field.
|
|
71
|
+
* @param p
|
|
72
|
+
*/
|
|
73
|
+
scale(p: DPoint): DPolygonLoop;
|
|
74
|
+
/**
|
|
75
|
+
* Multiply `x` to `x` field and `y` to `y` field.
|
|
76
|
+
* @param x
|
|
77
|
+
* @param y
|
|
78
|
+
*/
|
|
79
|
+
scale(x: number, y: number): DPolygonLoop;
|
|
80
|
+
/**
|
|
81
|
+
* Divide `x` and `y` to `v`
|
|
82
|
+
* @param v
|
|
83
|
+
*/
|
|
84
|
+
divide(v: number): DPolygonLoop;
|
|
85
|
+
/**
|
|
86
|
+
* Divide `x` field to `p.x` and `y` field to `p.y`.
|
|
87
|
+
* @param p
|
|
88
|
+
*/
|
|
89
|
+
divide(p: DPoint): DPolygonLoop;
|
|
90
|
+
/**
|
|
91
|
+
* Divide `x` field to `x` and `y` field to `y`.
|
|
92
|
+
* @param x
|
|
93
|
+
* @param y
|
|
94
|
+
*/
|
|
95
|
+
divide(x: number, y: number): DPolygonLoop;
|
|
27
96
|
degreeToRadians(): DPolygonLoop;
|
|
28
97
|
radiansToDegrees(): DPolygonLoop;
|
|
29
98
|
radiansToMeters(): DPolygonLoop;
|
|
@@ -37,5 +106,14 @@ export declare class DPolygonLoop {
|
|
|
37
106
|
minus(): DPolygonLoop;
|
|
38
107
|
degreeToMeters(): DPolygonLoop;
|
|
39
108
|
metersToDegree(): DPolygonLoop;
|
|
40
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Flip vertically
|
|
111
|
+
* @param size canvas size
|
|
112
|
+
*/
|
|
113
|
+
flipVertically(size: DPoint): DPolygonLoop;
|
|
114
|
+
/**
|
|
115
|
+
* Flip vertically
|
|
116
|
+
* @param height canvas height
|
|
117
|
+
*/
|
|
118
|
+
flipVertically(height: number): DPolygonLoop;
|
|
41
119
|
}
|