dgeoutils 2.3.6 → 2.4.1

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,81 +1,43 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- var __values = (this && this.__values) || function(o) {
28
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
29
- if (m) return m.call(o);
30
- if (o && typeof o.length === "number") return {
31
- next: function () {
32
- if (o && i >= o.length) o = void 0;
33
- return { value: o && o[i++], done: !o };
34
- }
35
- };
36
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.TraceMatrix = exports.TraceMatrixValues = void 0;
40
- var DPoint_1 = require("./DPoint");
41
- var DPolygon_1 = require("./DPolygon");
42
- var FastSearch_1 = require("./FastSearch");
43
- var utils_1 = require("./utils");
4
+ const DPoint_1 = require("./DPoint");
5
+ const DPolygon_1 = require("./DPolygon");
6
+ const FastSearch_1 = require("./FastSearch");
7
+ const utils_1 = require("./utils");
44
8
  var TraceMatrixValues;
45
9
  (function (TraceMatrixValues) {
46
10
  TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
47
11
  TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
48
12
  })(TraceMatrixValues = exports.TraceMatrixValues || (exports.TraceMatrixValues = {}));
49
- var getByPosition = function (m, p, defaultValue) {
50
- if (defaultValue === void 0) { defaultValue = TraceMatrixValues.f; }
13
+ const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
51
14
  if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
52
15
  return defaultValue;
53
16
  }
54
17
  return m[p.y][p.x];
55
18
  };
56
- var setByPosition = function (m, p, value) {
19
+ const setByPosition = (m, p, value) => {
57
20
  if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
58
21
  return value;
59
22
  }
60
23
  m[p.y][p.x] = value;
61
24
  return m[p.y][p.x];
62
25
  };
63
- var TraceMatrix = (function () {
64
- function TraceMatrix(size, f) {
65
- var _this = this;
26
+ class TraceMatrix {
27
+ constructor(size, f) {
66
28
  this.size = size;
67
- this.findGroupByIndex = function (m, s) {
68
- var res = new DPolygon_1.DPolygon();
29
+ this.findGroupByIndex = (m, s) => {
30
+ const res = new DPolygon_1.DPolygon();
69
31
  if (s && getByPosition(m, s) === TraceMatrixValues.t) {
70
32
  res.push(s);
71
- var startIndex = 0;
72
- var marked = TraceMatrix.createMatrix(_this.size, function () { return TraceMatrixValues.f; });
33
+ let startIndex = 0;
34
+ const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
73
35
  setByPosition(marked, s, TraceMatrixValues.t);
74
36
  while (startIndex < res.length) {
75
- var r = res.at(startIndex);
76
- for (var i = -1; i < 2; i++) {
77
- for (var j = -1; j < 2; j++) {
78
- var t = new DPoint_1.DPoint(r.x + i, r.y + j);
37
+ const r = res.at(startIndex);
38
+ for (let i = -1; i < 2; i++) {
39
+ for (let j = -1; j < 2; j++) {
40
+ const t = new DPoint_1.DPoint(r.x + i, r.y + j);
79
41
  if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
80
42
  getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
81
43
  res.push(t);
@@ -88,32 +50,32 @@ var TraceMatrix = (function () {
88
50
  }
89
51
  return res;
90
52
  };
91
- this.findAllGroupsInMatrix = function (m) {
92
- var firstMark = _this.findMarked(m);
53
+ this.findAllGroupsInMatrix = (m) => {
54
+ const firstMark = this.findMarked(m);
93
55
  if (!firstMark) {
94
56
  return [];
95
57
  }
96
- var group = _this.findGroupByIndex(m, firstMark);
97
- var groups = [group];
98
- var groupSum = group.length;
99
- var allGroups = __spreadArray([], __read(group.points), false);
100
- var fs = new FastSearch_1.FastSearch();
58
+ const group = this.findGroupByIndex(m, firstMark);
59
+ const groups = [group];
60
+ let groupSum = group.length;
61
+ let allGroups = [...group.points];
62
+ const fs = new FastSearch_1.FastSearch();
101
63
  fs.add(allGroups);
102
- while (groupSum < _this.totalCountInMatrix(m)) {
103
- var mark = _this.findMarked(m);
64
+ while (groupSum < this.totalCountInMatrix(m)) {
65
+ let mark = this.findMarked(m);
104
66
  while (mark && fs.find(mark)) {
105
- mark = _this.findMarked(m, mark);
67
+ mark = this.findMarked(m, mark);
106
68
  }
107
- var nextGroup = _this.findGroupByIndex(m, mark);
69
+ const nextGroup = this.findGroupByIndex(m, mark);
108
70
  groupSum += nextGroup.length;
109
- allGroups = __spreadArray(__spreadArray([], __read(allGroups), false), __read(nextGroup.points), false);
71
+ allGroups = [...allGroups, ...nextGroup.points];
110
72
  fs.add(nextGroup.points);
111
73
  groups.push(nextGroup);
112
74
  }
113
- return groups.filter(function (g) { return g.length > 2; });
75
+ return groups.filter((g) => g.length > 2);
114
76
  };
115
- this.traceGroup = function (m, group) {
116
- var traceDirections = [
77
+ this.traceGroup = (m, group) => {
78
+ const traceDirections = [
117
79
  new DPoint_1.DPoint(-1, -1),
118
80
  new DPoint_1.DPoint(-1, 0),
119
81
  new DPoint_1.DPoint(-1, 1),
@@ -123,20 +85,20 @@ var TraceMatrix = (function () {
123
85
  new DPoint_1.DPoint(1, -1),
124
86
  new DPoint_1.DPoint(0, -1)
125
87
  ];
126
- var left = function (d) { return (d + traceDirections.length + 1) % traceDirections.length; };
127
- var right = function (d) { return (d + traceDirections.length - 1) % traceDirections.length; };
88
+ const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
89
+ const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
128
90
  if (group.length < 2) {
129
- var t = group.at(0).clone();
91
+ const t = group.at(0).clone();
130
92
  return new DPolygon_1.DPolygon([t, t, t]);
131
93
  }
132
- var points = new DPolygon_1.DPolygon();
133
- var direction = 0;
134
- var prevDirection = Infinity;
135
- var p = group.at(0);
94
+ const points = new DPolygon_1.DPolygon();
95
+ let direction = 0;
96
+ let prevDirection = Infinity;
97
+ let p = group.at(0);
136
98
  while (!p.equal(group.at(0)) || points.length < 2) {
137
99
  while (true) {
138
- var nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
139
- var nextNeighbourValue = getByPosition(m, p.clone().move(traceDirections[left(direction)]));
100
+ const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
101
+ const nextNeighbourValue = getByPosition(m, p.clone().move(traceDirections[left(direction)]));
140
102
  if (nextValue === TraceMatrixValues.t && nextNeighbourValue === TraceMatrixValues.f) {
141
103
  break;
142
104
  }
@@ -151,76 +113,64 @@ var TraceMatrix = (function () {
151
113
  }
152
114
  return points.approximation().close();
153
115
  };
154
- this.createHoleMatrix = function (group) {
155
- var e_1, _a;
156
- var fullTraceDirections = [
116
+ this.createHoleMatrix = (group) => {
117
+ const fullTraceDirections = [
157
118
  new DPoint_1.DPoint(-1, 0),
158
119
  new DPoint_1.DPoint(0, 1),
159
120
  new DPoint_1.DPoint(1, 0),
160
121
  new DPoint_1.DPoint(0, -1)
161
122
  ];
162
123
  group.prepareToFastSearch();
163
- var tmpMatrix = TraceMatrix
164
- .createMatrix(_this.size, function (p) { return group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f; });
165
- var startCoords = new DPolygon_1.DPolygon();
166
- for (var i = 0; i < _this.size.w; i++) {
124
+ const tmpMatrix = TraceMatrix
125
+ .createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
126
+ const startCoords = new DPolygon_1.DPolygon();
127
+ for (let i = 0; i < this.size.w; i++) {
167
128
  startCoords.push(new DPoint_1.DPoint(i, -1));
168
- startCoords.push(new DPoint_1.DPoint(i, _this.size.h));
129
+ startCoords.push(new DPoint_1.DPoint(i, this.size.h));
169
130
  }
170
- for (var i = 0; i < _this.size.h; i++) {
131
+ for (let i = 0; i < this.size.h; i++) {
171
132
  startCoords.push(new DPoint_1.DPoint(-1, i));
172
- startCoords.push(new DPoint_1.DPoint(_this.size.w, i));
133
+ startCoords.push(new DPoint_1.DPoint(this.size.w, i));
173
134
  }
174
135
  while (startCoords.length) {
175
- var point = startCoords.pop();
176
- try {
177
- for (var fullTraceDirections_1 = (e_1 = void 0, __values(fullTraceDirections)), fullTraceDirections_1_1 = fullTraceDirections_1.next(); !fullTraceDirections_1_1.done; fullTraceDirections_1_1 = fullTraceDirections_1.next()) {
178
- var direction = fullTraceDirections_1_1.value;
179
- var tmpPoint = point.clone().move(direction);
180
- var value = getByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
181
- if (value === TraceMatrixValues.f) {
182
- setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
183
- startCoords.push(tmpPoint);
184
- }
185
- }
186
- }
187
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
188
- finally {
189
- try {
190
- if (fullTraceDirections_1_1 && !fullTraceDirections_1_1.done && (_a = fullTraceDirections_1.return)) _a.call(fullTraceDirections_1);
136
+ const point = startCoords.pop();
137
+ for (const direction of fullTraceDirections) {
138
+ const tmpPoint = point.clone().move(direction);
139
+ const value = getByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
140
+ if (value === TraceMatrixValues.f) {
141
+ setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
142
+ startCoords.push(tmpPoint);
191
143
  }
192
- finally { if (e_1) throw e_1.error; }
193
144
  }
194
145
  }
195
- var t = _this.reverseMatrix(tmpMatrix);
196
- return _this.totalCountInMatrix(t) ? t : null;
146
+ const t = this.reverseMatrix(tmpMatrix);
147
+ return this.totalCountInMatrix(t) ? t : null;
197
148
  };
198
149
  this.m = TraceMatrix.createMatrix(this.size, f);
199
150
  }
200
- TraceMatrix.prototype.fullMatrixTrace = function () {
201
- var _this = this;
202
- var groups = this.findAllGroupsInMatrix(this.m);
203
- var paths = groups.map(function (g) { return _this.traceGroup(_this.m, g); });
204
- var holeMatrixs = groups.map(this.createHoleMatrix);
205
- var holesGroups = holeMatrixs.map(function (m) { return m && _this.findAllGroupsInMatrix(m); });
206
- var holesPaths = holesGroups.map(function (hg, index) { return hg && hg.map(function (g) { return _this
207
- .traceGroup(holeMatrixs[index], g); }).filter(function (r) { return r.length > DPolygon_1.MIN_POINTS_IN_VALID_POLYGON; }); });
208
- return groups.map(function (g, index) {
209
- var res = paths[index];
151
+ fullMatrixTrace() {
152
+ const groups = this.findAllGroupsInMatrix(this.m);
153
+ const paths = groups.map((g) => this.traceGroup(this.m, g));
154
+ const holeMatrixs = groups.map(this.createHoleMatrix);
155
+ const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
156
+ const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
157
+ .traceGroup(holeMatrixs[index], g)).filter((r) => r.length > DPolygon_1.MIN_POINTS_IN_VALID_POLYGON));
158
+ return groups.map((g, index) => {
159
+ const res = paths[index];
210
160
  if (holesGroups[index] && holesGroups[index].length) {
211
161
  res.holes = holesPaths[index];
212
162
  }
213
163
  return res;
214
164
  });
215
- };
216
- TraceMatrix.prototype.reverseMatrix = function (m) {
217
- return TraceMatrix.createMatrix(this.size, function (p) { return getByPosition(m, p) === TraceMatrixValues.f ? TraceMatrixValues.t : TraceMatrixValues.f; });
218
- };
219
- TraceMatrix.prototype.findMarked = function (m, init) {
220
- var s = this.size;
221
- var ini = false;
222
- for (var i = 0; i < s.w; i++) {
223
- for (var j = 0; j < s.h; j++) {
165
+ }
166
+ reverseMatrix(m) {
167
+ return TraceMatrix.createMatrix(this.size, (p) => getByPosition(m, p) === TraceMatrixValues.f ? TraceMatrixValues.t : TraceMatrixValues.f);
168
+ }
169
+ findMarked(m, init) {
170
+ const s = this.size;
171
+ let ini = false;
172
+ for (let i = 0; i < s.w; i++) {
173
+ for (let j = 0; j < s.h; j++) {
224
174
  if (!ini && init) {
225
175
  i = init.x;
226
176
  j = init.y;
@@ -233,24 +183,22 @@ var TraceMatrix = (function () {
233
183
  }
234
184
  }
235
185
  return null;
236
- };
237
- TraceMatrix.prototype.totalCountInMatrix = function (m) {
238
- var res = 0;
239
- var s = this.size;
240
- for (var i = 0; i < s.w; i++) {
241
- for (var j = 0; j < s.h; j++) {
186
+ }
187
+ totalCountInMatrix(m) {
188
+ let res = 0;
189
+ const s = this.size;
190
+ for (let i = 0; i < s.w; i++) {
191
+ for (let j = 0; j < s.h; j++) {
242
192
  if (getByPosition(m, new DPoint_1.DPoint(i, j))) {
243
193
  res++;
244
194
  }
245
195
  }
246
196
  }
247
197
  return res;
248
- };
249
- TraceMatrix.createMatrix = function (size, f) {
250
- if (f === void 0) { f = function () { return TraceMatrixValues.f; }; }
198
+ }
199
+ static createMatrix(size, f = () => TraceMatrixValues.f) {
251
200
  return (0, utils_1.createArray)(size.h)
252
- .map(function (v, i) { return (0, utils_1.createArray)(size.w).map(function (v2, j) { return f(new DPoint_1.DPoint(j, i)); }); });
253
- };
254
- return TraceMatrix;
255
- }());
201
+ .map((v, i) => (0, utils_1.createArray)(size.w).map((v2, j) => f(new DPoint_1.DPoint(j, i))));
202
+ }
203
+ }
256
204
  exports.TraceMatrix = TraceMatrix;
@@ -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, cartesianProduct, 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.cartesianProduct = 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);
@@ -27,4 +27,5 @@ Object.defineProperty(exports, "createArray", { enumerable: true, get: function
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
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; } });
30
31
  Object.defineProperty(exports, "DGeo", { enumerable: true, get: function () { return utils_1.DGeo; } });
@@ -36,6 +36,7 @@ export declare const createCanvas: {
36
36
  document?: Document;
37
37
  };
38
38
  export declare const cartesianProduct: {
39
- <T>(...a: T[][]): T[][];
39
+ <T>(a: T[], ...b: T[][]): T[][];
40
40
  };
41
+ export declare const getCombinations: <T>(arr: T[][]) => T[][];
41
42
  export {};
package/dist/cjs/utils.js CHANGED
@@ -1,87 +1,58 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
2
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
29
- var DPoint_1 = require("./DPoint");
3
+ exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
4
+ const DPoint_1 = require("./DPoint");
30
5
  exports.DGeo = {
31
6
  DEBUG: false
32
7
  };
33
- var warn = function () {
34
- var args = [];
35
- for (var _i = 0; _i < arguments.length; _i++) {
36
- args[_i] = arguments[_i];
37
- }
8
+ const warn = (...args) => {
38
9
  if (exports.DGeo.DEBUG) {
39
- console.warn.apply(console, __spreadArray([], __read(args), false));
10
+ console.warn(...args);
40
11
  }
41
12
  };
42
13
  exports.warn = warn;
43
- var isDefAndNotNull = function (a) { return a != undefined; };
14
+ const isDefAndNotNull = (a) => a != undefined;
44
15
  exports.isDefAndNotNull = isDefAndNotNull;
45
- var hook = function (scope) { return function () { return scope; }; };
46
- var shouldBeInt = function (scope, funcName, argName) { return function (p) {
16
+ const hook = (scope) => () => scope;
17
+ const shouldBeInt = (scope, funcName, argName) => (p) => {
47
18
  if (!p.clone().round()
48
19
  .equal(p)) {
49
- (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be Int!");
20
+ (0, exports.warn)(`"${funcName}" -> "${argName}" should be Int!`);
50
21
  }
51
22
  return scope;
52
- }; };
53
- var shouldBeUInt = function (scope, funcName, argName) { return function (p) {
23
+ };
24
+ const shouldBeUInt = (scope, funcName, argName) => (p) => {
54
25
  if (!p.clone().round()
55
26
  .equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
56
- (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be UInt!");
27
+ (0, exports.warn)(`"${funcName}" -> "${argName}" should be UInt!`);
57
28
  }
58
29
  return scope;
59
- }; };
60
- var shouldBeDegree = function (scope, funcName, argName) { return function (p) {
30
+ };
31
+ const shouldBeDegree = (scope, funcName, argName) => (p) => {
61
32
  if (!p.likeWorldGeodeticSystem) {
62
- (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be degree!");
33
+ (0, exports.warn)(`"${funcName}" -> "${argName}" should be degree!`);
63
34
  }
64
35
  return scope;
65
- }; };
66
- var shouldBeRadians = function (scope, funcName, argName) { return function (p) {
36
+ };
37
+ const shouldBeRadians = (scope, funcName, argName) => (p) => {
67
38
  if (!p.likeRadians) {
68
- (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be radians!");
39
+ (0, exports.warn)(`"${funcName}" -> "${argName}" should be radians!`);
69
40
  }
70
41
  return scope;
71
- }; };
72
- var shouldExist = function (scope, funcName, argName) { return function (p) {
42
+ };
43
+ const shouldExist = (scope, funcName, argName) => (p) => {
73
44
  if (!(0, exports.isDefAndNotNull)(p)) {
74
- (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should exist!");
45
+ (0, exports.warn)(`"${funcName}" -> "${argName}" should exist!`);
75
46
  }
76
47
  return scope;
77
- }; };
78
- var shouldBeMeters = function (scope, funcName, argName) { return function (p) {
48
+ };
49
+ const shouldBeMeters = (scope, funcName, argName) => (p) => {
79
50
  if (!p.likePseudoMercator) {
80
- (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be meters!");
51
+ (0, exports.warn)(`"${funcName}" -> "${argName}" should be meters!`);
81
52
  }
82
53
  return scope;
83
- }; };
84
- var checkFunction = function (funcName) { return ({
54
+ };
55
+ const checkFunction = (funcName) => ({
85
56
  checkArgument: function (argName) {
86
57
  if (!exports.DGeo.DEBUG) {
87
58
  return {
@@ -102,71 +73,64 @@ var checkFunction = function (funcName) { return ({
102
73
  shouldExist: shouldExist(this, funcName, argName)
103
74
  };
104
75
  }
105
- }); };
76
+ });
106
77
  exports.checkFunction = checkFunction;
107
- var createArray = function (v, fillSymbol) {
108
- if (fillSymbol === void 0) { fillSymbol = 0; }
109
- return new Array(v).fill(fillSymbol);
110
- };
78
+ const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
111
79
  exports.createArray = createArray;
112
- var createMatrix = function (_a, fillSymbol) {
113
- var h = _a.h, w = _a.w;
114
- if (fillSymbol === void 0) { fillSymbol = 0; }
115
- return (0, exports.createArray)(h)
116
- .map(function () { return (0, exports.createArray)(w, fillSymbol); });
117
- };
80
+ const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
81
+ .map(() => (0, exports.createArray)(w, fillSymbol));
118
82
  exports.createMatrix = createMatrix;
119
- var gaussianElimination = function (matrix) {
120
- var n = matrix.length;
121
- var matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
122
- for (var i = 0; i < n; i++) {
123
- for (var j = 0; j < n + 1; j++) {
83
+ const gaussianElimination = (matrix) => {
84
+ const n = matrix.length;
85
+ const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
86
+ for (let i = 0; i < n; i++) {
87
+ for (let j = 0; j < n + 1; j++) {
124
88
  matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
125
89
  matrixClone[i][j] = matrix[i][j];
126
90
  }
127
91
  }
128
- for (var k = 0; k < n; k++) {
129
- for (var i = 0; i < n + 1; i++) {
92
+ for (let k = 0; k < n; k++) {
93
+ for (let i = 0; i < n + 1; i++) {
130
94
  matrixClone[k][i] /= matrix[k][k];
131
95
  }
132
- for (var i = k + 1; i < n; i++) {
133
- var K = matrixClone[i][k] / matrixClone[k][k];
134
- for (var j = 0; j < n + 1; j++) {
96
+ for (let i = k + 1; i < n; i++) {
97
+ const K = matrixClone[i][k] / matrixClone[k][k];
98
+ for (let j = 0; j < n + 1; j++) {
135
99
  matrixClone[i][j] -= matrixClone[k][j] * K;
136
100
  }
137
101
  }
138
- for (var i = 0; i < n; i++) {
139
- for (var j = 0; j < n + 1; j++) {
102
+ for (let i = 0; i < n; i++) {
103
+ for (let j = 0; j < n + 1; j++) {
140
104
  matrix[i][j] = matrixClone[i][j];
141
105
  }
142
106
  }
143
107
  }
144
- for (var k = n - 1; k > -1; k--) {
145
- for (var i = n; i > -1; i--) {
108
+ for (let k = n - 1; k > -1; k--) {
109
+ for (let i = n; i > -1; i--) {
146
110
  matrixClone[k][i] /= matrix[k][k];
147
111
  }
148
- for (var i = k - 1; i > -1; i--) {
149
- var K = matrixClone[i][k] / matrixClone[k][k];
150
- for (var j = n; j > -1; j--) {
112
+ for (let i = k - 1; i > -1; i--) {
113
+ const K = matrixClone[i][k] / matrixClone[k][k];
114
+ for (let j = n; j > -1; j--) {
151
115
  matrixClone[i][j] -= matrixClone[k][j] * K;
152
116
  }
153
117
  }
154
118
  }
155
- var answer = (0, exports.createArray)(n);
156
- for (var i = 0; i < n; i++) {
119
+ const answer = (0, exports.createArray)(n);
120
+ for (let i = 0; i < n; i++) {
157
121
  answer[i] = matrixClone[i][n];
158
122
  }
159
123
  return answer;
160
124
  };
161
125
  exports.gaussianElimination = gaussianElimination;
162
126
  exports.gaussianElimination.MIN = 1e-10;
163
- var createCanvas = function (a, b, c) {
127
+ const createCanvas = (a, b, c) => {
164
128
  var _a;
165
- var w = 0;
166
- var h = 0;
167
- var offscreen = false;
129
+ let w = 0;
130
+ let h = 0;
131
+ let offscreen = false;
168
132
  if (a instanceof DPoint_1.DPoint) {
169
- var x = a.x, y = a.y;
133
+ const { x, y } = a;
170
134
  w = x;
171
135
  h = y;
172
136
  }
@@ -183,7 +147,7 @@ var createCanvas = function (a, b, c) {
183
147
  if (typeof c === 'boolean') {
184
148
  offscreen = c;
185
149
  }
186
- var canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
150
+ const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
187
151
  if (!offscreen) {
188
152
  canvas.width = w;
189
153
  canvas.height = h;
@@ -191,12 +155,20 @@ var createCanvas = function (a, b, c) {
191
155
  return [canvas, canvas.getContext('2d')];
192
156
  };
193
157
  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];
158
+ const f = (a, b) => [].concat(...a.map((c) => b.map((d) => [].concat(c, d))));
159
+ const cartesianProduct = (a, b, ...c) => b ? (0, exports.cartesianProduct)(f(a, b), ...c) : a;
160
+ exports.cartesianProduct = cartesianProduct;
161
+ const getCombinations = (arr) => {
162
+ if (arr.length === 1) {
163
+ return arr[0];
164
+ }
165
+ const ans = [];
166
+ const otherCases = (0, exports.getCombinations)(arr.slice(1));
167
+ for (let i = 0; i < otherCases.length; i++) {
168
+ for (let j = 0; j < arr[0].length; j++) {
169
+ ans.push([arr[0][j], ...otherCases[i]]);
170
+ }
199
171
  }
200
- return b ? exports.cartesianProduct.apply(void 0, __spreadArray([f(a, b)], __read(c), false)) : a;
172
+ return ans;
201
173
  };
202
- exports.cartesianProduct = cartesianProduct;
174
+ exports.getCombinations = getCombinations;
@@ -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, cartesianProduct, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';