dgeoutils 2.3.5 → 2.4.0

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));
@@ -284,7 +285,7 @@ var DLine = (function () {
284
285
  return -x;
285
286
  })); });
286
287
  }
287
- return res.length === 1 ? res[0] : res;
288
+ return isArray ? res : res[0];
288
289
  };
289
290
  DLine.prototype.findFi = function (_a, delta) {
290
291
  var a = _a.a, b = _a.b;
@@ -97,7 +97,7 @@ export declare class DPolygon {
97
97
  static parse(a: number[][]): DPolygon;
98
98
  static parse(a: DCoord[]): DPolygon;
99
99
  toArrayOfCoords(): DCoord[];
100
- divideToPieces(piecesCount: number): DPolygon;
100
+ divideToPieces(piecesCount: number, withAltitude?: boolean): DPolygon;
101
101
  prepareToFastSearch(): void;
102
102
  fastHas({ x, y, z }: DPoint): boolean;
103
103
  get growingPiecesGenerator(): () => Generator<DPolygon, DPolygon>;
@@ -961,8 +961,9 @@ var DPolygon = (function () {
961
961
  DPolygon.prototype.toArrayOfCoords = function () {
962
962
  return this.mapArray(function (r) { return r.toCoords(); });
963
963
  };
964
- DPolygon.prototype.divideToPieces = function (piecesCount) {
964
+ DPolygon.prototype.divideToPieces = function (piecesCount, withAltitude) {
965
965
  var e_13, _a;
966
+ if (withAltitude === void 0) { withAltitude = false; }
966
967
  var fullLength = this.fullLength;
967
968
  var pieceLength = fullLength / piecesCount;
968
969
  var currentPieceLength = pieceLength;
@@ -979,6 +980,10 @@ var DPolygon = (function () {
979
980
  .filter(function (p) { return line_1.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE); })[0];
980
981
  intersectionPoint.properties.pieceBorder = true;
981
982
  this_1.insertAfter(i, intersectionPoint);
983
+ if (withAltitude) {
984
+ var p1z = p1.z;
985
+ intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
986
+ }
982
987
  currentPieceLength = pieceLength;
983
988
  }
984
989
  else {
@@ -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));
@@ -236,7 +237,7 @@ export class DLine {
236
237
  .move(sinCos.clone().scale(d[index])
237
238
  .setX(({ x }) => -x)));
238
239
  }
239
- return res.length === 1 ? res[0] : res;
240
+ return isArray ? res : res[0];
240
241
  }
241
242
  findFi({ a, b }, delta = 1.0001) {
242
243
  const { a: q, b: w } = this;
@@ -624,7 +624,7 @@ export class DPolygon {
624
624
  toArrayOfCoords() {
625
625
  return this.mapArray((r) => r.toCoords());
626
626
  }
627
- divideToPieces(piecesCount) {
627
+ divideToPieces(piecesCount, withAltitude = false) {
628
628
  const { fullLength } = this;
629
629
  const pieceLength = fullLength / piecesCount;
630
630
  let currentPieceLength = pieceLength;
@@ -641,6 +641,10 @@ export class DPolygon {
641
641
  .filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
642
642
  intersectionPoint.properties.pieceBorder = true;
643
643
  this.insertAfter(i, intersectionPoint);
644
+ if (withAltitude) {
645
+ const p1z = p1.z;
646
+ intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
647
+ }
644
648
  currentPieceLength = pieceLength;
645
649
  }
646
650
  else {
@@ -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));
@@ -281,7 +282,7 @@ var DLine = (function () {
281
282
  return -x;
282
283
  })); });
283
284
  }
284
- return res.length === 1 ? res[0] : res;
285
+ return isArray ? res : res[0];
285
286
  };
286
287
  DLine.prototype.findFi = function (_a, delta) {
287
288
  var a = _a.a, b = _a.b;
@@ -958,8 +958,9 @@ var DPolygon = (function () {
958
958
  DPolygon.prototype.toArrayOfCoords = function () {
959
959
  return this.mapArray(function (r) { return r.toCoords(); });
960
960
  };
961
- DPolygon.prototype.divideToPieces = function (piecesCount) {
961
+ DPolygon.prototype.divideToPieces = function (piecesCount, withAltitude) {
962
962
  var e_13, _a;
963
+ if (withAltitude === void 0) { withAltitude = false; }
963
964
  var fullLength = this.fullLength;
964
965
  var pieceLength = fullLength / piecesCount;
965
966
  var currentPieceLength = pieceLength;
@@ -976,6 +977,10 @@ var DPolygon = (function () {
976
977
  .filter(function (p) { return line_1.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE); })[0];
977
978
  intersectionPoint.properties.pieceBorder = true;
978
979
  this_1.insertAfter(i, intersectionPoint);
980
+ if (withAltitude) {
981
+ var p1z = p1.z;
982
+ intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
983
+ }
979
984
  currentPieceLength = pieceLength;
980
985
  }
981
986
  else {
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
+ };