dgeoutils 2.3.6 → 2.4.1
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/cjs/DCircle.js +52 -63
- package/dist/cjs/DLine.js +132 -181
- package/dist/cjs/DNumbers.js +16 -20
- package/dist/cjs/DPlane.js +56 -79
- package/dist/cjs/DPoint.js +240 -338
- package/dist/cjs/DPolygon.d.ts +1 -1
- package/dist/cjs/DPolygon.js +638 -1149
- package/dist/cjs/DPolygonLoop.js +138 -143
- package/dist/cjs/FastSearch.js +13 -37
- package/dist/cjs/TraceMatrix.js +87 -139
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/utils.d.ts +2 -1
- package/dist/cjs/utils.js +69 -97
- package/dist/es2015/DPolygon.js +5 -1
- package/dist/es2015/index.js +1 -1
- package/dist/es2015/utils.js +13 -0
- package/dist/esm/DPolygon.js +6 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils.js +13 -0
- package/dist/umd/dgeoutils.js +21 -2
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/TraceMatrix.js
CHANGED
|
@@ -1,81 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.TraceMatrix = exports.TraceMatrixValues = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const DPolygon_1 = require("./DPolygon");
|
|
6
|
+
const FastSearch_1 = require("./FastSearch");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
44
8
|
var TraceMatrixValues;
|
|
45
9
|
(function (TraceMatrixValues) {
|
|
46
10
|
TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
|
|
47
11
|
TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
|
|
48
12
|
})(TraceMatrixValues = exports.TraceMatrixValues || (exports.TraceMatrixValues = {}));
|
|
49
|
-
|
|
50
|
-
if (defaultValue === void 0) { defaultValue = TraceMatrixValues.f; }
|
|
13
|
+
const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
|
|
51
14
|
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
52
15
|
return defaultValue;
|
|
53
16
|
}
|
|
54
17
|
return m[p.y][p.x];
|
|
55
18
|
};
|
|
56
|
-
|
|
19
|
+
const setByPosition = (m, p, value) => {
|
|
57
20
|
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
58
21
|
return value;
|
|
59
22
|
}
|
|
60
23
|
m[p.y][p.x] = value;
|
|
61
24
|
return m[p.y][p.x];
|
|
62
25
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var _this = this;
|
|
26
|
+
class TraceMatrix {
|
|
27
|
+
constructor(size, f) {
|
|
66
28
|
this.size = size;
|
|
67
|
-
this.findGroupByIndex =
|
|
68
|
-
|
|
29
|
+
this.findGroupByIndex = (m, s) => {
|
|
30
|
+
const res = new DPolygon_1.DPolygon();
|
|
69
31
|
if (s && getByPosition(m, s) === TraceMatrixValues.t) {
|
|
70
32
|
res.push(s);
|
|
71
|
-
|
|
72
|
-
|
|
33
|
+
let startIndex = 0;
|
|
34
|
+
const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
|
|
73
35
|
setByPosition(marked, s, TraceMatrixValues.t);
|
|
74
36
|
while (startIndex < res.length) {
|
|
75
|
-
|
|
76
|
-
for (
|
|
77
|
-
for (
|
|
78
|
-
|
|
37
|
+
const r = res.at(startIndex);
|
|
38
|
+
for (let i = -1; i < 2; i++) {
|
|
39
|
+
for (let j = -1; j < 2; j++) {
|
|
40
|
+
const t = new DPoint_1.DPoint(r.x + i, r.y + j);
|
|
79
41
|
if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
|
|
80
42
|
getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
|
|
81
43
|
res.push(t);
|
|
@@ -88,32 +50,32 @@ var TraceMatrix = (function () {
|
|
|
88
50
|
}
|
|
89
51
|
return res;
|
|
90
52
|
};
|
|
91
|
-
this.findAllGroupsInMatrix =
|
|
92
|
-
|
|
53
|
+
this.findAllGroupsInMatrix = (m) => {
|
|
54
|
+
const firstMark = this.findMarked(m);
|
|
93
55
|
if (!firstMark) {
|
|
94
56
|
return [];
|
|
95
57
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
58
|
+
const group = this.findGroupByIndex(m, firstMark);
|
|
59
|
+
const groups = [group];
|
|
60
|
+
let groupSum = group.length;
|
|
61
|
+
let allGroups = [...group.points];
|
|
62
|
+
const fs = new FastSearch_1.FastSearch();
|
|
101
63
|
fs.add(allGroups);
|
|
102
|
-
while (groupSum <
|
|
103
|
-
|
|
64
|
+
while (groupSum < this.totalCountInMatrix(m)) {
|
|
65
|
+
let mark = this.findMarked(m);
|
|
104
66
|
while (mark && fs.find(mark)) {
|
|
105
|
-
mark =
|
|
67
|
+
mark = this.findMarked(m, mark);
|
|
106
68
|
}
|
|
107
|
-
|
|
69
|
+
const nextGroup = this.findGroupByIndex(m, mark);
|
|
108
70
|
groupSum += nextGroup.length;
|
|
109
|
-
allGroups =
|
|
71
|
+
allGroups = [...allGroups, ...nextGroup.points];
|
|
110
72
|
fs.add(nextGroup.points);
|
|
111
73
|
groups.push(nextGroup);
|
|
112
74
|
}
|
|
113
|
-
return groups.filter(
|
|
75
|
+
return groups.filter((g) => g.length > 2);
|
|
114
76
|
};
|
|
115
|
-
this.traceGroup =
|
|
116
|
-
|
|
77
|
+
this.traceGroup = (m, group) => {
|
|
78
|
+
const traceDirections = [
|
|
117
79
|
new DPoint_1.DPoint(-1, -1),
|
|
118
80
|
new DPoint_1.DPoint(-1, 0),
|
|
119
81
|
new DPoint_1.DPoint(-1, 1),
|
|
@@ -123,20 +85,20 @@ var TraceMatrix = (function () {
|
|
|
123
85
|
new DPoint_1.DPoint(1, -1),
|
|
124
86
|
new DPoint_1.DPoint(0, -1)
|
|
125
87
|
];
|
|
126
|
-
|
|
127
|
-
|
|
88
|
+
const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
|
|
89
|
+
const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
|
|
128
90
|
if (group.length < 2) {
|
|
129
|
-
|
|
91
|
+
const t = group.at(0).clone();
|
|
130
92
|
return new DPolygon_1.DPolygon([t, t, t]);
|
|
131
93
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
94
|
+
const points = new DPolygon_1.DPolygon();
|
|
95
|
+
let direction = 0;
|
|
96
|
+
let prevDirection = Infinity;
|
|
97
|
+
let p = group.at(0);
|
|
136
98
|
while (!p.equal(group.at(0)) || points.length < 2) {
|
|
137
99
|
while (true) {
|
|
138
|
-
|
|
139
|
-
|
|
100
|
+
const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
|
|
101
|
+
const nextNeighbourValue = getByPosition(m, p.clone().move(traceDirections[left(direction)]));
|
|
140
102
|
if (nextValue === TraceMatrixValues.t && nextNeighbourValue === TraceMatrixValues.f) {
|
|
141
103
|
break;
|
|
142
104
|
}
|
|
@@ -151,76 +113,64 @@ var TraceMatrix = (function () {
|
|
|
151
113
|
}
|
|
152
114
|
return points.approximation().close();
|
|
153
115
|
};
|
|
154
|
-
this.createHoleMatrix =
|
|
155
|
-
|
|
156
|
-
var fullTraceDirections = [
|
|
116
|
+
this.createHoleMatrix = (group) => {
|
|
117
|
+
const fullTraceDirections = [
|
|
157
118
|
new DPoint_1.DPoint(-1, 0),
|
|
158
119
|
new DPoint_1.DPoint(0, 1),
|
|
159
120
|
new DPoint_1.DPoint(1, 0),
|
|
160
121
|
new DPoint_1.DPoint(0, -1)
|
|
161
122
|
];
|
|
162
123
|
group.prepareToFastSearch();
|
|
163
|
-
|
|
164
|
-
.createMatrix(
|
|
165
|
-
|
|
166
|
-
for (
|
|
124
|
+
const tmpMatrix = TraceMatrix
|
|
125
|
+
.createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
126
|
+
const startCoords = new DPolygon_1.DPolygon();
|
|
127
|
+
for (let i = 0; i < this.size.w; i++) {
|
|
167
128
|
startCoords.push(new DPoint_1.DPoint(i, -1));
|
|
168
|
-
startCoords.push(new DPoint_1.DPoint(i,
|
|
129
|
+
startCoords.push(new DPoint_1.DPoint(i, this.size.h));
|
|
169
130
|
}
|
|
170
|
-
for (
|
|
131
|
+
for (let i = 0; i < this.size.h; i++) {
|
|
171
132
|
startCoords.push(new DPoint_1.DPoint(-1, i));
|
|
172
|
-
startCoords.push(new DPoint_1.DPoint(
|
|
133
|
+
startCoords.push(new DPoint_1.DPoint(this.size.w, i));
|
|
173
134
|
}
|
|
174
135
|
while (startCoords.length) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
183
|
-
startCoords.push(tmpPoint);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
188
|
-
finally {
|
|
189
|
-
try {
|
|
190
|
-
if (fullTraceDirections_1_1 && !fullTraceDirections_1_1.done && (_a = fullTraceDirections_1.return)) _a.call(fullTraceDirections_1);
|
|
136
|
+
const point = startCoords.pop();
|
|
137
|
+
for (const direction of fullTraceDirections) {
|
|
138
|
+
const tmpPoint = point.clone().move(direction);
|
|
139
|
+
const value = getByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
140
|
+
if (value === TraceMatrixValues.f) {
|
|
141
|
+
setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
142
|
+
startCoords.push(tmpPoint);
|
|
191
143
|
}
|
|
192
|
-
finally { if (e_1) throw e_1.error; }
|
|
193
144
|
}
|
|
194
145
|
}
|
|
195
|
-
|
|
196
|
-
return
|
|
146
|
+
const t = this.reverseMatrix(tmpMatrix);
|
|
147
|
+
return this.totalCountInMatrix(t) ? t : null;
|
|
197
148
|
};
|
|
198
149
|
this.m = TraceMatrix.createMatrix(this.size, f);
|
|
199
150
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
var res = paths[index];
|
|
151
|
+
fullMatrixTrace() {
|
|
152
|
+
const groups = this.findAllGroupsInMatrix(this.m);
|
|
153
|
+
const paths = groups.map((g) => this.traceGroup(this.m, g));
|
|
154
|
+
const holeMatrixs = groups.map(this.createHoleMatrix);
|
|
155
|
+
const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
|
|
156
|
+
const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
|
|
157
|
+
.traceGroup(holeMatrixs[index], g)).filter((r) => r.length > DPolygon_1.MIN_POINTS_IN_VALID_POLYGON));
|
|
158
|
+
return groups.map((g, index) => {
|
|
159
|
+
const res = paths[index];
|
|
210
160
|
if (holesGroups[index] && holesGroups[index].length) {
|
|
211
161
|
res.holes = holesPaths[index];
|
|
212
162
|
}
|
|
213
163
|
return res;
|
|
214
164
|
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return TraceMatrix.createMatrix(this.size,
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
for (
|
|
223
|
-
for (
|
|
165
|
+
}
|
|
166
|
+
reverseMatrix(m) {
|
|
167
|
+
return TraceMatrix.createMatrix(this.size, (p) => getByPosition(m, p) === TraceMatrixValues.f ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
168
|
+
}
|
|
169
|
+
findMarked(m, init) {
|
|
170
|
+
const s = this.size;
|
|
171
|
+
let ini = false;
|
|
172
|
+
for (let i = 0; i < s.w; i++) {
|
|
173
|
+
for (let j = 0; j < s.h; j++) {
|
|
224
174
|
if (!ini && init) {
|
|
225
175
|
i = init.x;
|
|
226
176
|
j = init.y;
|
|
@@ -233,24 +183,22 @@ var TraceMatrix = (function () {
|
|
|
233
183
|
}
|
|
234
184
|
}
|
|
235
185
|
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
for (
|
|
241
|
-
for (
|
|
186
|
+
}
|
|
187
|
+
totalCountInMatrix(m) {
|
|
188
|
+
let res = 0;
|
|
189
|
+
const s = this.size;
|
|
190
|
+
for (let i = 0; i < s.w; i++) {
|
|
191
|
+
for (let j = 0; j < s.h; j++) {
|
|
242
192
|
if (getByPosition(m, new DPoint_1.DPoint(i, j))) {
|
|
243
193
|
res++;
|
|
244
194
|
}
|
|
245
195
|
}
|
|
246
196
|
}
|
|
247
197
|
return res;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (f === void 0) { f = function () { return TraceMatrixValues.f; }; }
|
|
198
|
+
}
|
|
199
|
+
static createMatrix(size, f = () => TraceMatrixValues.f) {
|
|
251
200
|
return (0, utils_1.createArray)(size.h)
|
|
252
|
-
.map(
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
}());
|
|
201
|
+
.map((v, i) => (0, utils_1.createArray)(size.w).map((v2, j) => f(new DPoint_1.DPoint(j, i))));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
256
204
|
exports.TraceMatrix = TraceMatrix;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export * from './FastSearch';
|
|
|
7
7
|
export * from './TraceMatrix';
|
|
8
8
|
export * from './DPolygonLoop';
|
|
9
9
|
export * from './DPlane';
|
|
10
|
-
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, DGeo } from './utils';
|
|
10
|
+
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.DGeo = exports.cartesianProduct = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
|
|
13
|
+
exports.DGeo = exports.getCombinations = exports.cartesianProduct = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
|
|
14
14
|
__exportStar(require("./DCircle"), exports);
|
|
15
15
|
__exportStar(require("./DLine"), exports);
|
|
16
16
|
__exportStar(require("./DNumbers"), exports);
|
|
@@ -27,4 +27,5 @@ Object.defineProperty(exports, "createArray", { enumerable: true, get: function
|
|
|
27
27
|
Object.defineProperty(exports, "createMatrix", { enumerable: true, get: function () { return utils_1.createMatrix; } });
|
|
28
28
|
Object.defineProperty(exports, "isDefAndNotNull", { enumerable: true, get: function () { return utils_1.isDefAndNotNull; } });
|
|
29
29
|
Object.defineProperty(exports, "cartesianProduct", { enumerable: true, get: function () { return utils_1.cartesianProduct; } });
|
|
30
|
+
Object.defineProperty(exports, "getCombinations", { enumerable: true, get: function () { return utils_1.getCombinations; } });
|
|
30
31
|
Object.defineProperty(exports, "DGeo", { enumerable: true, get: function () { return utils_1.DGeo; } });
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare const createCanvas: {
|
|
|
36
36
|
document?: Document;
|
|
37
37
|
};
|
|
38
38
|
export declare const cartesianProduct: {
|
|
39
|
-
<T>(
|
|
39
|
+
<T>(a: T[], ...b: T[][]): T[][];
|
|
40
40
|
};
|
|
41
|
+
export declare const getCombinations: <T>(arr: T[][]) => T[][];
|
|
41
42
|
export {};
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,87 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
|
|
29
|
-
|
|
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");
|
|
30
5
|
exports.DGeo = {
|
|
31
6
|
DEBUG: false
|
|
32
7
|
};
|
|
33
|
-
|
|
34
|
-
var args = [];
|
|
35
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
36
|
-
args[_i] = arguments[_i];
|
|
37
|
-
}
|
|
8
|
+
const warn = (...args) => {
|
|
38
9
|
if (exports.DGeo.DEBUG) {
|
|
39
|
-
console.warn
|
|
10
|
+
console.warn(...args);
|
|
40
11
|
}
|
|
41
12
|
};
|
|
42
13
|
exports.warn = warn;
|
|
43
|
-
|
|
14
|
+
const isDefAndNotNull = (a) => a != undefined;
|
|
44
15
|
exports.isDefAndNotNull = isDefAndNotNull;
|
|
45
|
-
|
|
46
|
-
|
|
16
|
+
const hook = (scope) => () => scope;
|
|
17
|
+
const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
47
18
|
if (!p.clone().round()
|
|
48
19
|
.equal(p)) {
|
|
49
|
-
(0, exports.warn)("
|
|
20
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be Int!`);
|
|
50
21
|
}
|
|
51
22
|
return scope;
|
|
52
|
-
};
|
|
53
|
-
|
|
23
|
+
};
|
|
24
|
+
const shouldBeUInt = (scope, funcName, argName) => (p) => {
|
|
54
25
|
if (!p.clone().round()
|
|
55
26
|
.equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
|
|
56
|
-
(0, exports.warn)("
|
|
27
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be UInt!`);
|
|
57
28
|
}
|
|
58
29
|
return scope;
|
|
59
|
-
};
|
|
60
|
-
|
|
30
|
+
};
|
|
31
|
+
const shouldBeDegree = (scope, funcName, argName) => (p) => {
|
|
61
32
|
if (!p.likeWorldGeodeticSystem) {
|
|
62
|
-
(0, exports.warn)("
|
|
33
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be degree!`);
|
|
63
34
|
}
|
|
64
35
|
return scope;
|
|
65
|
-
};
|
|
66
|
-
|
|
36
|
+
};
|
|
37
|
+
const shouldBeRadians = (scope, funcName, argName) => (p) => {
|
|
67
38
|
if (!p.likeRadians) {
|
|
68
|
-
(0, exports.warn)("
|
|
39
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be radians!`);
|
|
69
40
|
}
|
|
70
41
|
return scope;
|
|
71
|
-
};
|
|
72
|
-
|
|
42
|
+
};
|
|
43
|
+
const shouldExist = (scope, funcName, argName) => (p) => {
|
|
73
44
|
if (!(0, exports.isDefAndNotNull)(p)) {
|
|
74
|
-
(0, exports.warn)("
|
|
45
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should exist!`);
|
|
75
46
|
}
|
|
76
47
|
return scope;
|
|
77
|
-
};
|
|
78
|
-
|
|
48
|
+
};
|
|
49
|
+
const shouldBeMeters = (scope, funcName, argName) => (p) => {
|
|
79
50
|
if (!p.likePseudoMercator) {
|
|
80
|
-
(0, exports.warn)("
|
|
51
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be meters!`);
|
|
81
52
|
}
|
|
82
53
|
return scope;
|
|
83
|
-
};
|
|
84
|
-
|
|
54
|
+
};
|
|
55
|
+
const checkFunction = (funcName) => ({
|
|
85
56
|
checkArgument: function (argName) {
|
|
86
57
|
if (!exports.DGeo.DEBUG) {
|
|
87
58
|
return {
|
|
@@ -102,71 +73,64 @@ var checkFunction = function (funcName) { return ({
|
|
|
102
73
|
shouldExist: shouldExist(this, funcName, argName)
|
|
103
74
|
};
|
|
104
75
|
}
|
|
105
|
-
});
|
|
76
|
+
});
|
|
106
77
|
exports.checkFunction = checkFunction;
|
|
107
|
-
|
|
108
|
-
if (fillSymbol === void 0) { fillSymbol = 0; }
|
|
109
|
-
return new Array(v).fill(fillSymbol);
|
|
110
|
-
};
|
|
78
|
+
const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
|
|
111
79
|
exports.createArray = createArray;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (fillSymbol === void 0) { fillSymbol = 0; }
|
|
115
|
-
return (0, exports.createArray)(h)
|
|
116
|
-
.map(function () { return (0, exports.createArray)(w, fillSymbol); });
|
|
117
|
-
};
|
|
80
|
+
const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
|
|
81
|
+
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
118
82
|
exports.createMatrix = createMatrix;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (
|
|
123
|
-
for (
|
|
83
|
+
const gaussianElimination = (matrix) => {
|
|
84
|
+
const n = matrix.length;
|
|
85
|
+
const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
for (let j = 0; j < n + 1; j++) {
|
|
124
88
|
matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
|
|
125
89
|
matrixClone[i][j] = matrix[i][j];
|
|
126
90
|
}
|
|
127
91
|
}
|
|
128
|
-
for (
|
|
129
|
-
for (
|
|
92
|
+
for (let k = 0; k < n; k++) {
|
|
93
|
+
for (let i = 0; i < n + 1; i++) {
|
|
130
94
|
matrixClone[k][i] /= matrix[k][k];
|
|
131
95
|
}
|
|
132
|
-
for (
|
|
133
|
-
|
|
134
|
-
for (
|
|
96
|
+
for (let i = k + 1; i < n; i++) {
|
|
97
|
+
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
98
|
+
for (let j = 0; j < n + 1; j++) {
|
|
135
99
|
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
136
100
|
}
|
|
137
101
|
}
|
|
138
|
-
for (
|
|
139
|
-
for (
|
|
102
|
+
for (let i = 0; i < n; i++) {
|
|
103
|
+
for (let j = 0; j < n + 1; j++) {
|
|
140
104
|
matrix[i][j] = matrixClone[i][j];
|
|
141
105
|
}
|
|
142
106
|
}
|
|
143
107
|
}
|
|
144
|
-
for (
|
|
145
|
-
for (
|
|
108
|
+
for (let k = n - 1; k > -1; k--) {
|
|
109
|
+
for (let i = n; i > -1; i--) {
|
|
146
110
|
matrixClone[k][i] /= matrix[k][k];
|
|
147
111
|
}
|
|
148
|
-
for (
|
|
149
|
-
|
|
150
|
-
for (
|
|
112
|
+
for (let i = k - 1; i > -1; i--) {
|
|
113
|
+
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
114
|
+
for (let j = n; j > -1; j--) {
|
|
151
115
|
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
152
116
|
}
|
|
153
117
|
}
|
|
154
118
|
}
|
|
155
|
-
|
|
156
|
-
for (
|
|
119
|
+
const answer = (0, exports.createArray)(n);
|
|
120
|
+
for (let i = 0; i < n; i++) {
|
|
157
121
|
answer[i] = matrixClone[i][n];
|
|
158
122
|
}
|
|
159
123
|
return answer;
|
|
160
124
|
};
|
|
161
125
|
exports.gaussianElimination = gaussianElimination;
|
|
162
126
|
exports.gaussianElimination.MIN = 1e-10;
|
|
163
|
-
|
|
127
|
+
const createCanvas = (a, b, c) => {
|
|
164
128
|
var _a;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
129
|
+
let w = 0;
|
|
130
|
+
let h = 0;
|
|
131
|
+
let offscreen = false;
|
|
168
132
|
if (a instanceof DPoint_1.DPoint) {
|
|
169
|
-
|
|
133
|
+
const { x, y } = a;
|
|
170
134
|
w = x;
|
|
171
135
|
h = y;
|
|
172
136
|
}
|
|
@@ -183,7 +147,7 @@ var createCanvas = function (a, b, c) {
|
|
|
183
147
|
if (typeof c === 'boolean') {
|
|
184
148
|
offscreen = c;
|
|
185
149
|
}
|
|
186
|
-
|
|
150
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
187
151
|
if (!offscreen) {
|
|
188
152
|
canvas.width = w;
|
|
189
153
|
canvas.height = h;
|
|
@@ -191,12 +155,20 @@ var createCanvas = function (a, b, c) {
|
|
|
191
155
|
return [canvas, canvas.getContext('2d')];
|
|
192
156
|
};
|
|
193
157
|
exports.createCanvas = createCanvas;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
158
|
+
const f = (a, b) => [].concat(...a.map((c) => b.map((d) => [].concat(c, d))));
|
|
159
|
+
const cartesianProduct = (a, b, ...c) => b ? (0, exports.cartesianProduct)(f(a, b), ...c) : a;
|
|
160
|
+
exports.cartesianProduct = cartesianProduct;
|
|
161
|
+
const getCombinations = (arr) => {
|
|
162
|
+
if (arr.length === 1) {
|
|
163
|
+
return arr[0];
|
|
164
|
+
}
|
|
165
|
+
const ans = [];
|
|
166
|
+
const otherCases = (0, exports.getCombinations)(arr.slice(1));
|
|
167
|
+
for (let i = 0; i < otherCases.length; i++) {
|
|
168
|
+
for (let j = 0; j < arr[0].length; j++) {
|
|
169
|
+
ans.push([arr[0][j], ...otherCases[i]]);
|
|
170
|
+
}
|
|
199
171
|
}
|
|
200
|
-
return
|
|
172
|
+
return ans;
|
|
201
173
|
};
|
|
202
|
-
exports.
|
|
174
|
+
exports.getCombinations = getCombinations;
|
package/dist/es2015/DPolygon.js
CHANGED
|
@@ -624,7 +624,7 @@ export class DPolygon {
|
|
|
624
624
|
toArrayOfCoords() {
|
|
625
625
|
return this.mapArray((r) => r.toCoords());
|
|
626
626
|
}
|
|
627
|
-
divideToPieces(piecesCount) {
|
|
627
|
+
divideToPieces(piecesCount, withAltitude = false) {
|
|
628
628
|
const { fullLength } = this;
|
|
629
629
|
const pieceLength = fullLength / piecesCount;
|
|
630
630
|
let currentPieceLength = pieceLength;
|
|
@@ -641,6 +641,10 @@ export class DPolygon {
|
|
|
641
641
|
.filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
|
|
642
642
|
intersectionPoint.properties.pieceBorder = true;
|
|
643
643
|
this.insertAfter(i, intersectionPoint);
|
|
644
|
+
if (withAltitude) {
|
|
645
|
+
const p1z = p1.z;
|
|
646
|
+
intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
|
|
647
|
+
}
|
|
644
648
|
currentPieceLength = pieceLength;
|
|
645
649
|
}
|
|
646
650
|
else {
|
package/dist/es2015/index.js
CHANGED
|
@@ -7,4 +7,4 @@ export * from './FastSearch';
|
|
|
7
7
|
export * from './TraceMatrix';
|
|
8
8
|
export * from './DPolygonLoop';
|
|
9
9
|
export * from './DPlane';
|
|
10
|
-
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, DGeo } from './utils';
|
|
10
|
+
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
|