dgeoutils 2.1.0 → 2.2.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.
@@ -1,155 +1,358 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DPolygonLoop = void 0;
4
+ var LoopFunctions;
5
+ (function (LoopFunctions) {
6
+ LoopFunctions[LoopFunctions["getTileFromCoords"] = 0] = "getTileFromCoords";
7
+ LoopFunctions[LoopFunctions["getCoordsFromTile"] = 1] = "getCoordsFromTile";
8
+ LoopFunctions[LoopFunctions["height"] = 2] = "height";
9
+ LoopFunctions[LoopFunctions["setX"] = 3] = "setX";
10
+ LoopFunctions[LoopFunctions["setY"] = 4] = "setY";
11
+ LoopFunctions[LoopFunctions["rotate"] = 5] = "rotate";
12
+ LoopFunctions[LoopFunctions["move"] = 6] = "move";
13
+ LoopFunctions[LoopFunctions["round"] = 7] = "round";
14
+ LoopFunctions[LoopFunctions["ceil"] = 8] = "ceil";
15
+ LoopFunctions[LoopFunctions["floor"] = 9] = "floor";
16
+ LoopFunctions[LoopFunctions["toFixed"] = 10] = "toFixed";
17
+ LoopFunctions[LoopFunctions["abs"] = 11] = "abs";
18
+ LoopFunctions[LoopFunctions["scale"] = 12] = "scale";
19
+ LoopFunctions[LoopFunctions["divide"] = 13] = "divide";
20
+ LoopFunctions[LoopFunctions["degreeToRadians"] = 14] = "degreeToRadians";
21
+ LoopFunctions[LoopFunctions["radiansToDegrees"] = 15] = "radiansToDegrees";
22
+ LoopFunctions[LoopFunctions["radiansToMeters"] = 16] = "radiansToMeters";
23
+ LoopFunctions[LoopFunctions["metersToRadians"] = 17] = "metersToRadians";
24
+ LoopFunctions[LoopFunctions["hipPoint"] = 18] = "hipPoint";
25
+ LoopFunctions[LoopFunctions["xPoint"] = 19] = "xPoint";
26
+ LoopFunctions[LoopFunctions["yPoint"] = 20] = "yPoint";
27
+ LoopFunctions[LoopFunctions["wPoint"] = 21] = "wPoint";
28
+ LoopFunctions[LoopFunctions["hPoint"] = 22] = "hPoint";
29
+ LoopFunctions[LoopFunctions["setIfLessThan"] = 23] = "setIfLessThan";
30
+ LoopFunctions[LoopFunctions["minus"] = 24] = "minus";
31
+ LoopFunctions[LoopFunctions["degreeToMeters"] = 25] = "degreeToMeters";
32
+ LoopFunctions[LoopFunctions["metersToDegree"] = 26] = "metersToDegree";
33
+ LoopFunctions[LoopFunctions["flipVertically"] = 27] = "flipVertically";
34
+ })(LoopFunctions || (LoopFunctions = {}));
35
+ // eslint-disable-next-line complexity
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.rotate:
60
+ res = (k) => a(k)
61
+ .rotate(numberArg);
62
+ break;
63
+ case LoopFunctions.move:
64
+ res = (k) => a(k)
65
+ .move(numberPointArg, numberArg);
66
+ break;
67
+ case LoopFunctions.round:
68
+ res = (k) => a(k)
69
+ .round();
70
+ break;
71
+ case LoopFunctions.ceil:
72
+ res = (k) => a(k)
73
+ .ceil();
74
+ break;
75
+ case LoopFunctions.floor:
76
+ res = (k) => a(k)
77
+ .floor();
78
+ break;
79
+ case LoopFunctions.toFixed:
80
+ res = (k) => a(k)
81
+ .toFixed(numberArg);
82
+ break;
83
+ case LoopFunctions.abs:
84
+ res = (k) => a(k)
85
+ .abs();
86
+ break;
87
+ case LoopFunctions.scale:
88
+ res = (k) => a(k)
89
+ .scale(numberPointArg, numberArg);
90
+ break;
91
+ case LoopFunctions.divide:
92
+ res = (k) => a(k)
93
+ .divide(numberPointArg, numberArg);
94
+ break;
95
+ case LoopFunctions.degreeToRadians:
96
+ res = (k) => a(k)
97
+ .degreeToRadians();
98
+ break;
99
+ case LoopFunctions.radiansToDegrees:
100
+ res = (k) => a(k)
101
+ .radiansToDegrees();
102
+ break;
103
+ case LoopFunctions.radiansToMeters:
104
+ res = (k) => a(k)
105
+ .radiansToMeters();
106
+ break;
107
+ case LoopFunctions.metersToRadians:
108
+ res = (k) => a(k)
109
+ .metersToRadians();
110
+ break;
111
+ case LoopFunctions.hipPoint:
112
+ res = (k) => a(k)
113
+ .hipPoint;
114
+ break;
115
+ case LoopFunctions.xPoint:
116
+ res = (k) => a(k)
117
+ .xPoint;
118
+ break;
119
+ case LoopFunctions.yPoint:
120
+ res = (k) => a(k)
121
+ .yPoint;
122
+ break;
123
+ case LoopFunctions.wPoint:
124
+ res = (k) => a(k)
125
+ .wPoint;
126
+ break;
127
+ case LoopFunctions.hPoint:
128
+ res = (k) => a(k)
129
+ .hPoint;
130
+ break;
131
+ case LoopFunctions.setIfLessThan:
132
+ res = (k) => a(k)
133
+ .setIfLessThan(pointArg);
134
+ break;
135
+ case LoopFunctions.minus:
136
+ res = (k) => a(k)
137
+ .minus();
138
+ break;
139
+ case LoopFunctions.degreeToMeters:
140
+ res = (k) => a(k)
141
+ .degreeToMeters();
142
+ break;
143
+ case LoopFunctions.metersToDegree:
144
+ res = (k) => a(k)
145
+ .metersToDegree();
146
+ break;
147
+ case LoopFunctions.flipVertically:
148
+ res = (k) => a(k)
149
+ .flipVertically(numberPointArg);
150
+ break;
151
+ default:
152
+ }
153
+ return res;
154
+ };
4
155
  class DPolygonLoop {
5
156
  constructor(parent) {
6
- this.f = (k) => k;
7
157
  this.parent = parent;
158
+ this.pool = [];
159
+ }
160
+ getLoopFunction() {
161
+ return this.pool.reduce(decodePoolRecord, (k) => k);
8
162
  }
9
163
  /**
10
164
  * Run loop
11
165
  */
12
- run(f = this.f) {
13
- return this.parent.map(f);
166
+ run() {
167
+ return this.parent.map(this.getLoopFunction());
14
168
  }
169
+ /**
170
+ * @param zoom default value would be `z` of point
171
+ */
15
172
  getTileFromCoords(zoom) {
16
- const t = this.f.bind(null);
17
- this.f = (k) => t(k).getTileFromCoords(zoom);
173
+ this.pool.push({
174
+ functionName: LoopFunctions.getTileFromCoords,
175
+ numberArg: zoom
176
+ });
18
177
  return this;
19
178
  }
179
+ /**
180
+ * @param zoom default value would be `z` of point
181
+ */
20
182
  getCoordsFromTile(zoom) {
21
- const t = this.f.bind(null);
22
- this.f = (k) => t(k).getCoordsFromTile(zoom);
183
+ this.pool.push({
184
+ functionName: LoopFunctions.getCoordsFromTile,
185
+ numberArg: zoom
186
+ });
23
187
  return this;
24
188
  }
25
189
  height(z) {
26
- const t = this.f.bind(null);
27
- this.f = (k) => t(k).height(z);
190
+ this.pool.push({
191
+ functionName: LoopFunctions.height,
192
+ numberArg: z
193
+ });
28
194
  return this;
29
195
  }
30
196
  setX(x) {
31
- const t = this.f.bind(null);
32
- this.f = (k) => t(k).setX(x);
197
+ this.pool.push({
198
+ functionName: LoopFunctions.setX,
199
+ setterArg: x
200
+ });
33
201
  return this;
34
202
  }
35
203
  setY(y) {
36
- const t = this.f.bind(null);
37
- this.f = (k) => t(k).setY(y);
204
+ this.pool.push({
205
+ functionName: LoopFunctions.setY,
206
+ setterArg: y
207
+ });
38
208
  return this;
39
209
  }
40
210
  rotate(a) {
41
- const t = this.f.bind(null);
42
- this.f = (k) => t(k).rotate(a);
211
+ this.pool.push({
212
+ functionName: LoopFunctions.rotate,
213
+ numberArg: a
214
+ });
43
215
  return this;
44
216
  }
45
- move(x = 0, y) {
46
- const t = this.f.bind(null);
47
- this.f = (k) => t(k).move(x, y);
217
+ move(x, y = x) {
218
+ this.pool.push({
219
+ functionName: LoopFunctions.move,
220
+ numberPointArg: x,
221
+ numberArg: y
222
+ });
48
223
  return this;
49
224
  }
50
225
  round() {
51
- const t = this.f.bind(null);
52
- this.f = (k) => t(k).round();
226
+ this.pool.push({
227
+ functionName: LoopFunctions.round
228
+ });
53
229
  return this;
54
230
  }
55
231
  ceil() {
56
- const t = this.f.bind(null);
57
- this.f = (k) => t(k).ceil();
232
+ this.pool.push({
233
+ functionName: LoopFunctions.ceil
234
+ });
58
235
  return this;
59
236
  }
60
237
  floor() {
61
- const t = this.f.bind(null);
62
- this.f = (k) => t(k).floor();
238
+ this.pool.push({
239
+ functionName: LoopFunctions.floor
240
+ });
63
241
  return this;
64
242
  }
65
243
  toFixed(n = 2) {
66
- const t = this.f.bind(null);
67
- this.f = (k) => t(k).toFixed(n);
244
+ this.pool.push({
245
+ functionName: LoopFunctions.toFixed,
246
+ numberArg: n
247
+ });
68
248
  return this;
69
249
  }
70
250
  abs() {
71
- const t = this.f.bind(null);
72
- this.f = (k) => t(k).abs();
251
+ this.pool.push({
252
+ functionName: LoopFunctions.abs
253
+ });
73
254
  return this;
74
255
  }
75
- scale(x = 0, y) {
76
- const t = this.f.bind(null);
77
- this.f = (k) => t(k).scale(x, y);
256
+ scale(x, y = x) {
257
+ this.pool.push({
258
+ functionName: LoopFunctions.scale,
259
+ numberPointArg: x,
260
+ numberArg: y
261
+ });
78
262
  return this;
79
263
  }
80
- divide(x = 0, y) {
81
- const t = this.f.bind(null);
82
- this.f = (k) => t(k).divide(x, y);
264
+ divide(x, y) {
265
+ this.pool.push({
266
+ functionName: LoopFunctions.divide,
267
+ numberPointArg: x,
268
+ numberArg: y
269
+ });
83
270
  return this;
84
271
  }
85
272
  degreeToRadians() {
86
- const t = this.f.bind(null);
87
- this.f = (k) => t(k).degreeToRadians();
273
+ this.pool.push({
274
+ functionName: LoopFunctions.degreeToRadians
275
+ });
88
276
  return this;
89
277
  }
90
278
  radiansToDegrees() {
91
- const t = this.f.bind(null);
92
- this.f = (k) => t(k).radiansToDegrees();
279
+ this.pool.push({
280
+ functionName: LoopFunctions.radiansToDegrees
281
+ });
93
282
  return this;
94
283
  }
95
284
  radiansToMeters() {
96
- const t = this.f.bind(null);
97
- this.f = (k) => t(k).radiansToMeters();
285
+ this.pool.push({
286
+ functionName: LoopFunctions.radiansToMeters
287
+ });
98
288
  return this;
99
289
  }
100
290
  metersToRadians() {
101
- const t = this.f.bind(null);
102
- this.f = (k) => t(k).metersToRadians();
291
+ this.pool.push({
292
+ functionName: LoopFunctions.metersToRadians
293
+ });
103
294
  return this;
104
295
  }
105
296
  getHipPoint() {
106
- const t = this.f.bind(null);
107
- this.f = (k) => t(k).hipPoint;
297
+ this.pool.push({
298
+ functionName: LoopFunctions.hipPoint
299
+ });
108
300
  return this;
109
301
  }
110
302
  getXPoint() {
111
- const t = this.f.bind(null);
112
- this.f = (k) => t(k).xPoint;
303
+ this.pool.push({
304
+ functionName: LoopFunctions.xPoint
305
+ });
113
306
  return this;
114
307
  }
115
308
  getYPoint() {
116
- const t = this.f.bind(null);
117
- this.f = (k) => t(k).yPoint;
309
+ this.pool.push({
310
+ functionName: LoopFunctions.yPoint
311
+ });
118
312
  return this;
119
313
  }
120
314
  getWPoint() {
121
- const t = this.f.bind(null);
122
- this.f = (k) => t(k).wPoint;
315
+ this.pool.push({
316
+ functionName: LoopFunctions.wPoint
317
+ });
123
318
  return this;
124
319
  }
125
320
  getHPoint() {
126
- const t = this.f.bind(null);
127
- this.f = (k) => t(k).hPoint;
321
+ this.pool.push({
322
+ functionName: LoopFunctions.hPoint
323
+ });
128
324
  return this;
129
325
  }
130
326
  setIfLessThan(p) {
131
- const t = this.f.bind(null);
132
- this.f = (k) => t(k).setIfLessThan(p);
327
+ this.pool.push({
328
+ functionName: LoopFunctions.setIfLessThan,
329
+ pointArg: p
330
+ });
133
331
  return this;
134
332
  }
135
333
  minus() {
136
- const t = this.f.bind(null);
137
- this.f = (k) => t(k).minus();
334
+ this.pool.push({
335
+ functionName: LoopFunctions.minus
336
+ });
138
337
  return this;
139
338
  }
140
339
  degreeToMeters() {
141
- const t = this.f.bind(null);
142
- this.f = (k) => t(k).degreeToMeters();
340
+ this.pool.push({
341
+ functionName: LoopFunctions.degreeToMeters
342
+ });
143
343
  return this;
144
344
  }
145
345
  metersToDegree() {
146
- const t = this.f.bind(null);
147
- this.f = (k) => t(k).metersToDegree();
346
+ this.pool.push({
347
+ functionName: LoopFunctions.metersToDegree
348
+ });
148
349
  return this;
149
350
  }
150
351
  flipVertically(size) {
151
- const t = this.f.bind(null);
152
- this.f = (k) => t(k).flipVertically(size);
352
+ this.pool.push({
353
+ functionName: LoopFunctions.flipVertically,
354
+ numberPointArg: size
355
+ });
153
356
  return this;
154
357
  }
155
358
  }
@@ -4,10 +4,7 @@ exports.TraceMatrix = exports.TraceMatrixValues = void 0;
4
4
  const DPoint_1 = require("./DPoint");
5
5
  const DPolygon_1 = require("./DPolygon");
6
6
  const FastSearch_1 = require("./FastSearch");
7
- const createArray = (v = 0) => new Array(v + 1)
8
- .join(' ')
9
- .split('')
10
- .map((r, i) => i);
7
+ const utils_1 = require("./utils");
11
8
  var TraceMatrixValues;
12
9
  (function (TraceMatrixValues) {
13
10
  TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
@@ -36,7 +33,7 @@ class TraceMatrix {
36
33
  const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
37
34
  setByPosition(marked, s, TraceMatrixValues.t);
38
35
  while (startIndex < res.length) {
39
- const r = res.p(startIndex);
36
+ const r = res.at(startIndex);
40
37
  for (let i = -1; i < 2; i++) {
41
38
  for (let j = -1; j < 2; j++) {
42
39
  const t = new DPoint_1.DPoint(r.x + i, r.y + j);
@@ -90,14 +87,14 @@ class TraceMatrix {
90
87
  const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
91
88
  const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
92
89
  if (group.length < 2) {
93
- const t = group.p(0).clone();
90
+ const t = group.at(0).clone();
94
91
  return new DPolygon_1.DPolygon([t, t, t]);
95
92
  }
96
93
  const points = new DPolygon_1.DPolygon();
97
94
  let direction = 0;
98
95
  let prevDirection = Infinity;
99
- let p = group.p(0);
100
- while (!p.equal(group.p(0)) || points.length < 2) {
96
+ let p = group.at(0);
97
+ while (!p.equal(group.at(0)) || points.length < 2) {
101
98
  // eslint-disable-next-line no-constant-condition
102
99
  while (true) {
103
100
  const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
@@ -201,7 +198,8 @@ class TraceMatrix {
201
198
  return res;
202
199
  }
203
200
  static createMatrix(size, f = () => TraceMatrixValues.f) {
204
- return createArray(size.h).map((i) => createArray(size.w).map((j) => f(new DPoint_1.DPoint(j, i))));
201
+ return (0, utils_1.createArray)(size.h)
202
+ .map((v, i) => (0, utils_1.createArray)(size.w).map((v2, j) => f(new DPoint_1.DPoint(j, i))));
205
203
  }
206
204
  }
207
205
  exports.TraceMatrix = TraceMatrix;
package/dist/utils.d.ts CHANGED
@@ -12,4 +12,5 @@ interface CheckFunction {
12
12
  checkArgument: (argName: string) => CheckArgument;
13
13
  }
14
14
  export declare const checkFunction: (funcName: string) => CheckFunction;
15
+ export declare const createArray: (v: number) => number[];
15
16
  export {};
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkFunction = exports.warn = void 0;
3
+ exports.createArray = exports.checkFunction = exports.warn = void 0;
4
4
  const index_1 = require("./index");
5
5
  const DPoint_1 = require("./DPoint");
6
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -21,7 +21,7 @@ const shouldBeInt = (scope, funcName, argName) => (p) => {
21
21
  };
22
22
  const shouldBeUInt = (scope, funcName, argName) => (p) => {
23
23
  if (!p.clone().round()
24
- .equal(p) || !p.gtOrEqual(DPoint_1.DPoint.Zero())) {
24
+ .equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
25
25
  (0, exports.warn)(`"${funcName}" -> "${argName}" should be UInt!`);
26
26
  }
27
27
  return scope;
@@ -66,3 +66,5 @@ const checkFunction = (funcName) => ({
66
66
  }
67
67
  });
68
68
  exports.checkFunction = checkFunction;
69
+ const createArray = (v) => new Array(v).fill(0);
70
+ exports.createArray = createArray;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgeoutils",
3
- "version": "2.1.0",
3
+ "version": "2.2.3",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "node_modules/.bin/tsc",