dgeoutils 2.3.4 → 2.3.7

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/DLine.js CHANGED
@@ -263,8 +263,9 @@ var DLine = (function () {
263
263
  return "LINESTRING (" + x1 + " " + y1 + ", " + x2 + " " + y2 + ")";
264
264
  };
265
265
  DLine.prototype.movePoint = function (i, k) {
266
- var p = Array.isArray(i) ? i : [i];
267
- var d = Array.isArray(k) ? k : [k];
266
+ var isArray = Array.isArray(i);
267
+ var p = isArray ? i : [i];
268
+ var d = (isArray ? k : [k]);
268
269
  var fi = this.findFi(new DLine(1, 0, 0));
269
270
  var td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
270
271
  var sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
@@ -273,17 +274,18 @@ var DLine = (function () {
273
274
  var p2T = p[0].clone().move(dt);
274
275
  var res = [];
275
276
  if (DNumbers_1.DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers_1.DNumbers.like(this.y(p2T).y, p2T.y)) {
276
- res = p.map(function (t, index) { return t.clone().move(sinCos.scale(d[index])); });
277
+ res = p.map(function (t, index) { return t.clone()
278
+ .move(sinCos.clone().scale(d[index])); });
277
279
  }
278
280
  else {
279
281
  res = p.map(function (t, index) { return t.clone()
280
- .move(sinCos.scale(d[index])
282
+ .move(sinCos.clone().scale(d[index])
281
283
  .setX(function (_a) {
282
284
  var x = _a.x;
283
285
  return -x;
284
286
  })); });
285
287
  }
286
- return res.length === 1 ? res[0] : res;
288
+ return isArray ? res : res[0];
287
289
  };
288
290
  DLine.prototype.findFi = function (_a, delta) {
289
291
  var a = _a.a, b = _a.b;
@@ -7,4 +7,4 @@ export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
9
  export * from './DPlane';
10
- export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
package/dist/cjs/index.js CHANGED
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.DGeo = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
13
+ exports.DGeo = exports.getCombinations = exports.cartesianProduct = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
14
14
  __exportStar(require("./DCircle"), exports);
15
15
  __exportStar(require("./DLine"), exports);
16
16
  __exportStar(require("./DNumbers"), exports);
@@ -26,4 +26,6 @@ Object.defineProperty(exports, "createCanvas", { enumerable: true, get: function
26
26
  Object.defineProperty(exports, "createArray", { enumerable: true, get: function () { return utils_1.createArray; } });
27
27
  Object.defineProperty(exports, "createMatrix", { enumerable: true, get: function () { return utils_1.createMatrix; } });
28
28
  Object.defineProperty(exports, "isDefAndNotNull", { enumerable: true, get: function () { return utils_1.isDefAndNotNull; } });
29
+ Object.defineProperty(exports, "cartesianProduct", { enumerable: true, get: function () { return utils_1.cartesianProduct; } });
30
+ Object.defineProperty(exports, "getCombinations", { enumerable: true, get: function () { return utils_1.getCombinations; } });
29
31
  Object.defineProperty(exports, "DGeo", { enumerable: true, get: function () { return utils_1.DGeo; } });
@@ -35,4 +35,8 @@ export declare const createCanvas: {
35
35
  (size: DPoint, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
36
36
  document?: Document;
37
37
  };
38
+ export declare const cartesianProduct: {
39
+ <T>(a: T[], ...b: T[][]): T[][];
40
+ };
41
+ export declare const getCombinations: <T>(arr: T[][]) => T[][];
38
42
  export {};
package/dist/cjs/utils.js CHANGED
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
25
  return to.concat(ar || Array.prototype.slice.call(from));
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
28
+ exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
29
29
  var DPoint_1 = require("./DPoint");
30
30
  exports.DGeo = {
31
31
  DEBUG: false
@@ -191,3 +191,26 @@ var createCanvas = function (a, b, c) {
191
191
  return [canvas, canvas.getContext('2d')];
192
192
  };
193
193
  exports.createCanvas = createCanvas;
194
+ var f = function (a, b) { return [].concat.apply([], __spreadArray([], __read(a.map(function (c) { return b.map(function (d) { return [].concat(c, d); }); })), false)); };
195
+ var cartesianProduct = function (a, b) {
196
+ var c = [];
197
+ for (var _i = 2; _i < arguments.length; _i++) {
198
+ c[_i - 2] = arguments[_i];
199
+ }
200
+ return b ? exports.cartesianProduct.apply(void 0, __spreadArray([f(a, b)], __read(c), false)) : a;
201
+ };
202
+ exports.cartesianProduct = cartesianProduct;
203
+ var getCombinations = function (arr) {
204
+ if (arr.length === 1) {
205
+ return arr[0];
206
+ }
207
+ var ans = [];
208
+ var otherCases = (0, exports.getCombinations)(arr.slice(1));
209
+ for (var i = 0; i < otherCases.length; i++) {
210
+ for (var j = 0; j < arr[0].length; j++) {
211
+ ans.push(__spreadArray([arr[0][j]], __read(otherCases[i]), false));
212
+ }
213
+ }
214
+ return ans;
215
+ };
216
+ exports.getCombinations = getCombinations;
@@ -218,8 +218,9 @@ export class DLine {
218
218
  return `LINESTRING (${x1} ${y1}, ${x2} ${y2})`;
219
219
  }
220
220
  movePoint(i, k) {
221
- const p = Array.isArray(i) ? i : [i];
222
- const d = Array.isArray(k) ? k : [k];
221
+ const isArray = Array.isArray(i);
222
+ const p = isArray ? i : [i];
223
+ const d = (isArray ? k : [k]);
223
224
  const fi = this.findFi(new DLine(1, 0, 0));
224
225
  const td = this.x(new DPoint(1, 1)).distance(this.x(new DPoint(2, 2))) / 2;
225
226
  const sinCos = new DPoint(Math.sin(fi), Math.cos(fi));
@@ -228,14 +229,15 @@ export class DLine {
228
229
  const p2T = p[0].clone().move(dt);
229
230
  let res = [];
230
231
  if (DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers.like(this.y(p2T).y, p2T.y)) {
231
- res = p.map((t, index) => t.clone().move(sinCos.scale(d[index])));
232
+ res = p.map((t, index) => t.clone()
233
+ .move(sinCos.clone().scale(d[index])));
232
234
  }
233
235
  else {
234
236
  res = p.map((t, index) => t.clone()
235
- .move(sinCos.scale(d[index])
237
+ .move(sinCos.clone().scale(d[index])
236
238
  .setX(({ x }) => -x)));
237
239
  }
238
- return res.length === 1 ? res[0] : res;
240
+ return isArray ? res : res[0];
239
241
  }
240
242
  findFi({ a, b }, delta = 1.0001) {
241
243
  const { a: q, b: w } = this;
@@ -7,4 +7,4 @@ export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
9
  export * from './DPlane';
10
- export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
@@ -145,3 +145,18 @@ export const createCanvas = (a, b, c) => {
145
145
  }
146
146
  return [canvas, canvas.getContext('2d')];
147
147
  };
148
+ const f = (a, b) => [].concat(...a.map((c) => b.map((d) => [].concat(c, d))));
149
+ export const cartesianProduct = (a, b, ...c) => b ? cartesianProduct(f(a, b), ...c) : a;
150
+ export const getCombinations = (arr) => {
151
+ if (arr.length === 1) {
152
+ return arr[0];
153
+ }
154
+ const ans = [];
155
+ const otherCases = getCombinations(arr.slice(1));
156
+ for (let i = 0; i < otherCases.length; i++) {
157
+ for (let j = 0; j < arr[0].length; j++) {
158
+ ans.push([arr[0][j], ...otherCases[i]]);
159
+ }
160
+ }
161
+ return ans;
162
+ };
package/dist/esm/DLine.js CHANGED
@@ -260,8 +260,9 @@ var DLine = (function () {
260
260
  return "LINESTRING (" + x1 + " " + y1 + ", " + x2 + " " + y2 + ")";
261
261
  };
262
262
  DLine.prototype.movePoint = function (i, k) {
263
- var p = Array.isArray(i) ? i : [i];
264
- var d = Array.isArray(k) ? k : [k];
263
+ var isArray = Array.isArray(i);
264
+ var p = isArray ? i : [i];
265
+ var d = (isArray ? k : [k]);
265
266
  var fi = this.findFi(new DLine(1, 0, 0));
266
267
  var td = this.x(new DPoint(1, 1)).distance(this.x(new DPoint(2, 2))) / 2;
267
268
  var sinCos = new DPoint(Math.sin(fi), Math.cos(fi));
@@ -270,17 +271,18 @@ var DLine = (function () {
270
271
  var p2T = p[0].clone().move(dt);
271
272
  var res = [];
272
273
  if (DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers.like(this.y(p2T).y, p2T.y)) {
273
- res = p.map(function (t, index) { return t.clone().move(sinCos.scale(d[index])); });
274
+ res = p.map(function (t, index) { return t.clone()
275
+ .move(sinCos.clone().scale(d[index])); });
274
276
  }
275
277
  else {
276
278
  res = p.map(function (t, index) { return t.clone()
277
- .move(sinCos.scale(d[index])
279
+ .move(sinCos.clone().scale(d[index])
278
280
  .setX(function (_a) {
279
281
  var x = _a.x;
280
282
  return -x;
281
283
  })); });
282
284
  }
283
- return res.length === 1 ? res[0] : res;
285
+ return isArray ? res : res[0];
284
286
  };
285
287
  DLine.prototype.findFi = function (_a, delta) {
286
288
  var a = _a.a, b = _a.b;
package/dist/esm/index.js CHANGED
@@ -7,4 +7,4 @@ export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
9
  export * from './DPlane';
10
- export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
package/dist/esm/utils.js CHANGED
@@ -181,3 +181,24 @@ export var createCanvas = function (a, b, c) {
181
181
  }
182
182
  return [canvas, canvas.getContext('2d')];
183
183
  };
184
+ var f = function (a, b) { return [].concat.apply([], __spreadArray([], __read(a.map(function (c) { return b.map(function (d) { return [].concat(c, d); }); })), false)); };
185
+ export var cartesianProduct = function (a, b) {
186
+ var c = [];
187
+ for (var _i = 2; _i < arguments.length; _i++) {
188
+ c[_i - 2] = arguments[_i];
189
+ }
190
+ return b ? cartesianProduct.apply(void 0, __spreadArray([f(a, b)], __read(c), false)) : a;
191
+ };
192
+ export var getCombinations = function (arr) {
193
+ if (arr.length === 1) {
194
+ return arr[0];
195
+ }
196
+ var ans = [];
197
+ var otherCases = getCombinations(arr.slice(1));
198
+ for (var i = 0; i < otherCases.length; i++) {
199
+ for (var j = 0; j < arr[0].length; j++) {
200
+ ans.push(__spreadArray([arr[0][j]], __read(otherCases[i]), false));
201
+ }
202
+ }
203
+ return ans;
204
+ };