dgeoutils 2.4.2 → 2.4.3
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 +310 -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 +1560 -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} +5 -1
- package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
- package/dist/cjs/utils.js +216 -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 +10 -0
- package/dist/{utils.js → es2015/utils.js} +29 -41
- package/dist/esm/DCircle.js +1 -1
- package/dist/esm/DLine.js +2 -2
- package/dist/esm/DPoint.js +2 -2
- package/dist/esm/DPolygon.js +8 -8
- package/dist/esm/utils.js +6 -6
- package/dist/umd/dgeoutils.js +26 -26
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +8 -13
- 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/dist/jsts.js';
|
|
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];
|
|
@@ -854,13 +851,13 @@ class DPolygon {
|
|
|
854
851
|
return this.first.equal(this.last);
|
|
855
852
|
}
|
|
856
853
|
buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
|
|
857
|
-
const reader = new
|
|
854
|
+
const reader = new jstsIo.WKTReader();
|
|
858
855
|
const { noHoles, closed } = this;
|
|
859
856
|
const points = reader
|
|
860
857
|
.read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
|
|
861
858
|
.buffer(v, quadrantSegments, type)
|
|
862
859
|
.getCoordinates();
|
|
863
|
-
return new DPolygon(points.map(({ x, y }) => new
|
|
860
|
+
return new DPolygon(points.map(({ x, y }) => new DPoint(x, y)));
|
|
864
861
|
}
|
|
865
862
|
sideBuffers(v, quadrantSegments = 64) {
|
|
866
863
|
const { first, last } = this;
|
|
@@ -953,7 +950,7 @@ class DPolygon {
|
|
|
953
950
|
}
|
|
954
951
|
getJSTSGeometry(p, unionThis, unionThat) {
|
|
955
952
|
const unionOrIntersection = unionThat === unionThis;
|
|
956
|
-
const reader = new
|
|
953
|
+
const reader = new jstsIo.WKTReader();
|
|
957
954
|
const a = reader.read(this.noHoles.toWKT());
|
|
958
955
|
const b = reader.read(p.noHoles.toWKT());
|
|
959
956
|
if (!unionOrIntersection) {
|
|
@@ -974,11 +971,11 @@ class DPolygon {
|
|
|
974
971
|
if (coordinates.length) {
|
|
975
972
|
let result = coordinates.reduce((ak, { x, y }, index) => {
|
|
976
973
|
const lastIndex = ak.length - 1;
|
|
977
|
-
const t = new
|
|
974
|
+
const t = new DPoint(x, y);
|
|
978
975
|
const { first } = ak[lastIndex];
|
|
979
976
|
if (t.equal(first)) {
|
|
980
977
|
if (coordinates[index + 1]) {
|
|
981
|
-
const nextPoint = new
|
|
978
|
+
const nextPoint = new DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
|
|
982
979
|
if (ak[lastIndex].length > 1) {
|
|
983
980
|
ak.push(new DPolygon([nextPoint]));
|
|
984
981
|
}
|
|
@@ -988,7 +985,7 @@ class DPolygon {
|
|
|
988
985
|
ak[lastIndex].push(t);
|
|
989
986
|
}
|
|
990
987
|
return ak;
|
|
991
|
-
}, [new DPolygon([new
|
|
988
|
+
}, [new DPolygon([new DPoint(coordinates[0].x, coordinates[0].y)])]);
|
|
992
989
|
if (unionThat && unionThis && result.length > 1) {
|
|
993
990
|
for (const q of result) {
|
|
994
991
|
for (const r of result) {
|
|
@@ -1036,7 +1033,6 @@ class DPolygon {
|
|
|
1036
1033
|
return null;
|
|
1037
1034
|
}
|
|
1038
1035
|
}
|
|
1039
|
-
exports.DPolygon = DPolygon;
|
|
1040
1036
|
DPolygon.CAP_ROUND = CAP_ROUND;
|
|
1041
1037
|
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1042
1038
|
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,10 @@
|
|
|
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, cartesianProduct, getCombinations, DGeo } from './utils';
|
|
@@ -1,60 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
|
|
4
|
-
const DPoint_1 = require("./DPoint");
|
|
5
|
-
exports.DGeo = {
|
|
1
|
+
import { DPoint } from './DPoint';
|
|
2
|
+
export const DGeo = {
|
|
6
3
|
DEBUG: false
|
|
7
4
|
};
|
|
8
|
-
const warn = (...args) => {
|
|
9
|
-
if (
|
|
5
|
+
export const warn = (...args) => {
|
|
6
|
+
if (DGeo.DEBUG) {
|
|
10
7
|
console.warn(...args);
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const isDefAndNotNull = (a) => a != undefined;
|
|
15
|
-
exports.isDefAndNotNull = isDefAndNotNull;
|
|
10
|
+
export const isDefAndNotNull = (a) => a != undefined;
|
|
16
11
|
const hook = (scope) => () => scope;
|
|
17
12
|
const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
18
13
|
if (!p.clone().round()
|
|
19
14
|
.equal(p)) {
|
|
20
|
-
|
|
15
|
+
warn(`"${funcName}" -> "${argName}" should be Int!`);
|
|
21
16
|
}
|
|
22
17
|
return scope;
|
|
23
18
|
};
|
|
24
19
|
const shouldBeUInt = (scope, funcName, argName) => (p) => {
|
|
25
20
|
if (!p.clone().round()
|
|
26
|
-
.equal(p) || !p.gtOrEqual(
|
|
27
|
-
|
|
21
|
+
.equal(p) || !p.gtOrEqual(DPoint.zero())) {
|
|
22
|
+
warn(`"${funcName}" -> "${argName}" should be UInt!`);
|
|
28
23
|
}
|
|
29
24
|
return scope;
|
|
30
25
|
};
|
|
31
26
|
const shouldBeDegree = (scope, funcName, argName) => (p) => {
|
|
32
27
|
if (!p.likeWorldGeodeticSystem) {
|
|
33
|
-
|
|
28
|
+
warn(`"${funcName}" -> "${argName}" should be degree!`);
|
|
34
29
|
}
|
|
35
30
|
return scope;
|
|
36
31
|
};
|
|
37
32
|
const shouldBeRadians = (scope, funcName, argName) => (p) => {
|
|
38
33
|
if (!p.likeRadians) {
|
|
39
|
-
|
|
34
|
+
warn(`"${funcName}" -> "${argName}" should be radians!`);
|
|
40
35
|
}
|
|
41
36
|
return scope;
|
|
42
37
|
};
|
|
43
38
|
const shouldExist = (scope, funcName, argName) => (p) => {
|
|
44
|
-
if (!
|
|
45
|
-
|
|
39
|
+
if (!isDefAndNotNull(p)) {
|
|
40
|
+
warn(`"${funcName}" -> "${argName}" should exist!`);
|
|
46
41
|
}
|
|
47
42
|
return scope;
|
|
48
43
|
};
|
|
49
44
|
const shouldBeMeters = (scope, funcName, argName) => (p) => {
|
|
50
45
|
if (!p.likePseudoMercator) {
|
|
51
|
-
|
|
46
|
+
warn(`"${funcName}" -> "${argName}" should be meters!`);
|
|
52
47
|
}
|
|
53
48
|
return scope;
|
|
54
49
|
};
|
|
55
|
-
const checkFunction = (funcName) => ({
|
|
50
|
+
export const checkFunction = (funcName) => ({
|
|
56
51
|
checkArgument: function (argName) {
|
|
57
|
-
if (!
|
|
52
|
+
if (!DGeo.DEBUG) {
|
|
58
53
|
return {
|
|
59
54
|
shouldBeDegree: hook(this),
|
|
60
55
|
shouldBeMeters: hook(this),
|
|
@@ -74,18 +69,15 @@ const checkFunction = (funcName) => ({
|
|
|
74
69
|
};
|
|
75
70
|
}
|
|
76
71
|
});
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
82
|
-
exports.createMatrix = createMatrix;
|
|
83
|
-
const gaussianElimination = (matrix) => {
|
|
72
|
+
export const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
|
|
73
|
+
export const createMatrix = ({ h, w }, fillSymbol = 0) => createArray(h)
|
|
74
|
+
.map(() => createArray(w, fillSymbol));
|
|
75
|
+
export const gaussianElimination = (matrix) => {
|
|
84
76
|
const n = matrix.length;
|
|
85
|
-
const matrixClone =
|
|
77
|
+
const matrixClone = createMatrix(new DPoint(n + 1, n));
|
|
86
78
|
for (let i = 0; i < n; i++) {
|
|
87
79
|
for (let j = 0; j < n + 1; j++) {
|
|
88
|
-
matrix[i][j] = matrix[i][j] === 0 ?
|
|
80
|
+
matrix[i][j] = matrix[i][j] === 0 ? gaussianElimination.MIN : matrix[i][j];
|
|
89
81
|
matrixClone[i][j] = matrix[i][j];
|
|
90
82
|
}
|
|
91
83
|
}
|
|
@@ -116,20 +108,19 @@ const gaussianElimination = (matrix) => {
|
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
|
-
const answer =
|
|
111
|
+
const answer = createArray(n);
|
|
120
112
|
for (let i = 0; i < n; i++) {
|
|
121
113
|
answer[i] = matrixClone[i][n];
|
|
122
114
|
}
|
|
123
115
|
return answer;
|
|
124
116
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const createCanvas = (a, b, c) => {
|
|
117
|
+
gaussianElimination.MIN = 1e-10;
|
|
118
|
+
export const createCanvas = (a, b, c) => {
|
|
128
119
|
var _a;
|
|
129
120
|
let w = 0;
|
|
130
121
|
let h = 0;
|
|
131
122
|
let offscreen = false;
|
|
132
|
-
if (a instanceof
|
|
123
|
+
if (a instanceof DPoint) {
|
|
133
124
|
const { x, y } = a;
|
|
134
125
|
w = x;
|
|
135
126
|
h = y;
|
|
@@ -147,23 +138,21 @@ const createCanvas = (a, b, c) => {
|
|
|
147
138
|
if (typeof c === 'boolean') {
|
|
148
139
|
offscreen = c;
|
|
149
140
|
}
|
|
150
|
-
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a =
|
|
141
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
151
142
|
if (!offscreen) {
|
|
152
143
|
canvas.width = w;
|
|
153
144
|
canvas.height = h;
|
|
154
145
|
}
|
|
155
146
|
return [canvas, canvas.getContext('2d')];
|
|
156
147
|
};
|
|
157
|
-
exports.createCanvas = createCanvas;
|
|
158
148
|
const f = (a, b) => [].concat(...a.map((c) => b.map((d) => [].concat(c, d))));
|
|
159
|
-
const cartesianProduct = (a, b, ...c) => b ?
|
|
160
|
-
|
|
161
|
-
const getCombinations = (arr) => {
|
|
149
|
+
export const cartesianProduct = (a, b, ...c) => b ? cartesianProduct(f(a, b), ...c) : a;
|
|
150
|
+
export const getCombinations = (arr) => {
|
|
162
151
|
if (arr.length === 1) {
|
|
163
152
|
return arr[0];
|
|
164
153
|
}
|
|
165
154
|
const ans = [];
|
|
166
|
-
const otherCases =
|
|
155
|
+
const otherCases = getCombinations(arr.slice(1));
|
|
167
156
|
for (let i = 0; i < otherCases.length; i++) {
|
|
168
157
|
for (let j = 0; j < arr[0].length; j++) {
|
|
169
158
|
ans.push([arr[0][j], ...otherCases[i]]);
|
|
@@ -171,4 +160,3 @@ const getCombinations = (arr) => {
|
|
|
171
160
|
}
|
|
172
161
|
return ans;
|
|
173
162
|
};
|
|
174
|
-
exports.getCombinations = getCombinations;
|
package/dist/esm/DCircle.js
CHANGED
|
@@ -9,7 +9,7 @@ var DCircle = (function () {
|
|
|
9
9
|
this.r = r;
|
|
10
10
|
}
|
|
11
11
|
DCircle.prototype.toString = function () {
|
|
12
|
-
return "("
|
|
12
|
+
return "(".concat(this.center.toString(), ", ").concat(this.r, ")");
|
|
13
13
|
};
|
|
14
14
|
DCircle.prototype.getValue = function () {
|
|
15
15
|
return { center: this.center, r: this.r };
|
package/dist/esm/DLine.js
CHANGED
|
@@ -156,7 +156,7 @@ var DLine = (function () {
|
|
|
156
156
|
configurable: true
|
|
157
157
|
});
|
|
158
158
|
DLine.prototype.toString = function () {
|
|
159
|
-
return "("
|
|
159
|
+
return "(".concat(this.a, ", ").concat(this.b, ", ").concat(this.c, ")");
|
|
160
160
|
};
|
|
161
161
|
DLine.prototype.getValue = function () {
|
|
162
162
|
return [this.a, this.b, this.c];
|
|
@@ -257,7 +257,7 @@ var DLine = (function () {
|
|
|
257
257
|
};
|
|
258
258
|
DLine.prototype.toWKT = function () {
|
|
259
259
|
var _a = this, _b = _a.begin, x1 = _b.x, y1 = _b.y, _c = _a.end, x2 = _c.x, y2 = _c.y;
|
|
260
|
-
return "LINESTRING ("
|
|
260
|
+
return "LINESTRING (".concat(x1, " ").concat(y1, ", ").concat(x2, " ").concat(y2, ")");
|
|
261
261
|
};
|
|
262
262
|
DLine.prototype.movePoint = function (i, k) {
|
|
263
263
|
var isArray = Array.isArray(i);
|
package/dist/esm/DPoint.js
CHANGED
|
@@ -133,7 +133,7 @@ var DPoint = (function () {
|
|
|
133
133
|
return a2 + Math.PI * 2 - a1;
|
|
134
134
|
};
|
|
135
135
|
DPoint.prototype.toString = function () {
|
|
136
|
-
return this.x
|
|
136
|
+
return "".concat(this.x, " ").concat(this.y);
|
|
137
137
|
};
|
|
138
138
|
DPoint.prototype.getValue = function () {
|
|
139
139
|
return [this.x, this.y];
|
|
@@ -144,7 +144,7 @@ var DPoint = (function () {
|
|
|
144
144
|
};
|
|
145
145
|
DPoint.prototype.toWKT = function () {
|
|
146
146
|
var _a = this, x = _a.x, y = _a.y;
|
|
147
|
-
return "POINT ("
|
|
147
|
+
return "POINT (".concat(x, " ").concat(y, ")");
|
|
148
148
|
};
|
|
149
149
|
DPoint.prototype.distance = function (p) {
|
|
150
150
|
checkFunction('distance')
|