dgeoutils 2.2.23 → 2.3.2
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/README.md +7 -0
- 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} +7 -1
- 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} +90 -86
- 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,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;
|
|
@@ -137,16 +134,16 @@ class DPolygon {
|
|
|
137
134
|
return this.pPoints;
|
|
138
135
|
}
|
|
139
136
|
get maxX() {
|
|
140
|
-
return this.
|
|
137
|
+
return this.reduce((a, r) => Math.max(a, r.x), -Infinity);
|
|
141
138
|
}
|
|
142
139
|
get minX() {
|
|
143
|
-
return this.
|
|
140
|
+
return this.reduce((a, r) => Math.min(a, r.x), Infinity);
|
|
144
141
|
}
|
|
145
142
|
get maxY() {
|
|
146
|
-
return this.
|
|
143
|
+
return this.reduce((a, r) => Math.max(a, r.y), -Infinity);
|
|
147
144
|
}
|
|
148
145
|
get minY() {
|
|
149
|
-
return this.
|
|
146
|
+
return this.reduce((a, r) => Math.min(a, r.y), Infinity);
|
|
150
147
|
}
|
|
151
148
|
get center() {
|
|
152
149
|
return this.leftTop.move(this.size.divide(2));
|
|
@@ -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;
|
|
@@ -233,8 +230,7 @@ class DPolygon {
|
|
|
233
230
|
const d = record[j] - record[j - 1];
|
|
234
231
|
if (d > 1) {
|
|
235
232
|
const part = new DPolygon(origin.removePart(record[j - 1], d));
|
|
236
|
-
const allInside = part.
|
|
237
|
-
.reduce((a, e) => a && containCalculator(origin, e), true);
|
|
233
|
+
const allInside = part.reduce((a, e) => a && containCalculator(origin, e), true);
|
|
238
234
|
if (allInside && origin.isClockwise === part.isClockwise) {
|
|
239
235
|
origin.insertAfter(record[j - 1] - 1, ...part.reverse().points);
|
|
240
236
|
p = origin;
|
|
@@ -246,7 +242,7 @@ class DPolygon {
|
|
|
246
242
|
return p;
|
|
247
243
|
}
|
|
248
244
|
get valid() {
|
|
249
|
-
return this.length >
|
|
245
|
+
return this.length > MIN_POINTS_IN_VALID_POLYGON;
|
|
250
246
|
}
|
|
251
247
|
get first() {
|
|
252
248
|
return this.at(0);
|
|
@@ -315,7 +311,7 @@ class DPolygon {
|
|
|
315
311
|
const p2 = p.first;
|
|
316
312
|
const p3 = p.second;
|
|
317
313
|
const d = p2.findInnerAngle(p1, p3);
|
|
318
|
-
if (d > Math.PI ||
|
|
314
|
+
if (d > Math.PI || DNumbers.likeZero(DNumbers.rad2Deg(d)) || DNumbers.likePI(d) || DNumbers.like2PI(d)) {
|
|
319
315
|
p.removePart(-1, 1);
|
|
320
316
|
}
|
|
321
317
|
else {
|
|
@@ -332,7 +328,7 @@ class DPolygon {
|
|
|
332
328
|
const p2 = p.at(i);
|
|
333
329
|
const p3 = p.at(i + 1);
|
|
334
330
|
const d = p2.findInnerAngle(p1, p3);
|
|
335
|
-
if (d > Math.PI ||
|
|
331
|
+
if (d > Math.PI || DNumbers.likeZero(DNumbers.rad2Deg(d)) || DNumbers.likePI(d) || DNumbers.like2PI(d)) {
|
|
336
332
|
p.removePart(--i, 1);
|
|
337
333
|
}
|
|
338
334
|
}
|
|
@@ -362,6 +358,9 @@ class DPolygon {
|
|
|
362
358
|
res.holes = [];
|
|
363
359
|
return res;
|
|
364
360
|
}
|
|
361
|
+
reduce(f, v) {
|
|
362
|
+
return this.pPoints.reduce(f, v);
|
|
363
|
+
}
|
|
365
364
|
intersection(l, includeOnly = false) {
|
|
366
365
|
const res = [];
|
|
367
366
|
for (const [, , line] of this.loopPointsGenerator(true)()) {
|
|
@@ -384,10 +383,10 @@ class DPolygon {
|
|
|
384
383
|
h = `, ${this.holes.map((hole) => hole.toString())
|
|
385
384
|
.join(', ')}`;
|
|
386
385
|
}
|
|
387
|
-
return `POLYGON ((${this.deintersection.
|
|
386
|
+
return `POLYGON ((${this.deintersection.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
388
387
|
.join(', ')})${h})`;
|
|
389
388
|
}
|
|
390
|
-
return `LINESTRING (${this.
|
|
389
|
+
return `LINESTRING (${this.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
391
390
|
.join(', ')})`;
|
|
392
391
|
}
|
|
393
392
|
filter(f) {
|
|
@@ -395,10 +394,13 @@ class DPolygon {
|
|
|
395
394
|
return this;
|
|
396
395
|
}
|
|
397
396
|
map(f) {
|
|
398
|
-
this.pPoints = this.
|
|
397
|
+
this.pPoints = this.mapArray(f);
|
|
399
398
|
this.holes = this.holes.map((h) => h.map(f));
|
|
400
399
|
return this;
|
|
401
400
|
}
|
|
401
|
+
mapArray(f) {
|
|
402
|
+
return this.pPoints.map(f);
|
|
403
|
+
}
|
|
402
404
|
sort(f) {
|
|
403
405
|
this.points.sort(f);
|
|
404
406
|
return this;
|
|
@@ -429,7 +431,7 @@ class DPolygon {
|
|
|
429
431
|
.reduce((a, h) => a + h.getValue(), ''));
|
|
430
432
|
}
|
|
431
433
|
toString() {
|
|
432
|
-
return `(${this.
|
|
434
|
+
return `(${this.mapArray((r) => r.toString()).join(', ')})`;
|
|
433
435
|
}
|
|
434
436
|
close() {
|
|
435
437
|
const p0 = this.first;
|
|
@@ -483,8 +485,11 @@ class DPolygon {
|
|
|
483
485
|
}
|
|
484
486
|
return false;
|
|
485
487
|
}
|
|
486
|
-
findIndex(
|
|
487
|
-
|
|
488
|
+
findIndex(a) {
|
|
489
|
+
if (a instanceof DPoint) {
|
|
490
|
+
return this.points.findIndex((t) => t.equal(a));
|
|
491
|
+
}
|
|
492
|
+
return this.points.findIndex(a);
|
|
488
493
|
}
|
|
489
494
|
approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
|
|
490
495
|
return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
|
|
@@ -508,36 +513,36 @@ class DPolygon {
|
|
|
508
513
|
return this.simpleIncludeX(p) && this.simpleIncludeY(p);
|
|
509
514
|
}
|
|
510
515
|
drawPolygonOnCanvas(canvas, fillColor, strokeColor, shadowColor, lineWidth = 1, steps = this.length - 1) {
|
|
511
|
-
if (this.length
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
ctx.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
ctx.stroke();
|
|
516
|
+
if (this.length > 1) {
|
|
517
|
+
const ctx = canvas.getContext('2d');
|
|
518
|
+
if (fillColor) {
|
|
519
|
+
ctx.fillStyle = fillColor;
|
|
520
|
+
}
|
|
521
|
+
if (strokeColor) {
|
|
522
|
+
ctx.strokeStyle = strokeColor;
|
|
523
|
+
}
|
|
524
|
+
if (lineWidth) {
|
|
525
|
+
ctx.lineWidth = lineWidth;
|
|
526
|
+
}
|
|
527
|
+
if (fillColor || strokeColor) {
|
|
528
|
+
ctx.beginPath();
|
|
529
|
+
}
|
|
530
|
+
this.goByPath(ctx, steps % this.length);
|
|
531
|
+
if (shadowColor) {
|
|
532
|
+
ctx.shadowColor = shadowColor;
|
|
533
|
+
ctx.shadowBlur = 0;
|
|
534
|
+
ctx.shadowOffsetX = 1;
|
|
535
|
+
ctx.shadowOffsetY = 1;
|
|
536
|
+
}
|
|
537
|
+
if (fillColor) {
|
|
538
|
+
ctx.closePath();
|
|
539
|
+
ctx.fill();
|
|
540
|
+
}
|
|
541
|
+
if (strokeColor) {
|
|
542
|
+
ctx.stroke();
|
|
543
|
+
}
|
|
540
544
|
}
|
|
545
|
+
return this;
|
|
541
546
|
}
|
|
542
547
|
clearPolygonOnCanvas(canvas) {
|
|
543
548
|
const ctx = canvas.getContext('2d');
|
|
@@ -559,8 +564,8 @@ class DPolygon {
|
|
|
559
564
|
const poly = this.deintersection;
|
|
560
565
|
let totalFi = 0;
|
|
561
566
|
for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
|
|
562
|
-
const line1 = new
|
|
563
|
-
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);
|
|
564
569
|
const fiDif = line1.findFi(line2);
|
|
565
570
|
if (line1.vectorProduct(line2).c > 0) {
|
|
566
571
|
totalFi += fiDif;
|
|
@@ -614,10 +619,10 @@ class DPolygon {
|
|
|
614
619
|
return this;
|
|
615
620
|
}
|
|
616
621
|
static parse(a) {
|
|
617
|
-
return new DPolygon(a.map((r) =>
|
|
622
|
+
return new DPolygon(a.map((r) => DPoint.parse(r)));
|
|
618
623
|
}
|
|
619
624
|
toArrayOfCoords() {
|
|
620
|
-
return this.
|
|
625
|
+
return this.mapArray((r) => r.toCoords());
|
|
621
626
|
}
|
|
622
627
|
divideToPieces(piecesCount) {
|
|
623
628
|
const { fullLength } = this;
|
|
@@ -630,7 +635,7 @@ class DPolygon {
|
|
|
630
635
|
currentPieceLength = pieceLength;
|
|
631
636
|
}
|
|
632
637
|
else if (d - currentPieceLength > 0) {
|
|
633
|
-
const circle = new
|
|
638
|
+
const circle = new DCircle(p1, currentPieceLength);
|
|
634
639
|
const line = p1.findLine(p2);
|
|
635
640
|
const intersectionPoint = line.intersectionWithCircle(circle)
|
|
636
641
|
.filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
|
|
@@ -842,13 +847,13 @@ class DPolygon {
|
|
|
842
847
|
return this.first.equal(this.last);
|
|
843
848
|
}
|
|
844
849
|
buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
|
|
845
|
-
const reader = new
|
|
850
|
+
const reader = new jstsIo.WKTReader();
|
|
846
851
|
const { noHoles, closed } = this;
|
|
847
852
|
const points = reader
|
|
848
853
|
.read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
|
|
849
854
|
.buffer(v, quadrantSegments, type)
|
|
850
855
|
.getCoordinates();
|
|
851
|
-
return new DPolygon(points.map(({ x, y }) => new
|
|
856
|
+
return new DPolygon(points.map(({ x, y }) => new DPoint(x, y)));
|
|
852
857
|
}
|
|
853
858
|
sideBuffers(v, quadrantSegments = 64) {
|
|
854
859
|
const { first, last } = this;
|
|
@@ -941,7 +946,7 @@ class DPolygon {
|
|
|
941
946
|
}
|
|
942
947
|
getJSTSGeometry(p, unionThis, unionThat) {
|
|
943
948
|
const unionOrIntersection = unionThat === unionThis;
|
|
944
|
-
const reader = new
|
|
949
|
+
const reader = new jstsIo.WKTReader();
|
|
945
950
|
const a = reader.read(this.noHoles.toWKT());
|
|
946
951
|
const b = reader.read(p.noHoles.toWKT());
|
|
947
952
|
if (!unionOrIntersection) {
|
|
@@ -962,11 +967,11 @@ class DPolygon {
|
|
|
962
967
|
if (coordinates.length) {
|
|
963
968
|
let result = coordinates.reduce((ak, { x, y }, index) => {
|
|
964
969
|
const lastIndex = ak.length - 1;
|
|
965
|
-
const t = new
|
|
970
|
+
const t = new DPoint(x, y);
|
|
966
971
|
const { first } = ak[lastIndex];
|
|
967
972
|
if (t.equal(first)) {
|
|
968
973
|
if (coordinates[index + 1]) {
|
|
969
|
-
const nextPoint = new
|
|
974
|
+
const nextPoint = new DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
|
|
970
975
|
if (ak[lastIndex].length > 1) {
|
|
971
976
|
ak.push(new DPolygon([nextPoint]));
|
|
972
977
|
}
|
|
@@ -976,7 +981,7 @@ class DPolygon {
|
|
|
976
981
|
ak[lastIndex].push(t);
|
|
977
982
|
}
|
|
978
983
|
return ak;
|
|
979
|
-
}, [new DPolygon([new
|
|
984
|
+
}, [new DPolygon([new DPoint(coordinates[0].x, coordinates[0].y)])]);
|
|
980
985
|
if (unionThat && unionThis && result.length > 1) {
|
|
981
986
|
for (const q of result) {
|
|
982
987
|
for (const r of result) {
|
|
@@ -1024,7 +1029,6 @@ class DPolygon {
|
|
|
1024
1029
|
return null;
|
|
1025
1030
|
}
|
|
1026
1031
|
}
|
|
1027
|
-
exports.DPolygon = DPolygon;
|
|
1028
1032
|
DPolygon.CAP_ROUND = CAP_ROUND;
|
|
1029
1033
|
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1030
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;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const FastSearch_1 = require("./FastSearch");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
var TraceMatrixValues;
|
|
1
|
+
import { DPoint } from './DPoint';
|
|
2
|
+
import { DPolygon, MIN_POINTS_IN_VALID_POLYGON } from './DPolygon';
|
|
3
|
+
import { FastSearch } from './FastSearch';
|
|
4
|
+
import { createArray } from './utils';
|
|
5
|
+
export var TraceMatrixValues;
|
|
9
6
|
(function (TraceMatrixValues) {
|
|
10
7
|
TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
|
|
11
8
|
TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
|
|
12
|
-
})(TraceMatrixValues
|
|
9
|
+
})(TraceMatrixValues || (TraceMatrixValues = {}));
|
|
13
10
|
const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
|
|
14
11
|
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
15
12
|
return defaultValue;
|
|
@@ -23,11 +20,11 @@ const setByPosition = (m, p, value) => {
|
|
|
23
20
|
m[p.y][p.x] = value;
|
|
24
21
|
return m[p.y][p.x];
|
|
25
22
|
};
|
|
26
|
-
class TraceMatrix {
|
|
23
|
+
export class TraceMatrix {
|
|
27
24
|
constructor(size, f) {
|
|
28
25
|
this.size = size;
|
|
29
26
|
this.findGroupByIndex = (m, s) => {
|
|
30
|
-
const res = new
|
|
27
|
+
const res = new DPolygon();
|
|
31
28
|
if (s && getByPosition(m, s) === TraceMatrixValues.t) {
|
|
32
29
|
res.push(s);
|
|
33
30
|
let startIndex = 0;
|
|
@@ -37,7 +34,7 @@ class TraceMatrix {
|
|
|
37
34
|
const r = res.at(startIndex);
|
|
38
35
|
for (let i = -1; i < 2; i++) {
|
|
39
36
|
for (let j = -1; j < 2; j++) {
|
|
40
|
-
const t = new
|
|
37
|
+
const t = new DPoint(r.x + i, r.y + j);
|
|
41
38
|
if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
|
|
42
39
|
getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
|
|
43
40
|
res.push(t);
|
|
@@ -59,7 +56,7 @@ class TraceMatrix {
|
|
|
59
56
|
const groups = [group];
|
|
60
57
|
let groupSum = group.length;
|
|
61
58
|
let allGroups = [...group.points];
|
|
62
|
-
const fs = new
|
|
59
|
+
const fs = new FastSearch();
|
|
63
60
|
fs.add(allGroups);
|
|
64
61
|
while (groupSum < this.totalCountInMatrix(m)) {
|
|
65
62
|
let mark = this.findMarked(m);
|
|
@@ -76,22 +73,22 @@ class TraceMatrix {
|
|
|
76
73
|
};
|
|
77
74
|
this.traceGroup = (m, group) => {
|
|
78
75
|
const traceDirections = [
|
|
79
|
-
new
|
|
80
|
-
new
|
|
81
|
-
new
|
|
82
|
-
new
|
|
83
|
-
new
|
|
84
|
-
new
|
|
85
|
-
new
|
|
86
|
-
new
|
|
76
|
+
new DPoint(-1, -1),
|
|
77
|
+
new DPoint(-1, 0),
|
|
78
|
+
new DPoint(-1, 1),
|
|
79
|
+
new DPoint(0, 1),
|
|
80
|
+
new DPoint(1, 1),
|
|
81
|
+
new DPoint(1, 0),
|
|
82
|
+
new DPoint(1, -1),
|
|
83
|
+
new DPoint(0, -1)
|
|
87
84
|
];
|
|
88
85
|
const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
|
|
89
86
|
const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
|
|
90
87
|
if (group.length < 2) {
|
|
91
88
|
const t = group.at(0).clone();
|
|
92
|
-
return new
|
|
89
|
+
return new DPolygon([t, t, t]);
|
|
93
90
|
}
|
|
94
|
-
const points = new
|
|
91
|
+
const points = new DPolygon();
|
|
95
92
|
let direction = 0;
|
|
96
93
|
let prevDirection = Infinity;
|
|
97
94
|
let p = group.at(0);
|
|
@@ -115,22 +112,22 @@ class TraceMatrix {
|
|
|
115
112
|
};
|
|
116
113
|
this.createHoleMatrix = (group) => {
|
|
117
114
|
const fullTraceDirections = [
|
|
118
|
-
new
|
|
119
|
-
new
|
|
120
|
-
new
|
|
121
|
-
new
|
|
115
|
+
new DPoint(-1, 0),
|
|
116
|
+
new DPoint(0, 1),
|
|
117
|
+
new DPoint(1, 0),
|
|
118
|
+
new DPoint(0, -1)
|
|
122
119
|
];
|
|
123
120
|
group.prepareToFastSearch();
|
|
124
121
|
const tmpMatrix = TraceMatrix
|
|
125
122
|
.createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
126
|
-
const startCoords = new
|
|
123
|
+
const startCoords = new DPolygon();
|
|
127
124
|
for (let i = 0; i < this.size.w; i++) {
|
|
128
|
-
startCoords.push(new
|
|
129
|
-
startCoords.push(new
|
|
125
|
+
startCoords.push(new DPoint(i, -1));
|
|
126
|
+
startCoords.push(new DPoint(i, this.size.h));
|
|
130
127
|
}
|
|
131
128
|
for (let i = 0; i < this.size.h; i++) {
|
|
132
|
-
startCoords.push(new
|
|
133
|
-
startCoords.push(new
|
|
129
|
+
startCoords.push(new DPoint(-1, i));
|
|
130
|
+
startCoords.push(new DPoint(this.size.w, i));
|
|
134
131
|
}
|
|
135
132
|
while (startCoords.length) {
|
|
136
133
|
const point = startCoords.pop();
|
|
@@ -154,7 +151,7 @@ class TraceMatrix {
|
|
|
154
151
|
const holeMatrixs = groups.map(this.createHoleMatrix);
|
|
155
152
|
const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
|
|
156
153
|
const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
|
|
157
|
-
.traceGroup(holeMatrixs[index], g)).filter((r) => r.length >
|
|
154
|
+
.traceGroup(holeMatrixs[index], g)).filter((r) => r.length > MIN_POINTS_IN_VALID_POLYGON));
|
|
158
155
|
return groups.map((g, index) => {
|
|
159
156
|
const res = paths[index];
|
|
160
157
|
if (holesGroups[index] && holesGroups[index].length) {
|
|
@@ -177,8 +174,8 @@ class TraceMatrix {
|
|
|
177
174
|
ini = true;
|
|
178
175
|
continue;
|
|
179
176
|
}
|
|
180
|
-
if (getByPosition(m, new
|
|
181
|
-
return new
|
|
177
|
+
if (getByPosition(m, new DPoint(i, j)) === TraceMatrixValues.t) {
|
|
178
|
+
return new DPoint(i, j);
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
181
|
}
|
|
@@ -189,7 +186,7 @@ class TraceMatrix {
|
|
|
189
186
|
const s = this.size;
|
|
190
187
|
for (let i = 0; i < s.w; i++) {
|
|
191
188
|
for (let j = 0; j < s.h; j++) {
|
|
192
|
-
if (getByPosition(m, new
|
|
189
|
+
if (getByPosition(m, new DPoint(i, j))) {
|
|
193
190
|
res++;
|
|
194
191
|
}
|
|
195
192
|
}
|
|
@@ -197,8 +194,7 @@ class TraceMatrix {
|
|
|
197
194
|
return res;
|
|
198
195
|
}
|
|
199
196
|
static createMatrix(size, f = () => TraceMatrixValues.f) {
|
|
200
|
-
return
|
|
201
|
-
.map((v, i) =>
|
|
197
|
+
return createArray(size.h)
|
|
198
|
+
.map((v, i) => createArray(size.w).map((v2, j) => f(new DPoint(j, i))));
|
|
202
199
|
}
|
|
203
200
|
}
|
|
204
|
-
exports.TraceMatrix = TraceMatrix;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './DCircle';
|
|
2
|
+
export * from './DLine';
|
|
3
|
+
export * from './DNumbers';
|
|
4
|
+
export * from './DPoint';
|
|
5
|
+
export * from './DPolygon';
|
|
6
|
+
export * from './FastSearch';
|
|
7
|
+
export * from './TraceMatrix';
|
|
8
|
+
export * from './DPolygonLoop';
|
|
9
|
+
export * from './DPlane';
|
|
10
|
+
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull } from './utils';
|
|
11
|
+
export const DGeo = {
|
|
12
|
+
DEBUG: false
|
|
13
|
+
};
|