dgeoutils 2.2.1 → 2.2.5

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.
@@ -35,6 +35,7 @@ var LoopFunctions;
35
35
  // eslint-disable-next-line complexity
36
36
  const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg, setterArg }) => {
37
37
  let res = a;
38
+ // eslint-disable-next-line default-case
38
39
  switch (functionName) {
39
40
  case LoopFunctions.getTileFromCoords:
40
41
  res = (k) => a(k)
@@ -148,11 +149,11 @@ const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg
148
149
  res = (k) => a(k)
149
150
  .flipVertically(numberPointArg);
150
151
  break;
151
- default:
152
152
  }
153
153
  return res;
154
154
  };
155
155
  class DPolygonLoop {
156
+ // eslint-disable-next-line no-empty-function,no-useless-constructor
156
157
  constructor(parent) {
157
158
  this.parent = parent;
158
159
  this.pool = [];
@@ -166,6 +167,9 @@ class DPolygonLoop {
166
167
  run() {
167
168
  return this.parent.map(this.getLoopFunction());
168
169
  }
170
+ /**
171
+ * @param zoom default value would be `z` of point
172
+ */
169
173
  getTileFromCoords(zoom) {
170
174
  this.pool.push({
171
175
  functionName: LoopFunctions.getTileFromCoords,
@@ -173,6 +177,9 @@ class DPolygonLoop {
173
177
  });
174
178
  return this;
175
179
  }
180
+ /**
181
+ * @param zoom default value would be `z` of point
182
+ */
176
183
  getCoordsFromTile(zoom) {
177
184
  this.pool.push({
178
185
  functionName: LoopFunctions.getCoordsFromTile,
@@ -208,7 +215,7 @@ class DPolygonLoop {
208
215
  });
209
216
  return this;
210
217
  }
211
- move(x = 0, y = x) {
218
+ move(x, y = x) {
212
219
  this.pool.push({
213
220
  functionName: LoopFunctions.move,
214
221
  numberPointArg: x,
@@ -247,7 +254,7 @@ class DPolygonLoop {
247
254
  });
248
255
  return this;
249
256
  }
250
- scale(x = 0, y = x) {
257
+ scale(x, y = x) {
251
258
  this.pool.push({
252
259
  functionName: LoopFunctions.scale,
253
260
  numberPointArg: x,
@@ -255,7 +262,7 @@ class DPolygonLoop {
255
262
  });
256
263
  return this;
257
264
  }
258
- divide(x = 0, y) {
265
+ divide(x, y) {
259
266
  this.pool.push({
260
267
  functionName: LoopFunctions.divide,
261
268
  numberPointArg: x,
@@ -6,8 +6,8 @@ export declare enum TraceMatrixValues {
6
6
  }
7
7
  declare type SimpleMatrix = TraceMatrixValues[][];
8
8
  export declare class TraceMatrix {
9
- private readonly m;
10
9
  private readonly size;
10
+ private readonly m;
11
11
  constructor(size: DPoint, f: (p: DPoint) => TraceMatrixValues);
12
12
  fullMatrixTrace(): DPolygon[];
13
13
  private reverseMatrix;
@@ -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";
@@ -28,6 +25,7 @@ const setByPosition = (m, p, value) => {
28
25
  };
29
26
  class TraceMatrix {
30
27
  constructor(size, f) {
28
+ this.size = size;
31
29
  this.findGroupByIndex = (m, s) => {
32
30
  const res = new DPolygon_1.DPolygon();
33
31
  if (s && getByPosition(m, s) === TraceMatrixValues.t) {
@@ -36,7 +34,7 @@ class TraceMatrix {
36
34
  const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
37
35
  setByPosition(marked, s, TraceMatrixValues.t);
38
36
  while (startIndex < res.length) {
39
- const r = res.p(startIndex);
37
+ const r = res.at(startIndex);
40
38
  for (let i = -1; i < 2; i++) {
41
39
  for (let j = -1; j < 2; j++) {
42
40
  const t = new DPoint_1.DPoint(r.x + i, r.y + j);
@@ -90,14 +88,14 @@ class TraceMatrix {
90
88
  const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
91
89
  const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
92
90
  if (group.length < 2) {
93
- const t = group.p(0).clone();
91
+ const t = group.at(0).clone();
94
92
  return new DPolygon_1.DPolygon([t, t, t]);
95
93
  }
96
94
  const points = new DPolygon_1.DPolygon();
97
95
  let direction = 0;
98
96
  let prevDirection = Infinity;
99
- let p = group.p(0);
100
- while (!p.equal(group.p(0)) || points.length < 2) {
97
+ let p = group.at(0);
98
+ while (!p.equal(group.at(0)) || points.length < 2) {
101
99
  // eslint-disable-next-line no-constant-condition
102
100
  while (true) {
103
101
  const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
@@ -149,7 +147,6 @@ class TraceMatrix {
149
147
  const t = this.reverseMatrix(tmpMatrix);
150
148
  return this.totalCountInMatrix(t) ? t : null;
151
149
  };
152
- this.size = size;
153
150
  this.m = TraceMatrix.createMatrix(this.size, f);
154
151
  }
155
152
  fullMatrixTrace() {
@@ -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/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './DPoint';
5
5
  export * from './DPolygon';
6
6
  export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
+ export * from './DPolygonLoop';
8
9
  export declare const DGeo: {
9
10
  DEBUG: boolean;
10
11
  };
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ __exportStar(require("./DPoint"), exports);
18
18
  __exportStar(require("./DPolygon"), exports);
19
19
  __exportStar(require("./FastSearch"), exports);
20
20
  __exportStar(require("./TraceMatrix"), exports);
21
+ __exportStar(require("./DPolygonLoop"), exports);
21
22
  exports.DGeo = {
22
23
  DEBUG: false
23
24
  };
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.2.1",
3
+ "version": "2.2.5",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "node_modules/.bin/tsc",
@@ -56,4 +56,4 @@
56
56
  "type": "git",
57
57
  "url": "https://github.com/edejin/DGeoUtils"
58
58
  }
59
- }
59
+ }