dgeoutils 2.2.23 → 2.2.24
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/DPolygon.d.ts +6 -0
- package/dist/DPolygon.js +21 -13
- package/package.json +1 -1
package/dist/DPolygon.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export declare class DPolygon {
|
|
|
51
51
|
get isClockwise(): boolean;
|
|
52
52
|
get clockWise(): DPolygon;
|
|
53
53
|
get noHoles(): DPolygon;
|
|
54
|
+
reduce<T>(f: (a: T, p: DPoint) => T, v: T): T;
|
|
55
|
+
reduce<T>(f: (a: T, p: DPoint, index: number) => T, v: T): T;
|
|
54
56
|
intersection(l: DLine, includeOnly?: boolean): DPoint[];
|
|
55
57
|
setCenter(newCenter: DPoint): DPolygon;
|
|
56
58
|
static WKT_LINESTRING: string;
|
|
@@ -59,6 +61,8 @@ export declare class DPolygon {
|
|
|
59
61
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
60
62
|
map(f: (r: DPoint) => DPoint): DPolygon;
|
|
61
63
|
map(f: (r: DPoint, index: number) => DPoint): DPolygon;
|
|
64
|
+
mapArray<T>(f: (r: DPoint) => T): T[];
|
|
65
|
+
mapArray<T>(f: (r: DPoint, index: number) => T): T[];
|
|
62
66
|
sort(f: (a: DPoint, b: DPoint) => number): DPolygon;
|
|
63
67
|
at(index: number): DPoint;
|
|
64
68
|
pop(): DPoint;
|
|
@@ -76,6 +80,8 @@ export declare class DPolygon {
|
|
|
76
80
|
equal(p: DPolygon | null): boolean;
|
|
77
81
|
same(p: DPolygon): boolean;
|
|
78
82
|
findIndex(p: DPoint): number;
|
|
83
|
+
findIndex(f: (p: DPoint) => boolean): number;
|
|
84
|
+
findIndex(f: (p: DPoint, index: number) => boolean): number;
|
|
79
85
|
approximation(e?: number): DPolygon;
|
|
80
86
|
insertAfter(index: number, ...points: DPoint[]): void;
|
|
81
87
|
removePart(index: number, count: number): DPoint[];
|
package/dist/DPolygon.js
CHANGED
|
@@ -137,16 +137,16 @@ class DPolygon {
|
|
|
137
137
|
return this.pPoints;
|
|
138
138
|
}
|
|
139
139
|
get maxX() {
|
|
140
|
-
return this.
|
|
140
|
+
return this.reduce((a, r) => Math.max(a, r.x), -Infinity);
|
|
141
141
|
}
|
|
142
142
|
get minX() {
|
|
143
|
-
return this.
|
|
143
|
+
return this.reduce((a, r) => Math.min(a, r.x), Infinity);
|
|
144
144
|
}
|
|
145
145
|
get maxY() {
|
|
146
|
-
return this.
|
|
146
|
+
return this.reduce((a, r) => Math.max(a, r.y), -Infinity);
|
|
147
147
|
}
|
|
148
148
|
get minY() {
|
|
149
|
-
return this.
|
|
149
|
+
return this.reduce((a, r) => Math.min(a, r.y), Infinity);
|
|
150
150
|
}
|
|
151
151
|
get center() {
|
|
152
152
|
return this.leftTop.move(this.size.divide(2));
|
|
@@ -233,8 +233,7 @@ class DPolygon {
|
|
|
233
233
|
const d = record[j] - record[j - 1];
|
|
234
234
|
if (d > 1) {
|
|
235
235
|
const part = new DPolygon(origin.removePart(record[j - 1], d));
|
|
236
|
-
const allInside = part.
|
|
237
|
-
.reduce((a, e) => a && containCalculator(origin, e), true);
|
|
236
|
+
const allInside = part.reduce((a, e) => a && containCalculator(origin, e), true);
|
|
238
237
|
if (allInside && origin.isClockwise === part.isClockwise) {
|
|
239
238
|
origin.insertAfter(record[j - 1] - 1, ...part.reverse().points);
|
|
240
239
|
p = origin;
|
|
@@ -362,6 +361,9 @@ class DPolygon {
|
|
|
362
361
|
res.holes = [];
|
|
363
362
|
return res;
|
|
364
363
|
}
|
|
364
|
+
reduce(f, v) {
|
|
365
|
+
return this.pPoints.reduce(f, v);
|
|
366
|
+
}
|
|
365
367
|
intersection(l, includeOnly = false) {
|
|
366
368
|
const res = [];
|
|
367
369
|
for (const [, , line] of this.loopPointsGenerator(true)()) {
|
|
@@ -384,10 +386,10 @@ class DPolygon {
|
|
|
384
386
|
h = `, ${this.holes.map((hole) => hole.toString())
|
|
385
387
|
.join(', ')}`;
|
|
386
388
|
}
|
|
387
|
-
return `POLYGON ((${this.deintersection.
|
|
389
|
+
return `POLYGON ((${this.deintersection.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
388
390
|
.join(', ')})${h})`;
|
|
389
391
|
}
|
|
390
|
-
return `LINESTRING (${this.
|
|
392
|
+
return `LINESTRING (${this.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
391
393
|
.join(', ')})`;
|
|
392
394
|
}
|
|
393
395
|
filter(f) {
|
|
@@ -395,10 +397,13 @@ class DPolygon {
|
|
|
395
397
|
return this;
|
|
396
398
|
}
|
|
397
399
|
map(f) {
|
|
398
|
-
this.pPoints = this.
|
|
400
|
+
this.pPoints = this.mapArray(f);
|
|
399
401
|
this.holes = this.holes.map((h) => h.map(f));
|
|
400
402
|
return this;
|
|
401
403
|
}
|
|
404
|
+
mapArray(f) {
|
|
405
|
+
return this.pPoints.map(f);
|
|
406
|
+
}
|
|
402
407
|
sort(f) {
|
|
403
408
|
this.points.sort(f);
|
|
404
409
|
return this;
|
|
@@ -429,7 +434,7 @@ class DPolygon {
|
|
|
429
434
|
.reduce((a, h) => a + h.getValue(), ''));
|
|
430
435
|
}
|
|
431
436
|
toString() {
|
|
432
|
-
return `(${this.
|
|
437
|
+
return `(${this.mapArray((r) => r.toString()).join(', ')})`;
|
|
433
438
|
}
|
|
434
439
|
close() {
|
|
435
440
|
const p0 = this.first;
|
|
@@ -483,8 +488,11 @@ class DPolygon {
|
|
|
483
488
|
}
|
|
484
489
|
return false;
|
|
485
490
|
}
|
|
486
|
-
findIndex(
|
|
487
|
-
|
|
491
|
+
findIndex(a) {
|
|
492
|
+
if (a instanceof DPoint_1.DPoint) {
|
|
493
|
+
return this.points.findIndex((t) => t.equal(a));
|
|
494
|
+
}
|
|
495
|
+
return this.points.findIndex(a);
|
|
488
496
|
}
|
|
489
497
|
approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
|
|
490
498
|
return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
|
|
@@ -617,7 +625,7 @@ class DPolygon {
|
|
|
617
625
|
return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
|
|
618
626
|
}
|
|
619
627
|
toArrayOfCoords() {
|
|
620
|
-
return this.
|
|
628
|
+
return this.mapArray((r) => r.toCoords());
|
|
621
629
|
}
|
|
622
630
|
divideToPieces(piecesCount) {
|
|
623
631
|
const { fullLength } = this;
|