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