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