dgeoutils 2.4.1 → 2.4.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/dist/{cjs/DCircle.d.ts → DCircle.d.ts} +0 -0
- package/dist/{cjs/DCircle.js → DCircle.js} +0 -0
- package/dist/{cjs/DLine.d.ts → DLine.d.ts} +0 -0
- package/dist/{cjs/DLine.js → DLine.js} +0 -0
- package/dist/{cjs/DNumbers.d.ts → DNumbers.d.ts} +0 -0
- package/dist/{cjs/DNumbers.js → DNumbers.js} +0 -0
- package/dist/{cjs/DPlane.d.ts → DPlane.d.ts} +0 -0
- package/dist/{cjs/DPlane.js → DPlane.js} +0 -0
- package/dist/{cjs/DPoint.d.ts → DPoint.d.ts} +0 -0
- package/dist/{cjs/DPoint.js → DPoint.js} +0 -0
- package/dist/{cjs/DPolygon.d.ts → DPolygon.d.ts} +0 -0
- package/dist/{cjs/DPolygon.js → DPolygon.js} +0 -0
- package/dist/{cjs/DPolygonLoop.d.ts → DPolygonLoop.d.ts} +0 -0
- package/dist/{cjs/DPolygonLoop.js → DPolygonLoop.js} +0 -0
- package/dist/{cjs/FastSearch.d.ts → FastSearch.d.ts} +0 -0
- package/dist/{cjs/FastSearch.js → FastSearch.js} +0 -0
- package/dist/{cjs/TraceMatrix.d.ts → TraceMatrix.d.ts} +0 -0
- package/dist/{cjs/TraceMatrix.js → TraceMatrix.js} +0 -0
- package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- package/dist/{cjs/index.js → index.js} +0 -0
- package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
- package/dist/{cjs/utils.js → utils.js} +0 -0
- package/package.json +5 -6
- package/dist/es2015/DCircle.js +0 -87
- package/dist/es2015/DLine.js +0 -257
- package/dist/es2015/DNumbers.js +0 -22
- package/dist/es2015/DPlane.js +0 -105
- package/dist/es2015/DPoint.js +0 -472
- package/dist/es2015/DPolygon.js +0 -1040
- package/dist/es2015/DPolygonLoop.js +0 -392
- package/dist/es2015/FastSearch.js +0 -25
- package/dist/es2015/TraceMatrix.js +0 -200
- package/dist/es2015/index.js +0 -10
- package/dist/es2015/utils.js +0 -162
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
var LoopFunctions;
|
|
2
|
-
(function (LoopFunctions) {
|
|
3
|
-
LoopFunctions[LoopFunctions["getTileFromCoords"] = 0] = "getTileFromCoords";
|
|
4
|
-
LoopFunctions[LoopFunctions["getCoordsFromTile"] = 1] = "getCoordsFromTile";
|
|
5
|
-
LoopFunctions[LoopFunctions["height"] = 2] = "height";
|
|
6
|
-
LoopFunctions[LoopFunctions["setX"] = 3] = "setX";
|
|
7
|
-
LoopFunctions[LoopFunctions["setY"] = 4] = "setY";
|
|
8
|
-
LoopFunctions[LoopFunctions["setZ"] = 5] = "setZ";
|
|
9
|
-
LoopFunctions[LoopFunctions["rotate"] = 6] = "rotate";
|
|
10
|
-
LoopFunctions[LoopFunctions["rotate3dX"] = 7] = "rotate3dX";
|
|
11
|
-
LoopFunctions[LoopFunctions["rotate3dY"] = 8] = "rotate3dY";
|
|
12
|
-
LoopFunctions[LoopFunctions["rotate3dZ"] = 9] = "rotate3dZ";
|
|
13
|
-
LoopFunctions[LoopFunctions["move"] = 10] = "move";
|
|
14
|
-
LoopFunctions[LoopFunctions["round"] = 11] = "round";
|
|
15
|
-
LoopFunctions[LoopFunctions["ceil"] = 12] = "ceil";
|
|
16
|
-
LoopFunctions[LoopFunctions["floor"] = 13] = "floor";
|
|
17
|
-
LoopFunctions[LoopFunctions["toFixed"] = 14] = "toFixed";
|
|
18
|
-
LoopFunctions[LoopFunctions["abs"] = 15] = "abs";
|
|
19
|
-
LoopFunctions[LoopFunctions["scale"] = 16] = "scale";
|
|
20
|
-
LoopFunctions[LoopFunctions["divide"] = 17] = "divide";
|
|
21
|
-
LoopFunctions[LoopFunctions["degreeToRadians"] = 18] = "degreeToRadians";
|
|
22
|
-
LoopFunctions[LoopFunctions["radiansToDegrees"] = 19] = "radiansToDegrees";
|
|
23
|
-
LoopFunctions[LoopFunctions["radiansToMeters"] = 20] = "radiansToMeters";
|
|
24
|
-
LoopFunctions[LoopFunctions["metersToRadians"] = 21] = "metersToRadians";
|
|
25
|
-
LoopFunctions[LoopFunctions["hipPoint"] = 22] = "hipPoint";
|
|
26
|
-
LoopFunctions[LoopFunctions["xPoint"] = 23] = "xPoint";
|
|
27
|
-
LoopFunctions[LoopFunctions["yPoint"] = 24] = "yPoint";
|
|
28
|
-
LoopFunctions[LoopFunctions["wPoint"] = 25] = "wPoint";
|
|
29
|
-
LoopFunctions[LoopFunctions["hPoint"] = 26] = "hPoint";
|
|
30
|
-
LoopFunctions[LoopFunctions["setIfLessThan"] = 27] = "setIfLessThan";
|
|
31
|
-
LoopFunctions[LoopFunctions["minus"] = 28] = "minus";
|
|
32
|
-
LoopFunctions[LoopFunctions["degreeToMeters"] = 29] = "degreeToMeters";
|
|
33
|
-
LoopFunctions[LoopFunctions["metersToDegree"] = 30] = "metersToDegree";
|
|
34
|
-
LoopFunctions[LoopFunctions["flipVertically"] = 31] = "flipVertically";
|
|
35
|
-
})(LoopFunctions || (LoopFunctions = {}));
|
|
36
|
-
const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg, setterArg }) => {
|
|
37
|
-
let res = a;
|
|
38
|
-
switch (functionName) {
|
|
39
|
-
case LoopFunctions.getTileFromCoords:
|
|
40
|
-
res = (k) => a(k)
|
|
41
|
-
.getTileFromCoords(numberArg);
|
|
42
|
-
break;
|
|
43
|
-
case LoopFunctions.getCoordsFromTile:
|
|
44
|
-
res = (k) => a(k)
|
|
45
|
-
.getCoordsFromTile(numberArg);
|
|
46
|
-
break;
|
|
47
|
-
case LoopFunctions.height:
|
|
48
|
-
res = (k) => a(k)
|
|
49
|
-
.height(numberArg);
|
|
50
|
-
break;
|
|
51
|
-
case LoopFunctions.setX:
|
|
52
|
-
res = (k) => a(k)
|
|
53
|
-
.setX(setterArg);
|
|
54
|
-
break;
|
|
55
|
-
case LoopFunctions.setY:
|
|
56
|
-
res = (k) => a(k)
|
|
57
|
-
.setY(setterArg);
|
|
58
|
-
break;
|
|
59
|
-
case LoopFunctions.setZ:
|
|
60
|
-
res = (k) => a(k)
|
|
61
|
-
.setZ(setterArg);
|
|
62
|
-
break;
|
|
63
|
-
case LoopFunctions.rotate:
|
|
64
|
-
res = (k) => a(k)
|
|
65
|
-
.rotate(numberArg);
|
|
66
|
-
break;
|
|
67
|
-
case LoopFunctions.rotate3dX:
|
|
68
|
-
res = (k) => a(k)
|
|
69
|
-
.rotate3dX(numberArg);
|
|
70
|
-
break;
|
|
71
|
-
case LoopFunctions.rotate3dY:
|
|
72
|
-
res = (k) => a(k)
|
|
73
|
-
.rotate3dY(numberArg);
|
|
74
|
-
break;
|
|
75
|
-
case LoopFunctions.rotate3dZ:
|
|
76
|
-
res = (k) => a(k)
|
|
77
|
-
.rotate3dZ(numberArg);
|
|
78
|
-
break;
|
|
79
|
-
case LoopFunctions.move:
|
|
80
|
-
res = (k) => a(k)
|
|
81
|
-
.move(numberPointArg, numberArg);
|
|
82
|
-
break;
|
|
83
|
-
case LoopFunctions.round:
|
|
84
|
-
res = (k) => a(k)
|
|
85
|
-
.round();
|
|
86
|
-
break;
|
|
87
|
-
case LoopFunctions.ceil:
|
|
88
|
-
res = (k) => a(k)
|
|
89
|
-
.ceil();
|
|
90
|
-
break;
|
|
91
|
-
case LoopFunctions.floor:
|
|
92
|
-
res = (k) => a(k)
|
|
93
|
-
.floor();
|
|
94
|
-
break;
|
|
95
|
-
case LoopFunctions.toFixed:
|
|
96
|
-
res = (k) => a(k)
|
|
97
|
-
.toFixed(numberArg);
|
|
98
|
-
break;
|
|
99
|
-
case LoopFunctions.abs:
|
|
100
|
-
res = (k) => a(k)
|
|
101
|
-
.abs();
|
|
102
|
-
break;
|
|
103
|
-
case LoopFunctions.scale:
|
|
104
|
-
res = (k) => a(k)
|
|
105
|
-
.scale(numberPointArg, numberArg);
|
|
106
|
-
break;
|
|
107
|
-
case LoopFunctions.divide:
|
|
108
|
-
res = (k) => a(k)
|
|
109
|
-
.divide(numberPointArg, numberArg);
|
|
110
|
-
break;
|
|
111
|
-
case LoopFunctions.degreeToRadians:
|
|
112
|
-
res = (k) => a(k)
|
|
113
|
-
.degreeToRadians();
|
|
114
|
-
break;
|
|
115
|
-
case LoopFunctions.radiansToDegrees:
|
|
116
|
-
res = (k) => a(k)
|
|
117
|
-
.radiansToDegrees();
|
|
118
|
-
break;
|
|
119
|
-
case LoopFunctions.radiansToMeters:
|
|
120
|
-
res = (k) => a(k)
|
|
121
|
-
.radiansToMeters();
|
|
122
|
-
break;
|
|
123
|
-
case LoopFunctions.metersToRadians:
|
|
124
|
-
res = (k) => a(k)
|
|
125
|
-
.metersToRadians();
|
|
126
|
-
break;
|
|
127
|
-
case LoopFunctions.hipPoint:
|
|
128
|
-
res = (k) => a(k)
|
|
129
|
-
.hipPoint;
|
|
130
|
-
break;
|
|
131
|
-
case LoopFunctions.xPoint:
|
|
132
|
-
res = (k) => a(k)
|
|
133
|
-
.xPoint;
|
|
134
|
-
break;
|
|
135
|
-
case LoopFunctions.yPoint:
|
|
136
|
-
res = (k) => a(k)
|
|
137
|
-
.yPoint;
|
|
138
|
-
break;
|
|
139
|
-
case LoopFunctions.wPoint:
|
|
140
|
-
res = (k) => a(k)
|
|
141
|
-
.wPoint;
|
|
142
|
-
break;
|
|
143
|
-
case LoopFunctions.hPoint:
|
|
144
|
-
res = (k) => a(k)
|
|
145
|
-
.hPoint;
|
|
146
|
-
break;
|
|
147
|
-
case LoopFunctions.setIfLessThan:
|
|
148
|
-
res = (k) => a(k)
|
|
149
|
-
.setIfLessThan(pointArg);
|
|
150
|
-
break;
|
|
151
|
-
case LoopFunctions.minus:
|
|
152
|
-
res = (k) => a(k)
|
|
153
|
-
.minus();
|
|
154
|
-
break;
|
|
155
|
-
case LoopFunctions.degreeToMeters:
|
|
156
|
-
res = (k) => a(k)
|
|
157
|
-
.degreeToMeters();
|
|
158
|
-
break;
|
|
159
|
-
case LoopFunctions.metersToDegree:
|
|
160
|
-
res = (k) => a(k)
|
|
161
|
-
.metersToDegree();
|
|
162
|
-
break;
|
|
163
|
-
case LoopFunctions.flipVertically:
|
|
164
|
-
res = (k) => a(k)
|
|
165
|
-
.flipVertically(numberPointArg);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
return res;
|
|
169
|
-
};
|
|
170
|
-
export class DPolygonLoop {
|
|
171
|
-
constructor(parent) {
|
|
172
|
-
this.parent = parent;
|
|
173
|
-
this.pool = [];
|
|
174
|
-
}
|
|
175
|
-
getLoopFunction() {
|
|
176
|
-
return this.pool.reduce(decodePoolRecord, (k) => k);
|
|
177
|
-
}
|
|
178
|
-
run() {
|
|
179
|
-
return this.parent.map(this.getLoopFunction());
|
|
180
|
-
}
|
|
181
|
-
getTileFromCoords(zoom) {
|
|
182
|
-
this.pool.push({
|
|
183
|
-
functionName: LoopFunctions.getTileFromCoords,
|
|
184
|
-
numberArg: zoom
|
|
185
|
-
});
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
getCoordsFromTile(zoom) {
|
|
189
|
-
this.pool.push({
|
|
190
|
-
functionName: LoopFunctions.getCoordsFromTile,
|
|
191
|
-
numberArg: zoom
|
|
192
|
-
});
|
|
193
|
-
return this;
|
|
194
|
-
}
|
|
195
|
-
height(z) {
|
|
196
|
-
this.pool.push({
|
|
197
|
-
functionName: LoopFunctions.height,
|
|
198
|
-
numberArg: z
|
|
199
|
-
});
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
setX(x) {
|
|
203
|
-
this.pool.push({
|
|
204
|
-
functionName: LoopFunctions.setX,
|
|
205
|
-
setterArg: x
|
|
206
|
-
});
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
setY(y) {
|
|
210
|
-
this.pool.push({
|
|
211
|
-
functionName: LoopFunctions.setY,
|
|
212
|
-
setterArg: y
|
|
213
|
-
});
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
setZ(z) {
|
|
217
|
-
this.pool.push({
|
|
218
|
-
functionName: LoopFunctions.setZ,
|
|
219
|
-
setterArg: z
|
|
220
|
-
});
|
|
221
|
-
return this;
|
|
222
|
-
}
|
|
223
|
-
rotate(a) {
|
|
224
|
-
this.pool.push({
|
|
225
|
-
functionName: LoopFunctions.rotate,
|
|
226
|
-
numberArg: a
|
|
227
|
-
});
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
rotate3dX(a) {
|
|
231
|
-
this.pool.push({
|
|
232
|
-
functionName: LoopFunctions.rotate3dX,
|
|
233
|
-
numberArg: a
|
|
234
|
-
});
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
rotate3dY(a) {
|
|
238
|
-
this.pool.push({
|
|
239
|
-
functionName: LoopFunctions.rotate3dY,
|
|
240
|
-
numberArg: a
|
|
241
|
-
});
|
|
242
|
-
return this;
|
|
243
|
-
}
|
|
244
|
-
rotate3dZ(a) {
|
|
245
|
-
this.pool.push({
|
|
246
|
-
functionName: LoopFunctions.rotate3dZ,
|
|
247
|
-
numberArg: a
|
|
248
|
-
});
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
move(x, y = x) {
|
|
252
|
-
this.pool.push({
|
|
253
|
-
functionName: LoopFunctions.move,
|
|
254
|
-
numberPointArg: x,
|
|
255
|
-
numberArg: y
|
|
256
|
-
});
|
|
257
|
-
return this;
|
|
258
|
-
}
|
|
259
|
-
round() {
|
|
260
|
-
this.pool.push({
|
|
261
|
-
functionName: LoopFunctions.round
|
|
262
|
-
});
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
ceil() {
|
|
266
|
-
this.pool.push({
|
|
267
|
-
functionName: LoopFunctions.ceil
|
|
268
|
-
});
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
floor() {
|
|
272
|
-
this.pool.push({
|
|
273
|
-
functionName: LoopFunctions.floor
|
|
274
|
-
});
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
toFixed(n = 2) {
|
|
278
|
-
this.pool.push({
|
|
279
|
-
functionName: LoopFunctions.toFixed,
|
|
280
|
-
numberArg: n
|
|
281
|
-
});
|
|
282
|
-
return this;
|
|
283
|
-
}
|
|
284
|
-
abs() {
|
|
285
|
-
this.pool.push({
|
|
286
|
-
functionName: LoopFunctions.abs
|
|
287
|
-
});
|
|
288
|
-
return this;
|
|
289
|
-
}
|
|
290
|
-
scale(x, y = x) {
|
|
291
|
-
this.pool.push({
|
|
292
|
-
functionName: LoopFunctions.scale,
|
|
293
|
-
numberPointArg: x,
|
|
294
|
-
numberArg: y
|
|
295
|
-
});
|
|
296
|
-
return this;
|
|
297
|
-
}
|
|
298
|
-
divide(x, y) {
|
|
299
|
-
this.pool.push({
|
|
300
|
-
functionName: LoopFunctions.divide,
|
|
301
|
-
numberPointArg: x,
|
|
302
|
-
numberArg: y
|
|
303
|
-
});
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
degreeToRadians() {
|
|
307
|
-
this.pool.push({
|
|
308
|
-
functionName: LoopFunctions.degreeToRadians
|
|
309
|
-
});
|
|
310
|
-
return this;
|
|
311
|
-
}
|
|
312
|
-
radiansToDegrees() {
|
|
313
|
-
this.pool.push({
|
|
314
|
-
functionName: LoopFunctions.radiansToDegrees
|
|
315
|
-
});
|
|
316
|
-
return this;
|
|
317
|
-
}
|
|
318
|
-
radiansToMeters() {
|
|
319
|
-
this.pool.push({
|
|
320
|
-
functionName: LoopFunctions.radiansToMeters
|
|
321
|
-
});
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
metersToRadians() {
|
|
325
|
-
this.pool.push({
|
|
326
|
-
functionName: LoopFunctions.metersToRadians
|
|
327
|
-
});
|
|
328
|
-
return this;
|
|
329
|
-
}
|
|
330
|
-
getHipPoint() {
|
|
331
|
-
this.pool.push({
|
|
332
|
-
functionName: LoopFunctions.hipPoint
|
|
333
|
-
});
|
|
334
|
-
return this;
|
|
335
|
-
}
|
|
336
|
-
getXPoint() {
|
|
337
|
-
this.pool.push({
|
|
338
|
-
functionName: LoopFunctions.xPoint
|
|
339
|
-
});
|
|
340
|
-
return this;
|
|
341
|
-
}
|
|
342
|
-
getYPoint() {
|
|
343
|
-
this.pool.push({
|
|
344
|
-
functionName: LoopFunctions.yPoint
|
|
345
|
-
});
|
|
346
|
-
return this;
|
|
347
|
-
}
|
|
348
|
-
getWPoint() {
|
|
349
|
-
this.pool.push({
|
|
350
|
-
functionName: LoopFunctions.wPoint
|
|
351
|
-
});
|
|
352
|
-
return this;
|
|
353
|
-
}
|
|
354
|
-
getHPoint() {
|
|
355
|
-
this.pool.push({
|
|
356
|
-
functionName: LoopFunctions.hPoint
|
|
357
|
-
});
|
|
358
|
-
return this;
|
|
359
|
-
}
|
|
360
|
-
setIfLessThan(p) {
|
|
361
|
-
this.pool.push({
|
|
362
|
-
functionName: LoopFunctions.setIfLessThan,
|
|
363
|
-
pointArg: p
|
|
364
|
-
});
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
minus() {
|
|
368
|
-
this.pool.push({
|
|
369
|
-
functionName: LoopFunctions.minus
|
|
370
|
-
});
|
|
371
|
-
return this;
|
|
372
|
-
}
|
|
373
|
-
degreeToMeters() {
|
|
374
|
-
this.pool.push({
|
|
375
|
-
functionName: LoopFunctions.degreeToMeters
|
|
376
|
-
});
|
|
377
|
-
return this;
|
|
378
|
-
}
|
|
379
|
-
metersToDegree() {
|
|
380
|
-
this.pool.push({
|
|
381
|
-
functionName: LoopFunctions.metersToDegree
|
|
382
|
-
});
|
|
383
|
-
return this;
|
|
384
|
-
}
|
|
385
|
-
flipVertically(size) {
|
|
386
|
-
this.pool.push({
|
|
387
|
-
functionName: LoopFunctions.flipVertically,
|
|
388
|
-
numberPointArg: size
|
|
389
|
-
});
|
|
390
|
-
return this;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export class FastSearch {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.searchStore = {};
|
|
4
|
-
}
|
|
5
|
-
add(points) {
|
|
6
|
-
for (const { x, y, z } of points) {
|
|
7
|
-
if (!this.searchStore[x]) {
|
|
8
|
-
this.searchStore[x] = {};
|
|
9
|
-
}
|
|
10
|
-
if (!this.searchStore[x][y]) {
|
|
11
|
-
this.searchStore[x][y] = {};
|
|
12
|
-
}
|
|
13
|
-
this.searchStore[x][y][z || 'undefined'] = true;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
find({ x, y, z }) {
|
|
17
|
-
if (!this.searchStore[x]) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
if (!this.searchStore[x][y]) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return this.searchStore[x][y][z || 'undefined'];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
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;
|
|
6
|
-
(function (TraceMatrixValues) {
|
|
7
|
-
TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
|
|
8
|
-
TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
|
|
9
|
-
})(TraceMatrixValues || (TraceMatrixValues = {}));
|
|
10
|
-
const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
|
|
11
|
-
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
return m[p.y][p.x];
|
|
15
|
-
};
|
|
16
|
-
const setByPosition = (m, p, value) => {
|
|
17
|
-
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
m[p.y][p.x] = value;
|
|
21
|
-
return m[p.y][p.x];
|
|
22
|
-
};
|
|
23
|
-
export class TraceMatrix {
|
|
24
|
-
constructor(size, f) {
|
|
25
|
-
this.size = size;
|
|
26
|
-
this.findGroupByIndex = (m, s) => {
|
|
27
|
-
const res = new DPolygon();
|
|
28
|
-
if (s && getByPosition(m, s) === TraceMatrixValues.t) {
|
|
29
|
-
res.push(s);
|
|
30
|
-
let startIndex = 0;
|
|
31
|
-
const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
|
|
32
|
-
setByPosition(marked, s, TraceMatrixValues.t);
|
|
33
|
-
while (startIndex < res.length) {
|
|
34
|
-
const r = res.at(startIndex);
|
|
35
|
-
for (let i = -1; i < 2; i++) {
|
|
36
|
-
for (let j = -1; j < 2; j++) {
|
|
37
|
-
const t = new DPoint(r.x + i, r.y + j);
|
|
38
|
-
if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
|
|
39
|
-
getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
|
|
40
|
-
res.push(t);
|
|
41
|
-
setByPosition(marked, t, TraceMatrixValues.t);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
startIndex++;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return res;
|
|
49
|
-
};
|
|
50
|
-
this.findAllGroupsInMatrix = (m) => {
|
|
51
|
-
const firstMark = this.findMarked(m);
|
|
52
|
-
if (!firstMark) {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
const group = this.findGroupByIndex(m, firstMark);
|
|
56
|
-
const groups = [group];
|
|
57
|
-
let groupSum = group.length;
|
|
58
|
-
let allGroups = [...group.points];
|
|
59
|
-
const fs = new FastSearch();
|
|
60
|
-
fs.add(allGroups);
|
|
61
|
-
while (groupSum < this.totalCountInMatrix(m)) {
|
|
62
|
-
let mark = this.findMarked(m);
|
|
63
|
-
while (mark && fs.find(mark)) {
|
|
64
|
-
mark = this.findMarked(m, mark);
|
|
65
|
-
}
|
|
66
|
-
const nextGroup = this.findGroupByIndex(m, mark);
|
|
67
|
-
groupSum += nextGroup.length;
|
|
68
|
-
allGroups = [...allGroups, ...nextGroup.points];
|
|
69
|
-
fs.add(nextGroup.points);
|
|
70
|
-
groups.push(nextGroup);
|
|
71
|
-
}
|
|
72
|
-
return groups.filter((g) => g.length > 2);
|
|
73
|
-
};
|
|
74
|
-
this.traceGroup = (m, group) => {
|
|
75
|
-
const traceDirections = [
|
|
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)
|
|
84
|
-
];
|
|
85
|
-
const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
|
|
86
|
-
const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
|
|
87
|
-
if (group.length < 2) {
|
|
88
|
-
const t = group.at(0).clone();
|
|
89
|
-
return new DPolygon([t, t, t]);
|
|
90
|
-
}
|
|
91
|
-
const points = new DPolygon();
|
|
92
|
-
let direction = 0;
|
|
93
|
-
let prevDirection = Infinity;
|
|
94
|
-
let p = group.at(0);
|
|
95
|
-
while (!p.equal(group.at(0)) || points.length < 2) {
|
|
96
|
-
while (true) {
|
|
97
|
-
const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
|
|
98
|
-
const nextNeighbourValue = getByPosition(m, p.clone().move(traceDirections[left(direction)]));
|
|
99
|
-
if (nextValue === TraceMatrixValues.t && nextNeighbourValue === TraceMatrixValues.f) {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
direction = right(direction);
|
|
103
|
-
}
|
|
104
|
-
if (prevDirection !== direction) {
|
|
105
|
-
points.push(p);
|
|
106
|
-
prevDirection = direction;
|
|
107
|
-
}
|
|
108
|
-
p = p.clone().move(traceDirections[direction]);
|
|
109
|
-
direction = left(left(direction));
|
|
110
|
-
}
|
|
111
|
-
return points.approximation().close();
|
|
112
|
-
};
|
|
113
|
-
this.createHoleMatrix = (group) => {
|
|
114
|
-
const fullTraceDirections = [
|
|
115
|
-
new DPoint(-1, 0),
|
|
116
|
-
new DPoint(0, 1),
|
|
117
|
-
new DPoint(1, 0),
|
|
118
|
-
new DPoint(0, -1)
|
|
119
|
-
];
|
|
120
|
-
group.prepareToFastSearch();
|
|
121
|
-
const tmpMatrix = TraceMatrix
|
|
122
|
-
.createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
123
|
-
const startCoords = new DPolygon();
|
|
124
|
-
for (let i = 0; i < this.size.w; i++) {
|
|
125
|
-
startCoords.push(new DPoint(i, -1));
|
|
126
|
-
startCoords.push(new DPoint(i, this.size.h));
|
|
127
|
-
}
|
|
128
|
-
for (let i = 0; i < this.size.h; i++) {
|
|
129
|
-
startCoords.push(new DPoint(-1, i));
|
|
130
|
-
startCoords.push(new DPoint(this.size.w, i));
|
|
131
|
-
}
|
|
132
|
-
while (startCoords.length) {
|
|
133
|
-
const point = startCoords.pop();
|
|
134
|
-
for (const direction of fullTraceDirections) {
|
|
135
|
-
const tmpPoint = point.clone().move(direction);
|
|
136
|
-
const value = getByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
137
|
-
if (value === TraceMatrixValues.f) {
|
|
138
|
-
setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
139
|
-
startCoords.push(tmpPoint);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const t = this.reverseMatrix(tmpMatrix);
|
|
144
|
-
return this.totalCountInMatrix(t) ? t : null;
|
|
145
|
-
};
|
|
146
|
-
this.m = TraceMatrix.createMatrix(this.size, f);
|
|
147
|
-
}
|
|
148
|
-
fullMatrixTrace() {
|
|
149
|
-
const groups = this.findAllGroupsInMatrix(this.m);
|
|
150
|
-
const paths = groups.map((g) => this.traceGroup(this.m, g));
|
|
151
|
-
const holeMatrixs = groups.map(this.createHoleMatrix);
|
|
152
|
-
const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
|
|
153
|
-
const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
|
|
154
|
-
.traceGroup(holeMatrixs[index], g)).filter((r) => r.length > MIN_POINTS_IN_VALID_POLYGON));
|
|
155
|
-
return groups.map((g, index) => {
|
|
156
|
-
const res = paths[index];
|
|
157
|
-
if (holesGroups[index] && holesGroups[index].length) {
|
|
158
|
-
res.holes = holesPaths[index];
|
|
159
|
-
}
|
|
160
|
-
return res;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
reverseMatrix(m) {
|
|
164
|
-
return TraceMatrix.createMatrix(this.size, (p) => getByPosition(m, p) === TraceMatrixValues.f ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
165
|
-
}
|
|
166
|
-
findMarked(m, init) {
|
|
167
|
-
const s = this.size;
|
|
168
|
-
let ini = false;
|
|
169
|
-
for (let i = 0; i < s.w; i++) {
|
|
170
|
-
for (let j = 0; j < s.h; j++) {
|
|
171
|
-
if (!ini && init) {
|
|
172
|
-
i = init.x;
|
|
173
|
-
j = init.y;
|
|
174
|
-
ini = true;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (getByPosition(m, new DPoint(i, j)) === TraceMatrixValues.t) {
|
|
178
|
-
return new DPoint(i, j);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
totalCountInMatrix(m) {
|
|
185
|
-
let res = 0;
|
|
186
|
-
const s = this.size;
|
|
187
|
-
for (let i = 0; i < s.w; i++) {
|
|
188
|
-
for (let j = 0; j < s.h; j++) {
|
|
189
|
-
if (getByPosition(m, new DPoint(i, j))) {
|
|
190
|
-
res++;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return res;
|
|
195
|
-
}
|
|
196
|
-
static createMatrix(size, f = () => TraceMatrixValues.f) {
|
|
197
|
-
return createArray(size.h)
|
|
198
|
-
.map((v, i) => createArray(size.w).map((v2, j) => f(new DPoint(j, i))));
|
|
199
|
-
}
|
|
200
|
-
}
|
package/dist/es2015/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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';
|