dgeoutils 2.4.0 → 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,128 +1,44 @@
1
1
  "use strict";
2
- var __generator = (this && this.__generator) || function (thisArg, body) {
3
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
4
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
5
- function verb(n) { return function (v) { return step([n, v]); }; }
6
- function step(op) {
7
- if (f) throw new TypeError("Generator is already executing.");
8
- while (_) try {
9
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
10
- if (y = 0, t) op = [op[0] & 2, t.value];
11
- switch (op[0]) {
12
- case 0: case 1: t = op; break;
13
- case 4: _.label++; return { value: op[1], done: false };
14
- case 5: _.label++; y = op[1]; op = [0]; continue;
15
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
16
- default:
17
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
18
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
19
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
20
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
21
- if (t[2]) _.ops.pop();
22
- _.trys.pop(); continue;
23
- }
24
- op = body.call(thisArg, _);
25
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
26
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
27
- }
28
- };
29
- var __values = (this && this.__values) || function(o) {
30
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
31
- if (m) return m.call(o);
32
- if (o && typeof o.length === "number") return {
33
- next: function () {
34
- if (o && i >= o.length) o = void 0;
35
- return { value: o && o[i++], done: !o };
36
- }
37
- };
38
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
39
- };
40
- var __read = (this && this.__read) || function (o, n) {
41
- var m = typeof Symbol === "function" && o[Symbol.iterator];
42
- if (!m) return o;
43
- var i = m.call(o), r, ar = [], e;
44
- try {
45
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
46
- }
47
- catch (error) { e = { error: error }; }
48
- finally {
49
- try {
50
- if (r && !r.done && (m = i["return"])) m.call(i);
51
- }
52
- finally { if (e) throw e.error; }
53
- }
54
- return ar;
55
- };
56
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
58
- if (ar || !(i in from)) {
59
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
60
- ar[i] = from[i];
61
- }
62
- }
63
- return to.concat(ar || Array.prototype.slice.call(from));
64
- };
65
2
  Object.defineProperty(exports, "__esModule", { value: true });
66
3
  exports.DPolygon = exports.MIN_POINTS_IN_VALID_POLYGON = void 0;
67
- var DPoint_1 = require("./DPoint");
68
- var DLine_1 = require("./DLine");
69
- var DCircle_1 = require("./DCircle");
70
- var DNumbers_1 = require("./DNumbers");
71
- var jsts_1 = require("jsts");
72
- var DPolygonLoop_1 = require("./DPolygonLoop");
73
- var utils_1 = require("./utils");
74
- var _a = jsts_1.operation.buffer.BufferParameters, CAP_ROUND = _a.CAP_ROUND, CAP_FLAT = _a.CAP_FLAT, CAP_SQUARE = _a.CAP_SQUARE;
4
+ const DPoint_1 = require("./DPoint");
5
+ const DLine_1 = require("./DLine");
6
+ const DCircle_1 = require("./DCircle");
7
+ const DNumbers_1 = require("./DNumbers");
8
+ const jsts_1 = require("jsts");
9
+ const DPolygonLoop_1 = require("./DPolygonLoop");
10
+ const utils_1 = require("./utils");
11
+ const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = jsts_1.operation;
75
12
  exports.MIN_POINTS_IN_VALID_POLYGON = 3;
76
- var APPROXIMATION_VALUE = 0.1;
77
- var MAX_CONVEX_ITERATIONS = 100;
78
- var CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
79
- var containCalculator = function (poly, p) {
80
- var e_1, _a, e_2, _b;
81
- var hasSamePoint = poly.points.some(function (point) { return point.equal(p); });
13
+ const APPROXIMATION_VALUE = 0.1;
14
+ const MAX_CONVEX_ITERATIONS = 100;
15
+ const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
16
+ const containCalculator = (poly, p) => {
17
+ const hasSamePoint = poly.points.some((point) => point.equal(p));
82
18
  if (hasSamePoint) {
83
19
  return true;
84
20
  }
85
- try {
86
- for (var _c = __values(poly.loopPointsGenerator(true)()), _d = _c.next(); !_d.done; _d = _c.next()) {
87
- var _e = __read(_d.value, 3), polygonLine = _e[2];
88
- var onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
89
- if (onBorder) {
90
- return true;
91
- }
21
+ for (const [, , polygonLine] of poly.loopPointsGenerator(true)()) {
22
+ const onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
23
+ if (onBorder) {
24
+ return true;
92
25
  }
93
26
  }
94
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
95
- finally {
96
- try {
97
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
98
- }
99
- finally { if (e_1) throw e_1.error; }
100
- }
101
- var totalFi = 0;
102
- try {
103
- for (var _f = __values(poly.loopPointsGenerator()()), _g = _f.next(); !_g.done; _g = _f.next()) {
104
- var _h = __read(_g.value, 2), _j = _h[0], x = _j.x, y = _j.y, _k = _h[1], a = _k.x, b = _k.y;
105
- var line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
106
- var line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
107
- var fiDif = line1.findFi(line2);
108
- if (line1.vectorProduct(line2).c > 0) {
109
- totalFi += fiDif;
110
- }
111
- else {
112
- totalFi -= fiDif;
113
- }
27
+ let totalFi = 0;
28
+ for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
29
+ const line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
30
+ const line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
31
+ const fiDif = line1.findFi(line2);
32
+ if (line1.vectorProduct(line2).c > 0) {
33
+ totalFi += fiDif;
114
34
  }
115
- }
116
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
117
- finally {
118
- try {
119
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
35
+ else {
36
+ totalFi -= fiDif;
120
37
  }
121
- finally { if (e_2) throw e_2.error; }
122
38
  }
123
- var eps = Math.PI / 10000;
124
- var result = false;
125
- var absTotalFi = Math.abs(totalFi);
39
+ const eps = Math.PI / 10000;
40
+ let result = false;
41
+ const absTotalFi = Math.abs(totalFi);
126
42
  if (absTotalFi < eps) {
127
43
  result = false;
128
44
  }
@@ -134,58 +50,46 @@ var containCalculator = function (poly, p) {
134
50
  }
135
51
  return result;
136
52
  };
137
- var DPolygon = (function () {
138
- function DPolygon(pPoints) {
139
- if (pPoints === void 0) { pPoints = []; }
53
+ class DPolygon {
54
+ constructor(pPoints = []) {
140
55
  this.pPoints = pPoints;
141
56
  this.properties = {};
142
57
  this.holes = [];
143
58
  this.searchStore = {};
144
59
  }
145
- DPolygon.arrayOfTrianglesToVertices = function (triangles, height) {
146
- return triangles.map(function (v) { return ((0, utils_1.isDefAndNotNull)(height) ? v
60
+ static arrayOfTrianglesToVertices(triangles, height) {
61
+ return triangles.map((v) => ((0, utils_1.isDefAndNotNull)(height) ? v
147
62
  .loop()
148
63
  .height(height)
149
64
  .run() : v)
150
- .toArrayOfCoords(); })
65
+ .toArrayOfCoords())
151
66
  .flat(2);
152
- };
153
- DPolygon.minAreaRectangleSize = function (poly) {
154
- var _a = poly.clone().open(), first = _a.first, second = _a.second, last = _a.last;
67
+ }
68
+ static minAreaRectangleSize(poly) {
69
+ const { first, second, last } = poly.clone().open();
155
70
  return new DPoint_1.DPoint(first.distance(second), first.distance(last));
156
- };
157
- DPolygon.toDash = function (poly) {
158
- var e_3, _a;
159
- var p = new DPolygon();
160
- var result = [p];
161
- var trigger = true;
162
- try {
163
- for (var _b = __values(poly.points), _c = _b.next(); !_c.done; _c = _b.next()) {
164
- var point = _c.value;
71
+ }
72
+ static toDash(poly) {
73
+ let p = new DPolygon();
74
+ const result = [p];
75
+ let trigger = true;
76
+ for (const point of poly.points) {
77
+ if (trigger) {
78
+ p.push(point.clone());
79
+ }
80
+ if (point.properties.pieceBorder) {
81
+ trigger = !trigger;
165
82
  if (trigger) {
83
+ p = new DPolygon();
84
+ result.push(p);
166
85
  p.push(point.clone());
167
86
  }
168
- if (point.properties.pieceBorder) {
169
- trigger = !trigger;
170
- if (trigger) {
171
- p = new DPolygon();
172
- result.push(p);
173
- p.push(point.clone());
174
- }
175
- }
176
87
  }
177
88
  }
178
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
179
- finally {
180
- try {
181
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
182
- }
183
- finally { if (e_3) throw e_3.error; }
184
- }
185
89
  return result;
186
- };
187
- DPolygon.minAreaRectangleDirection = function (poly) {
188
- var _a = poly.clone().open(), first = _a.first, second = _a.second, last = _a.last;
90
+ }
91
+ static minAreaRectangleDirection(poly) {
92
+ const { first, second, last } = poly.clone().open();
189
93
  if (!first || !second || !last) {
190
94
  return 0;
191
95
  }
@@ -193,581 +97,374 @@ var DPolygon = (function () {
193
97
  return first.findLine(second).getFi();
194
98
  }
195
99
  return first.findLine(last).getFi();
196
- };
197
- DPolygon.parseFromWKT = function (wkt) {
198
- var data = wkt.trim().toUpperCase();
199
- var res = new DPolygon();
100
+ }
101
+ static parseFromWKT(wkt) {
102
+ const data = wkt.trim().toUpperCase();
103
+ let res = new DPolygon();
200
104
  if (data.indexOf('POLYGON') === 0) {
201
- var regexp = /POLYGON \(\((?<data>(?:(?!\)\)$).)*?)\)\)$/miu;
202
- var reg = regexp.exec(data);
203
- var _a = __read(reg.groups.data
105
+ const regexp = /POLYGON \(\((?<data>(?:(?!\)\)$).)*?)\)\)$/miu;
106
+ const reg = regexp.exec(data);
107
+ const [path, ...holes] = reg.groups.data
204
108
  .split('), (')
205
- .map(function (p) { return new DPolygon(p.split(', ')
206
- .map(function (pares) { return DPoint_1.DPoint.parse(pares.split(' ').map(Number)); })); })), path = _a[0], holes = _a.slice(1);
109
+ .map((p) => new DPolygon(p.split(', ')
110
+ .map((pares) => DPoint_1.DPoint.parse(pares.split(' ').map(Number)))));
207
111
  if (holes && holes.length) {
208
112
  path.holes = holes;
209
113
  }
210
114
  res = path;
211
115
  }
212
116
  if (data.indexOf('LINESTRING') === 0) {
213
- var regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
214
- var reg = regexp.exec(data);
117
+ const regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
118
+ const reg = regexp.exec(data);
215
119
  res = new DPolygon(reg.groups.data
216
- .split(', ').map(function (t) { return DPoint_1.DPoint.parse(t.split(' ').map(Number)); }));
120
+ .split(', ').map((t) => DPoint_1.DPoint.parse(t.split(' ').map(Number))));
217
121
  }
218
122
  if (data.indexOf('POINT') === 0) {
219
123
  res = new DPolygon([DPoint_1.DPoint.parseFromWKT(data)]);
220
124
  }
221
125
  return res;
222
- };
223
- DPolygon.createSquareBySize = function (size) {
126
+ }
127
+ static createSquareBySize(size) {
224
128
  return new DPolygon([DPoint_1.DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
225
- };
226
- DPolygon.prototype.loop = function () {
129
+ }
130
+ loop() {
227
131
  return new DPolygonLoop_1.DPolygonLoop(this);
228
- };
229
- Object.defineProperty(DPolygon.prototype, "points", {
230
- get: function () {
231
- return this.pPoints;
232
- },
233
- set: function (p) {
234
- this.pPoints = p;
235
- },
236
- enumerable: false,
237
- configurable: true
238
- });
239
- Object.defineProperty(DPolygon.prototype, "maxX", {
240
- get: function () {
241
- return this.reduce(function (a, r) { return Math.max(a, r.x); }, -Infinity);
242
- },
243
- enumerable: false,
244
- configurable: true
245
- });
246
- Object.defineProperty(DPolygon.prototype, "minX", {
247
- get: function () {
248
- return this.reduce(function (a, r) { return Math.min(a, r.x); }, Infinity);
249
- },
250
- enumerable: false,
251
- configurable: true
252
- });
253
- Object.defineProperty(DPolygon.prototype, "maxY", {
254
- get: function () {
255
- return this.reduce(function (a, r) { return Math.max(a, r.y); }, -Infinity);
256
- },
257
- enumerable: false,
258
- configurable: true
259
- });
260
- Object.defineProperty(DPolygon.prototype, "minY", {
261
- get: function () {
262
- return this.reduce(function (a, r) { return Math.min(a, r.y); }, Infinity);
263
- },
264
- enumerable: false,
265
- configurable: true
266
- });
267
- Object.defineProperty(DPolygon.prototype, "center", {
268
- get: function () {
269
- return this.leftTop.move(this.size.divide(2));
270
- },
271
- enumerable: false,
272
- configurable: true
273
- });
274
- Object.defineProperty(DPolygon.prototype, "h", {
275
- get: function () {
276
- return this.maxY - this.minY;
277
- },
278
- enumerable: false,
279
- configurable: true
280
- });
281
- Object.defineProperty(DPolygon.prototype, "w", {
282
- get: function () {
283
- return this.maxX - this.minX;
284
- },
285
- enumerable: false,
286
- configurable: true
287
- });
288
- Object.defineProperty(DPolygon.prototype, "dY", {
289
- get: function () {
290
- return this.h;
291
- },
292
- enumerable: false,
293
- configurable: true
294
- });
295
- Object.defineProperty(DPolygon.prototype, "dX", {
296
- get: function () {
297
- return this.w;
298
- },
299
- enumerable: false,
300
- configurable: true
301
- });
302
- Object.defineProperty(DPolygon.prototype, "extend", {
303
- get: function () {
304
- var _a = this, minX = _a.minX, minY = _a.minY, maxX = _a.maxX, maxY = _a.maxY;
305
- return new DPolygon([
306
- new DPoint_1.DPoint(minX, minY),
307
- new DPoint_1.DPoint(maxX, minY),
308
- new DPoint_1.DPoint(maxX, maxY),
309
- new DPoint_1.DPoint(minX, maxY),
310
- new DPoint_1.DPoint(minX, minY)
311
- ]);
312
- },
313
- enumerable: false,
314
- configurable: true
315
- });
316
- Object.defineProperty(DPolygon.prototype, "size", {
317
- get: function () {
318
- var _a = this, w = _a.w, h = _a.h;
319
- return new DPoint_1.DPoint(w, h);
320
- },
321
- enumerable: false,
322
- configurable: true
323
- });
324
- Object.defineProperty(DPolygon.prototype, "leftTop", {
325
- get: function () {
326
- var _a = this, minX = _a.minX, minY = _a.minY;
327
- return new DPoint_1.DPoint(minX, minY);
328
- },
329
- enumerable: false,
330
- configurable: true
331
- });
332
- Object.defineProperty(DPolygon.prototype, "rightBottom", {
333
- get: function () {
334
- var _a = this, maxX = _a.maxX, maxY = _a.maxY;
335
- return new DPoint_1.DPoint(maxX, maxY);
336
- },
337
- enumerable: false,
338
- configurable: true
339
- });
340
- Object.defineProperty(DPolygon.prototype, "length", {
341
- get: function () {
342
- return this.pPoints.length;
343
- },
344
- enumerable: false,
345
- configurable: true
346
- });
347
- Object.defineProperty(DPolygon.prototype, "fullLength", {
348
- get: function () {
349
- return this.clone().open().perimeter;
350
- },
351
- enumerable: false,
352
- configurable: true
353
- });
354
- Object.defineProperty(DPolygon.prototype, "perimeter", {
355
- get: function () {
356
- var e_4, _a;
357
- var p = 0;
358
- try {
359
- for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
360
- var _d = __read(_c.value, 2), p1 = _d[0], p2 = _d[1];
361
- p += p1.distance(p2);
362
- }
363
- }
364
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
365
- finally {
366
- try {
367
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
368
- }
369
- finally { if (e_4) throw e_4.error; }
370
- }
371
- return p;
372
- },
373
- enumerable: false,
374
- configurable: true
375
- });
376
- Object.defineProperty(DPolygon.prototype, "area", {
377
- get: function () {
378
- var e_5, _a;
379
- var sum = 0;
380
- try {
381
- for (var _b = __values(this.deintersection.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
382
- var _d = __read(_c.value, 2), _e = _d[0], x = _e.x, y = _e.y, _f = _d[1], a = _f.x, b = _f.y;
383
- sum += x * b - y * a;
384
- }
385
- }
386
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
387
- finally {
388
- try {
389
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
390
- }
391
- finally { if (e_5) throw e_5.error; }
392
- }
393
- return Math.abs(sum / 2) - this.holes.reduce(function (a, hole) { return a + hole.area; }, 0);
394
- },
395
- enumerable: false,
396
- configurable: true
397
- });
398
- Object.defineProperty(DPolygon.prototype, "deintersection", {
399
- get: function () {
400
- var e_6, _a;
401
- var p = this.clone().close();
402
- var store = {};
403
- for (var i = 0; i < p.length - 1; i++) {
404
- var k = p.at(i).toString();
405
- store[k] = store[k] || [];
406
- store[k].push(i);
407
- var _loop_1 = function (j) {
408
- var firstLine = p.at(i).findLine(p.at(i + 1));
409
- var secondLine = p.at(j).findLine(p.at(j + 1));
410
- var intersectionPoint = firstLine.intersection(secondLine);
411
- if (intersectionPoint &&
412
- !__spreadArray(__spreadArray([], __read(firstLine.points), false), __read(secondLine.points), false).some(function (t) { return t.like(intersectionPoint); })) {
413
- var part = p.removePart(i, j - i).reverse();
414
- p.insertAfter.apply(p, __spreadArray([i], __read(part), false));
415
- p.insertAfter(j, intersectionPoint);
416
- p.insertAfter(i, intersectionPoint);
417
- }
418
- };
419
- for (var j = i + 2; j < p.length - 1; j++) {
420
- _loop_1(j);
132
+ }
133
+ set points(p) {
134
+ this.pPoints = p;
135
+ }
136
+ get points() {
137
+ return this.pPoints;
138
+ }
139
+ get maxX() {
140
+ return this.reduce((a, r) => Math.max(a, r.x), -Infinity);
141
+ }
142
+ get minX() {
143
+ return this.reduce((a, r) => Math.min(a, r.x), Infinity);
144
+ }
145
+ get maxY() {
146
+ return this.reduce((a, r) => Math.max(a, r.y), -Infinity);
147
+ }
148
+ get minY() {
149
+ return this.reduce((a, r) => Math.min(a, r.y), Infinity);
150
+ }
151
+ get center() {
152
+ return this.leftTop.move(this.size.divide(2));
153
+ }
154
+ get h() {
155
+ return this.maxY - this.minY;
156
+ }
157
+ get w() {
158
+ return this.maxX - this.minX;
159
+ }
160
+ get dY() {
161
+ return this.h;
162
+ }
163
+ get dX() {
164
+ return this.w;
165
+ }
166
+ get extend() {
167
+ const { minX, minY, maxX, maxY } = this;
168
+ return new DPolygon([
169
+ new DPoint_1.DPoint(minX, minY),
170
+ new DPoint_1.DPoint(maxX, minY),
171
+ new DPoint_1.DPoint(maxX, maxY),
172
+ new DPoint_1.DPoint(minX, maxY),
173
+ new DPoint_1.DPoint(minX, minY)
174
+ ]);
175
+ }
176
+ get size() {
177
+ const { w, h } = this;
178
+ return new DPoint_1.DPoint(w, h);
179
+ }
180
+ get leftTop() {
181
+ const { minX, minY } = this;
182
+ return new DPoint_1.DPoint(minX, minY);
183
+ }
184
+ get rightBottom() {
185
+ const { maxX, maxY } = this;
186
+ return new DPoint_1.DPoint(maxX, maxY);
187
+ }
188
+ get length() {
189
+ return this.pPoints.length;
190
+ }
191
+ get fullLength() {
192
+ return this.clone().open().perimeter;
193
+ }
194
+ get perimeter() {
195
+ let p = 0;
196
+ for (const [p1, p2] of this.loopPointsGenerator()()) {
197
+ p += p1.distance(p2);
198
+ }
199
+ return p;
200
+ }
201
+ get area() {
202
+ let sum = 0;
203
+ for (const [{ x, y }, { x: a, y: b }] of this.deintersection.loopPointsGenerator()()) {
204
+ sum += x * b - y * a;
205
+ }
206
+ return Math.abs(sum / 2) - this.holes.reduce((a, hole) => a + hole.area, 0);
207
+ }
208
+ get deintersection() {
209
+ let p = this.clone().close();
210
+ const store = {};
211
+ for (let i = 0; i < p.length - 1; i++) {
212
+ const k = p.at(i).toString();
213
+ store[k] = store[k] || [];
214
+ store[k].push(i);
215
+ for (let j = i + 2; j < p.length - 1; j++) {
216
+ const firstLine = p.at(i).findLine(p.at(i + 1));
217
+ const secondLine = p.at(j).findLine(p.at(j + 1));
218
+ const intersectionPoint = firstLine.intersection(secondLine);
219
+ if (intersectionPoint &&
220
+ ![...firstLine.points, ...secondLine.points].some((t) => t.like(intersectionPoint))) {
221
+ const part = p.removePart(i, j - i).reverse();
222
+ p.insertAfter(i, ...part);
223
+ p.insertAfter(j, intersectionPoint);
224
+ p.insertAfter(i, intersectionPoint);
421
225
  }
422
226
  }
423
- try {
424
- for (var _b = __values(Object.keys(store)), _c = _b.next(); !_c.done; _c = _b.next()) {
425
- var key = _c.value;
426
- var record = store[key];
427
- if (record.length > 1) {
428
- var _loop_2 = function (j) {
429
- var origin_1 = p.clone();
430
- var d = record[j] - record[j - 1];
431
- if (d > 1) {
432
- var part = new DPolygon(origin_1.removePart(record[j - 1], d));
433
- var allInside = part.reduce(function (a, e) { return a && containCalculator(origin_1, e); }, true);
434
- if (allInside && origin_1.isClockwise === part.isClockwise) {
435
- origin_1.insertAfter.apply(origin_1, __spreadArray([record[j - 1] - 1], __read(part.reverse().points), false));
436
- p = origin_1;
437
- }
438
- }
439
- };
440
- for (var j = record.length - 1; j > 0; j--) {
441
- _loop_2(j);
227
+ }
228
+ for (const key of Object.keys(store)) {
229
+ const record = store[key];
230
+ if (record.length > 1) {
231
+ for (let j = record.length - 1; j > 0; j--) {
232
+ const origin = p.clone();
233
+ const d = record[j] - record[j - 1];
234
+ if (d > 1) {
235
+ const part = new DPolygon(origin.removePart(record[j - 1], d));
236
+ const allInside = part.reduce((a, e) => a && containCalculator(origin, e), true);
237
+ if (allInside && origin.isClockwise === part.isClockwise) {
238
+ origin.insertAfter(record[j - 1] - 1, ...part.reverse().points);
239
+ p = origin;
442
240
  }
443
241
  }
444
242
  }
445
243
  }
446
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
447
- finally {
448
- try {
449
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
244
+ }
245
+ return p;
246
+ }
247
+ get valid() {
248
+ return this.length > exports.MIN_POINTS_IN_VALID_POLYGON;
249
+ }
250
+ get first() {
251
+ return this.at(0);
252
+ }
253
+ get second() {
254
+ return this.at(1);
255
+ }
256
+ get last() {
257
+ return this.at(this.length - 1);
258
+ }
259
+ get minAreaRectangle() {
260
+ const p = this.convex;
261
+ let resultPolygon = new DPolygon();
262
+ let resultArea = Infinity;
263
+ for (const [, , l] of p.loopPointsGenerator(true)()) {
264
+ let maxWidth = 0;
265
+ let maxWidthPoint1 = null;
266
+ let maxWidthPoint2 = null;
267
+ let maxHeight = 0;
268
+ let maxHeightPoint = null;
269
+ for (const [z, , , i] of p.loopPointsGenerator()()) {
270
+ const p1 = l.findPoint(l.findPerpendicular(z));
271
+ const h = p1.distance(z);
272
+ if (h >= maxHeight) {
273
+ maxHeight = h;
274
+ maxHeightPoint = z;
450
275
  }
451
- finally { if (e_6) throw e_6.error; }
452
- }
453
- return p;
454
- },
455
- enumerable: false,
456
- configurable: true
457
- });
458
- Object.defineProperty(DPolygon.prototype, "valid", {
459
- get: function () {
460
- return this.length > exports.MIN_POINTS_IN_VALID_POLYGON;
461
- },
462
- enumerable: false,
463
- configurable: true
464
- });
465
- Object.defineProperty(DPolygon.prototype, "first", {
466
- get: function () {
467
- return this.at(0);
468
- },
469
- enumerable: false,
470
- configurable: true
471
- });
472
- Object.defineProperty(DPolygon.prototype, "second", {
473
- get: function () {
474
- return this.at(1);
475
- },
476
- enumerable: false,
477
- configurable: true
478
- });
479
- Object.defineProperty(DPolygon.prototype, "last", {
480
- get: function () {
481
- return this.at(this.length - 1);
482
- },
483
- enumerable: false,
484
- configurable: true
485
- });
486
- Object.defineProperty(DPolygon.prototype, "minAreaRectangle", {
487
- get: function () {
488
- var e_7, _a, e_8, _b;
489
- var p = this.convex;
490
- var resultPolygon = new DPolygon();
491
- var resultArea = Infinity;
492
- try {
493
- for (var _c = __values(p.loopPointsGenerator(true)()), _d = _c.next(); !_d.done; _d = _c.next()) {
494
- var _e = __read(_d.value, 3), l = _e[2];
495
- var maxWidth = 0;
496
- var maxWidthPoint1 = null;
497
- var maxWidthPoint2 = null;
498
- var maxHeight = 0;
499
- var maxHeightPoint = null;
500
- try {
501
- for (var _f = (e_8 = void 0, __values(p.loopPointsGenerator()())), _g = _f.next(); !_g.done; _g = _f.next()) {
502
- var _h = __read(_g.value, 4), z = _h[0], i = _h[3];
503
- var p1 = l.findPoint(l.findPerpendicular(z));
504
- var h = p1.distance(z);
505
- if (h >= maxHeight) {
506
- maxHeight = h;
507
- maxHeightPoint = z;
508
- }
509
- for (var j = i; j < p.length - 1; j++) {
510
- var p2 = l.findPoint(l.findPerpendicular(p.at(j)));
511
- var w = p1.distance(p2);
512
- if (w >= maxWidth) {
513
- maxWidth = w;
514
- maxWidthPoint1 = p1;
515
- maxWidthPoint2 = p2;
516
- }
517
- }
518
- }
519
- }
520
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
521
- finally {
522
- try {
523
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
524
- }
525
- finally { if (e_8) throw e_8.error; }
526
- }
527
- if (!maxWidthPoint1 || !maxWidthPoint2 || !maxHeightPoint) {
528
- continue;
529
- }
530
- var widthLine = maxWidthPoint1.findLine(maxWidthPoint2);
531
- var perpendicular1 = widthLine.findPerpendicular(maxWidthPoint1);
532
- var perpendicular2 = widthLine.findPerpendicular(maxWidthPoint2);
533
- var tempPolygon = new DPolygon([
534
- maxWidthPoint1,
535
- maxWidthPoint2,
536
- perpendicular2.findPoint(perpendicular2.findPerpendicular(maxHeightPoint)),
537
- perpendicular1.findPoint(perpendicular1.findPerpendicular(maxHeightPoint))
538
- ]).close();
539
- if (tempPolygon.area < resultArea) {
540
- resultPolygon = tempPolygon;
541
- resultArea = tempPolygon.area;
276
+ for (let j = i; j < p.length - 1; j++) {
277
+ const p2 = l.findPoint(l.findPerpendicular(p.at(j)));
278
+ const w = p1.distance(p2);
279
+ if (w >= maxWidth) {
280
+ maxWidth = w;
281
+ maxWidthPoint1 = p1;
282
+ maxWidthPoint2 = p2;
542
283
  }
543
284
  }
544
285
  }
545
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
546
- finally {
547
- try {
548
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
549
- }
550
- finally { if (e_7) throw e_7.error; }
551
- }
552
- return resultPolygon;
553
- },
554
- enumerable: false,
555
- configurable: true
556
- });
557
- Object.defineProperty(DPolygon.prototype, "convex", {
558
- get: function () {
559
- var p = this.clone().open();
560
- var isClockwise = p.isClockwise;
561
- if (!isClockwise) {
562
- p.reverse();
563
- }
564
- var l = 0;
565
- do {
566
- var p1 = p.last;
567
- var p2 = p.first;
568
- var p3 = p.second;
569
- var d = p2.findInnerAngle(p1, p3);
570
- if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
571
- p.removePart(-1, 1);
572
- }
573
- else {
574
- break;
575
- }
576
- } while (p.length);
577
- p.close();
578
- var iteration = 0;
579
- do {
580
- p = p.deintersection;
581
- l = p.length;
582
- for (var i = 1; i < p.length - 1; i++) {
583
- var p1 = p.at(i - 1);
584
- var p2 = p.at(i);
585
- var p3 = p.at(i + 1);
586
- var d = p2.findInnerAngle(p1, p3);
587
- if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
588
- p.removePart(--i, 1);
589
- }
590
- }
591
- iteration++;
592
- } while (p.length !== l && iteration < MAX_CONVEX_ITERATIONS);
593
- if (!isClockwise) {
594
- p.reverse();
286
+ if (!maxWidthPoint1 || !maxWidthPoint2 || !maxHeightPoint) {
287
+ continue;
595
288
  }
596
- return p;
597
- },
598
- enumerable: false,
599
- configurable: true
600
- });
601
- Object.defineProperty(DPolygon.prototype, "isClockwise", {
602
- get: function () {
603
- var e_9, _a;
604
- var sum = 0;
605
- try {
606
- for (var _b = __values(this.clone().close()
607
- .loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
608
- var _d = __read(_c.value, 2), _e = _d[0], x = _e.x, y = _e.y, _f = _d[1], a = _f.x, b = _f.y;
609
- sum += (a - x) * (b + y);
610
- }
289
+ const widthLine = maxWidthPoint1.findLine(maxWidthPoint2);
290
+ const perpendicular1 = widthLine.findPerpendicular(maxWidthPoint1);
291
+ const perpendicular2 = widthLine.findPerpendicular(maxWidthPoint2);
292
+ const tempPolygon = new DPolygon([
293
+ maxWidthPoint1,
294
+ maxWidthPoint2,
295
+ perpendicular2.findPoint(perpendicular2.findPerpendicular(maxHeightPoint)),
296
+ perpendicular1.findPoint(perpendicular1.findPerpendicular(maxHeightPoint))
297
+ ]).close();
298
+ if (tempPolygon.area < resultArea) {
299
+ resultPolygon = tempPolygon;
300
+ resultArea = tempPolygon.area;
611
301
  }
612
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
613
- finally {
614
- try {
615
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
616
- }
617
- finally { if (e_9) throw e_9.error; }
302
+ }
303
+ return resultPolygon;
304
+ }
305
+ get convex() {
306
+ let p = this.clone().open();
307
+ const { isClockwise } = p;
308
+ if (!isClockwise) {
309
+ p.reverse();
310
+ }
311
+ let l = 0;
312
+ do {
313
+ const p1 = p.last;
314
+ const p2 = p.first;
315
+ const p3 = p.second;
316
+ const d = p2.findInnerAngle(p1, p3);
317
+ if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
318
+ p.removePart(-1, 1);
618
319
  }
619
- return sum < 0;
620
- },
621
- enumerable: false,
622
- configurable: true
623
- });
624
- Object.defineProperty(DPolygon.prototype, "clockWise", {
625
- get: function () {
626
- if (this.isClockwise) {
627
- return this.clone();
320
+ else {
321
+ break;
628
322
  }
629
- return this.clone().reverse();
630
- },
631
- enumerable: false,
632
- configurable: true
633
- });
634
- Object.defineProperty(DPolygon.prototype, "noHoles", {
635
- get: function () {
636
- var res = this.clone();
637
- res.holes = [];
638
- return res;
639
- },
640
- enumerable: false,
641
- configurable: true
642
- });
643
- DPolygon.prototype.reduce = function (f, v) {
644
- return this.pPoints.reduce(f, v);
645
- };
646
- DPolygon.prototype.intersection = function (l, includeOnly) {
647
- var e_10, _a;
648
- if (includeOnly === void 0) { includeOnly = false; }
649
- var res = [];
650
- try {
651
- for (var _b = __values(this.loopPointsGenerator(true)()), _c = _b.next(); !_c.done; _c = _b.next()) {
652
- var _d = __read(_c.value, 3), line = _d[2];
653
- var intersect = line.intersection(l, 0, includeOnly);
654
- if (intersect) {
655
- res.push(intersect);
323
+ } while (p.length);
324
+ p.close();
325
+ let iteration = 0;
326
+ do {
327
+ p = p.deintersection;
328
+ l = p.length;
329
+ for (let i = 1; i < p.length - 1; i++) {
330
+ const p1 = p.at(i - 1);
331
+ const p2 = p.at(i);
332
+ const p3 = p.at(i + 1);
333
+ const d = p2.findInnerAngle(p1, p3);
334
+ if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
335
+ p.removePart(--i, 1);
656
336
  }
657
337
  }
338
+ iteration++;
339
+ } while (p.length !== l && iteration < MAX_CONVEX_ITERATIONS);
340
+ if (!isClockwise) {
341
+ p.reverse();
342
+ }
343
+ return p;
344
+ }
345
+ get isClockwise() {
346
+ let sum = 0;
347
+ for (const [{ x, y }, { x: a, y: b }] of this.clone().close()
348
+ .loopPointsGenerator()()) {
349
+ sum += (a - x) * (b + y);
350
+ }
351
+ return sum < 0;
352
+ }
353
+ get clockWise() {
354
+ if (this.isClockwise) {
355
+ return this.clone();
658
356
  }
659
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
660
- finally {
661
- try {
662
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
357
+ return this.clone().reverse();
358
+ }
359
+ get noHoles() {
360
+ const res = this.clone();
361
+ res.holes = [];
362
+ return res;
363
+ }
364
+ reduce(f, v) {
365
+ return this.pPoints.reduce(f, v);
366
+ }
367
+ intersection(l, includeOnly = false) {
368
+ const res = [];
369
+ for (const [, , line] of this.loopPointsGenerator(true)()) {
370
+ const intersect = line.intersection(l, 0, includeOnly);
371
+ if (intersect) {
372
+ res.push(intersect);
663
373
  }
664
- finally { if (e_10) throw e_10.error; }
665
374
  }
666
375
  return res;
667
- };
668
- DPolygon.prototype.setCenter = function (newCenter) {
376
+ }
377
+ setCenter(newCenter) {
669
378
  return this.loop()
670
379
  .move(newCenter.clone().move(this.center.minus()))
671
380
  .run();
672
- };
673
- DPolygon.prototype.toWKT = function (type, withZ) {
674
- if (type === void 0) { type = DPolygon.WKT_POLYGON; }
675
- if (withZ === void 0) { withZ = false; }
381
+ }
382
+ toWKT(type = DPolygon.WKT_POLYGON, withZ = false) {
676
383
  if (type === DPolygon.WKT_POLYGON) {
677
- var h = '';
384
+ let h = '';
678
385
  if (this.holes && this.holes.length) {
679
- h = ", " + this.holes.map(function (hole) { return hole.toString(); })
680
- .join(', ');
386
+ h = `, ${this.holes.map((hole) => hole.toString())
387
+ .join(', ')}`;
681
388
  }
682
- return "POLYGON ((" + this.deintersection.mapArray(function (r) { return r.x + " " + r.y + (withZ ? " " + r.z : ''); })
683
- .join(', ') + ")" + h + ")";
389
+ return `POLYGON ((${this.deintersection.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
390
+ .join(', ')})${h})`;
684
391
  }
685
- return "LINESTRING (" + this.mapArray(function (r) { return r.x + " " + r.y + (withZ ? " " + r.z : ''); })
686
- .join(', ') + ")";
687
- };
688
- DPolygon.prototype.filter = function (f) {
392
+ return `LINESTRING (${this.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
393
+ .join(', ')})`;
394
+ }
395
+ filter(f) {
689
396
  this.pPoints = this.pPoints.filter(f);
690
397
  return this;
691
- };
692
- DPolygon.prototype.map = function (f) {
398
+ }
399
+ map(f) {
693
400
  this.pPoints = this.mapArray(f);
694
- this.holes = this.holes.map(function (h) { return h.map(f); });
401
+ this.holes = this.holes.map((h) => h.map(f));
695
402
  return this;
696
- };
697
- DPolygon.prototype.mapArray = function (f) {
403
+ }
404
+ mapArray(f) {
698
405
  return this.pPoints.map(f);
699
- };
700
- DPolygon.prototype.sort = function (f) {
406
+ }
407
+ sort(f) {
701
408
  this.points.sort(f);
702
409
  return this;
703
- };
704
- DPolygon.prototype.at = function (index) {
705
- var length = this.length;
410
+ }
411
+ at(index) {
412
+ const { length } = this;
706
413
  return this.points[(index % length + length) % length];
707
- };
708
- DPolygon.prototype.pop = function () {
414
+ }
415
+ pop() {
709
416
  return this.pPoints.pop();
710
- };
711
- DPolygon.prototype.push = function () {
712
- var _a;
713
- var args = [];
714
- for (var _i = 0; _i < arguments.length; _i++) {
715
- args[_i] = arguments[_i];
716
- }
717
- return (_a = this.pPoints).push.apply(_a, __spreadArray([], __read(args), false));
718
- };
719
- DPolygon.prototype.shift = function () {
417
+ }
418
+ push(...args) {
419
+ return this.pPoints.push(...args);
420
+ }
421
+ shift() {
720
422
  return this.pPoints.shift();
721
- };
722
- DPolygon.prototype.unshift = function () {
723
- var _a;
724
- var args = [];
725
- for (var _i = 0; _i < arguments.length; _i++) {
726
- args[_i] = arguments[_i];
727
- }
728
- return (_a = this.pPoints).unshift.apply(_a, __spreadArray([], __read(args), false));
729
- };
730
- DPolygon.prototype.reverse = function () {
423
+ }
424
+ unshift(...args) {
425
+ return this.pPoints.unshift(...args);
426
+ }
427
+ reverse() {
731
428
  this.pPoints = this.pPoints.reverse();
732
- this.holes = this.holes.map(function (h) { return h.reverse(); });
429
+ this.holes = this.holes.map((h) => h.reverse());
733
430
  return this;
734
- };
735
- DPolygon.prototype.getValue = function () {
736
- return (this.pPoints.map(function (r) { return r.getValue(); }) + this.holes
737
- .reduce(function (a, h) { return a + h.getValue(); }, ''));
738
- };
739
- DPolygon.prototype.toString = function () {
740
- return "(" + this.mapArray(function (r) { return r.toString(); }).join(', ') + ")";
741
- };
742
- DPolygon.prototype.close = function () {
743
- var p0 = this.first;
431
+ }
432
+ getValue() {
433
+ return (this.pPoints.map((r) => r.getValue()) + this.holes
434
+ .reduce((a, h) => a + h.getValue(), ''));
435
+ }
436
+ toString() {
437
+ return `(${this.mapArray((r) => r.toString()).join(', ')})`;
438
+ }
439
+ close() {
440
+ const p0 = this.first;
744
441
  if (p0 && !this.closed) {
745
442
  this.push(p0.clone());
746
443
  }
747
444
  return this;
748
- };
749
- DPolygon.prototype.open = function () {
750
- var p = this.first;
445
+ }
446
+ open() {
447
+ const p = this.first;
751
448
  if (this.length > 2 && p && this.closed) {
752
449
  this.pop();
753
450
  }
754
451
  return this;
755
- };
756
- DPolygon.prototype.add = function (poly) {
757
- var res = new DPolygon(__spreadArray(__spreadArray([], __read(this.points), false), __read(poly.points), false)).close();
758
- res.holes = __spreadArray(__spreadArray([], __read(this.holes), false), __read(poly.holes), false).map(function (h) { return h.clone(); });
452
+ }
453
+ add(poly) {
454
+ const res = new DPolygon([...this.points, ...poly.points]).close();
455
+ res.holes = [...this.holes, ...poly.holes].map((h) => h.clone());
759
456
  return res;
760
- };
761
- DPolygon.prototype.has = function (p) {
762
- return this.pPoints.some(function (q) { return q.equal(p); });
763
- };
764
- DPolygon.prototype.clone = function () {
765
- var res = new DPolygon(this.points.map(function (r) { return r.clone(); }));
766
- res.holes = this.holes.map(function (h) { return h.clone(); });
457
+ }
458
+ has(p) {
459
+ return this.pPoints.some((q) => q.equal(p));
460
+ }
461
+ clone() {
462
+ const res = new DPolygon(this.points.map((r) => r.clone()));
463
+ res.holes = this.holes.map((h) => h.clone());
767
464
  res.properties = this.properties;
768
465
  return res;
769
- };
770
- DPolygon.prototype.equal = function (p) {
466
+ }
467
+ equal(p) {
771
468
  if (!(p instanceof DPolygon)) {
772
469
  return false;
773
470
  }
@@ -775,14 +472,14 @@ var DPolygon = (function () {
775
472
  return false;
776
473
  }
777
474
  return (this.same(p) &&
778
- this.holes.reduce(function (a, hole) { return a && p.holes.some(function (pHoles) { return pHoles.same(hole); }); }, true));
779
- };
780
- DPolygon.prototype.same = function (p) {
781
- var pClone = p.clone().close();
782
- var thisAsString = this.clone()
475
+ this.holes.reduce((a, hole) => a && p.holes.some((pHoles) => pHoles.same(hole)), true));
476
+ }
477
+ same(p) {
478
+ const pClone = p.clone().close();
479
+ const thisAsString = this.clone()
783
480
  .close()
784
481
  .toString();
785
- for (var i = 0; i < pClone.length; i++) {
482
+ for (let i = 0; i < pClone.length; i++) {
786
483
  if (thisAsString === pClone.toString() || thisAsString === pClone.clone().reverse()
787
484
  .toString()) {
788
485
  return true;
@@ -790,45 +487,37 @@ var DPolygon = (function () {
790
487
  pClone.nextStart();
791
488
  }
792
489
  return false;
793
- };
794
- DPolygon.prototype.findIndex = function (a) {
490
+ }
491
+ findIndex(a) {
795
492
  if (a instanceof DPoint_1.DPoint) {
796
- return this.points.findIndex(function (t) { return t.equal(a); });
493
+ return this.points.findIndex((t) => t.equal(a));
797
494
  }
798
495
  return this.points.findIndex(a);
799
- };
800
- DPolygon.prototype.approximation = function (e) {
801
- if (e === void 0) { e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE; }
496
+ }
497
+ approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
802
498
  return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
803
- };
804
- DPolygon.prototype.insertAfter = function (index) {
805
- var _a;
806
- var points = [];
807
- for (var _i = 1; _i < arguments.length; _i++) {
808
- points[_i - 1] = arguments[_i];
809
- }
810
- (_a = this.pPoints).splice.apply(_a, __spreadArray([index + 1, 0], __read(points), false));
811
- };
812
- DPolygon.prototype.removePart = function (index, count) {
499
+ }
500
+ insertAfter(index, ...points) {
501
+ this.pPoints.splice(index + 1, 0, ...points);
502
+ }
503
+ removePart(index, count) {
813
504
  return this.pPoints.splice(index + 1, count);
814
- };
815
- DPolygon.prototype.hasSimpleIntersection = function (p) {
816
- var extend1 = this.extend;
817
- var extend2 = p.extend;
818
- var extend1points = extend1.points;
819
- var extend2points = extend2.points;
820
- var in1 = extend1points.some(function (t) { return extend2.simpleInclude(t); });
821
- var in2 = extend2points.some(function (t) { return extend1.simpleInclude(t); });
505
+ }
506
+ hasSimpleIntersection(p) {
507
+ const extend1 = this.extend;
508
+ const extend2 = p.extend;
509
+ const extend1points = extend1.points;
510
+ const extend2points = extend2.points;
511
+ const in1 = extend1points.some((t) => extend2.simpleInclude(t));
512
+ const in2 = extend2points.some((t) => extend1.simpleInclude(t));
822
513
  return in1 || in2;
823
- };
824
- DPolygon.prototype.simpleInclude = function (p) {
514
+ }
515
+ simpleInclude(p) {
825
516
  return this.simpleIncludeX(p) && this.simpleIncludeY(p);
826
- };
827
- DPolygon.prototype.drawPolygonOnCanvas = function (canvas, fillColor, strokeColor, shadowColor, lineWidth, steps) {
828
- if (lineWidth === void 0) { lineWidth = 1; }
829
- if (steps === void 0) { steps = this.length - 1; }
517
+ }
518
+ drawPolygonOnCanvas(canvas, fillColor, strokeColor, shadowColor, lineWidth = 1, steps = this.length - 1) {
830
519
  if (this.length > 1) {
831
- var ctx = canvas.getContext('2d');
520
+ const ctx = canvas.getContext('2d');
832
521
  if (fillColor) {
833
522
  ctx.fillStyle = fillColor;
834
523
  }
@@ -857,51 +546,39 @@ var DPolygon = (function () {
857
546
  }
858
547
  }
859
548
  return this;
860
- };
861
- DPolygon.prototype.clearPolygonOnCanvas = function (canvas) {
862
- var ctx = canvas.getContext('2d');
863
- var old = ctx.globalCompositeOperation;
549
+ }
550
+ clearPolygonOnCanvas(canvas) {
551
+ const ctx = canvas.getContext('2d');
552
+ const old = ctx.globalCompositeOperation;
864
553
  ctx.globalCompositeOperation = 'destination-out';
865
554
  this.goByPath(ctx);
866
555
  ctx.fill();
867
556
  ctx.globalCompositeOperation = old;
868
- };
869
- DPolygon.prototype.contain = function (p, isBorderInside) {
870
- var e_11, _a;
871
- if (isBorderInside === void 0) { isBorderInside = false; }
872
- var simpleInclude = this.simpleInclude(p);
557
+ }
558
+ contain(p, isBorderInside = false) {
559
+ const simpleInclude = this.simpleInclude(p);
873
560
  if (!simpleInclude) {
874
561
  return false;
875
562
  }
876
- var onBorder = this.onBorder(p);
563
+ const onBorder = this.onBorder(p);
877
564
  if (onBorder) {
878
565
  return isBorderInside;
879
566
  }
880
- var poly = this.deintersection;
881
- var totalFi = 0;
882
- try {
883
- for (var _b = __values(poly.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
884
- var _d = __read(_c.value, 2), _e = _d[0], x = _e.x, y = _e.y, _f = _d[1], a = _f.x, b = _f.y;
885
- var line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
886
- var line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
887
- var fiDif = line1.findFi(line2);
888
- if (line1.vectorProduct(line2).c > 0) {
889
- totalFi += fiDif;
890
- }
891
- else {
892
- totalFi -= fiDif;
893
- }
567
+ const poly = this.deintersection;
568
+ let totalFi = 0;
569
+ for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
570
+ const line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
571
+ const line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
572
+ const fiDif = line1.findFi(line2);
573
+ if (line1.vectorProduct(line2).c > 0) {
574
+ totalFi += fiDif;
894
575
  }
895
- }
896
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
897
- finally {
898
- try {
899
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
576
+ else {
577
+ totalFi -= fiDif;
900
578
  }
901
- finally { if (e_11) throw e_11.error; }
902
579
  }
903
- var eps = Math.PI / 10000;
904
- var absTotalFi = Math.abs(totalFi);
580
+ const eps = Math.PI / 10000;
581
+ const absTotalFi = Math.abs(totalFi);
905
582
  if (absTotalFi < eps) {
906
583
  return false;
907
584
  }
@@ -909,79 +586,66 @@ var DPolygon = (function () {
909
586
  return true;
910
587
  }
911
588
  throw new Error('contains2 faild');
912
- };
913
- DPolygon.prototype.onBorder = function (p) {
914
- var e_12, _a;
915
- var simpleInclude = this.simpleInclude(p);
589
+ }
590
+ onBorder(p) {
591
+ const simpleInclude = this.simpleInclude(p);
916
592
  if (simpleInclude) {
917
- var poly = this.deintersection;
918
- var hasSamePoint = this.points.some(function (point) { return point.equal(p); });
593
+ const poly = this.deintersection;
594
+ const hasSamePoint = this.points.some((point) => point.equal(p));
919
595
  if (hasSamePoint) {
920
596
  return true;
921
597
  }
922
- try {
923
- for (var _b = __values(poly.loopPointsGenerator(true)()), _c = _b.next(); !_c.done; _c = _b.next()) {
924
- var _d = __read(_c.value, 3), polygonLine = _d[2];
925
- var onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
926
- if (onBorder) {
927
- return true;
928
- }
929
- }
930
- }
931
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
932
- finally {
933
- try {
934
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
598
+ for (const [, , polygonLine] of poly.loopPointsGenerator(true)()) {
599
+ const onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
600
+ if (onBorder) {
601
+ return true;
935
602
  }
936
- finally { if (e_12) throw e_12.error; }
937
603
  }
938
604
  }
939
605
  return false;
940
- };
941
- DPolygon.prototype.nextStart = function () {
606
+ }
607
+ nextStart() {
942
608
  this.open();
943
609
  this.push(this.shift());
944
610
  this.close();
945
611
  return this;
946
- };
947
- DPolygon.prototype.removeDuplicates = function () {
948
- for (var i = 0; i < this.length - 1; i++) {
949
- var p1 = this.at(i);
950
- var p2 = this.at(i + 1);
612
+ }
613
+ removeDuplicates() {
614
+ for (let i = 0; i < this.length - 1; i++) {
615
+ const p1 = this.at(i);
616
+ const p2 = this.at(i + 1);
951
617
  if (p1.equal(p2)) {
952
618
  this.removePart(i, 1);
953
619
  i--;
954
620
  }
955
621
  }
956
622
  return this;
957
- };
958
- DPolygon.parse = function (a) {
959
- return new DPolygon(a.map(function (r) { return DPoint_1.DPoint.parse(r); }));
960
- };
961
- DPolygon.prototype.toArrayOfCoords = function () {
962
- return this.mapArray(function (r) { return r.toCoords(); });
963
- };
964
- DPolygon.prototype.divideToPieces = function (piecesCount, withAltitude) {
965
- var e_13, _a;
966
- if (withAltitude === void 0) { withAltitude = false; }
967
- var fullLength = this.fullLength;
968
- var pieceLength = fullLength / piecesCount;
969
- var currentPieceLength = pieceLength;
970
- var _loop_3 = function (p1, p2, i) {
971
- var d = p1.distance(p2);
623
+ }
624
+ static parse(a) {
625
+ return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
626
+ }
627
+ toArrayOfCoords() {
628
+ return this.mapArray((r) => r.toCoords());
629
+ }
630
+ divideToPieces(piecesCount, withAltitude = false) {
631
+ const { fullLength } = this;
632
+ const pieceLength = fullLength / piecesCount;
633
+ let currentPieceLength = pieceLength;
634
+ for (const [p1, p2, , i] of this.loopPointsGenerator()()) {
635
+ const d = p1.distance(p2);
972
636
  if (d === currentPieceLength) {
973
637
  p2.properties.pieceBorder = true;
974
638
  currentPieceLength = pieceLength;
975
639
  }
976
640
  else if (d - currentPieceLength > 0) {
977
- var circle = new DCircle_1.DCircle(p1, currentPieceLength);
978
- var line_1 = p1.findLine(p2);
979
- var intersectionPoint = line_1.intersectionWithCircle(circle)
980
- .filter(function (p) { return line_1.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE); })[0];
641
+ const circle = new DCircle_1.DCircle(p1, currentPieceLength);
642
+ const line = p1.findLine(p2);
643
+ const intersectionPoint = line.intersectionWithCircle(circle)
644
+ .filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
981
645
  intersectionPoint.properties.pieceBorder = true;
982
- this_1.insertAfter(i, intersectionPoint);
646
+ this.insertAfter(i, intersectionPoint);
983
647
  if (withAltitude) {
984
- var p1z = p1.z;
648
+ const p1z = p1.z;
985
649
  intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
986
650
  }
987
651
  currentPieceLength = pieceLength;
@@ -989,48 +653,22 @@ var DPolygon = (function () {
989
653
  else {
990
654
  currentPieceLength -= d;
991
655
  }
992
- };
993
- var this_1 = this;
994
- try {
995
- for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
996
- var _d = __read(_c.value, 4), p1 = _d[0], p2 = _d[1], i = _d[3];
997
- _loop_3(p1, p2, i);
998
- }
999
- }
1000
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
1001
- finally {
1002
- try {
1003
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1004
- }
1005
- finally { if (e_13) throw e_13.error; }
1006
656
  }
1007
657
  return this;
1008
- };
1009
- DPolygon.prototype.prepareToFastSearch = function () {
1010
- var e_14, _a;
658
+ }
659
+ prepareToFastSearch() {
1011
660
  this.searchStore = {};
1012
- try {
1013
- for (var _b = __values(this.points), _c = _b.next(); !_c.done; _c = _b.next()) {
1014
- var _d = _c.value, x = _d.x, y = _d.y, z = _d.z;
1015
- if (!this.searchStore[x]) {
1016
- this.searchStore[x] = {};
1017
- }
1018
- if (!this.searchStore[x][y]) {
1019
- this.searchStore[x][y] = {};
1020
- }
1021
- this.searchStore[x][y][z || 'undefined'] = true;
661
+ for (const { x, y, z } of this.points) {
662
+ if (!this.searchStore[x]) {
663
+ this.searchStore[x] = {};
1022
664
  }
1023
- }
1024
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1025
- finally {
1026
- try {
1027
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
665
+ if (!this.searchStore[x][y]) {
666
+ this.searchStore[x][y] = {};
1028
667
  }
1029
- finally { if (e_14) throw e_14.error; }
668
+ this.searchStore[x][y][z || 'undefined'] = true;
1030
669
  }
1031
- };
1032
- DPolygon.prototype.fastHas = function (_a) {
1033
- var x = _a.x, y = _a.y, z = _a.z;
670
+ }
671
+ fastHas({ x, y, z }) {
1034
672
  if (!this.searchStore[x]) {
1035
673
  return false;
1036
674
  }
@@ -1041,56 +679,23 @@ var DPolygon = (function () {
1041
679
  return false;
1042
680
  }
1043
681
  return this.searchStore[x][y][z || 'undefined'];
1044
- };
1045
- Object.defineProperty(DPolygon.prototype, "growingPiecesGenerator", {
1046
- get: function () {
1047
- var polygon = this;
1048
- return function () {
1049
- var r, _a, _b, p, e_15_1;
1050
- var e_15, _c;
1051
- return __generator(this, function (_d) {
1052
- switch (_d.label) {
1053
- case 0:
1054
- r = new DPolygon();
1055
- _d.label = 1;
1056
- case 1:
1057
- _d.trys.push([1, 6, 7, 8]);
1058
- _a = __values(polygon.pPoints), _b = _a.next();
1059
- _d.label = 2;
1060
- case 2:
1061
- if (!!_b.done) return [3, 5];
1062
- p = _b.value;
1063
- r.push(p);
1064
- if (!p.properties.pieceBorder) return [3, 4];
1065
- return [4, r.clone()];
1066
- case 3:
1067
- _d.sent();
1068
- _d.label = 4;
1069
- case 4:
1070
- _b = _a.next();
1071
- return [3, 2];
1072
- case 5: return [3, 8];
1073
- case 6:
1074
- e_15_1 = _d.sent();
1075
- e_15 = { error: e_15_1 };
1076
- return [3, 8];
1077
- case 7:
1078
- try {
1079
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1080
- }
1081
- finally { if (e_15) throw e_15.error; }
1082
- return [7];
1083
- case 8: return [2, r.clone()];
1084
- }
1085
- });
1086
- };
1087
- },
1088
- enumerable: false,
1089
- configurable: true
1090
- });
1091
- DPolygon.prototype.simpleUnion = function (p) {
682
+ }
683
+ get growingPiecesGenerator() {
684
+ const polygon = this;
685
+ return function* () {
686
+ const r = new DPolygon();
687
+ for (const p of polygon.pPoints) {
688
+ r.push(p);
689
+ if (p.properties.pieceBorder) {
690
+ yield r.clone();
691
+ }
692
+ }
693
+ return r.clone();
694
+ };
695
+ }
696
+ simpleUnion(p) {
1092
697
  try {
1093
- var res = this.simpleLogicFunction(p, true, true);
698
+ const res = this.simpleLogicFunction(p, true, true);
1094
699
  if (res === null) {
1095
700
  return null;
1096
701
  }
@@ -1102,77 +707,49 @@ var DPolygon = (function () {
1102
707
  catch (ex) {
1103
708
  return null;
1104
709
  }
1105
- };
1106
- DPolygon.prototype.simpleIntersection = function (p) {
710
+ }
711
+ simpleIntersection(p) {
1107
712
  return this.simpleLogicFunction(p, false, false);
1108
- };
1109
- DPolygon.prototype.simpleDifference = function (p) {
713
+ }
714
+ simpleDifference(p) {
1110
715
  return this.simpleLogicFunction(p, true, false);
1111
- };
1112
- DPolygon.prototype.smartUnion = function (p) {
1113
- var e_16, _a;
1114
- var res = this.clone().simpleUnion(p);
716
+ }
717
+ smartUnion(p) {
718
+ const res = this.clone().simpleUnion(p);
1115
719
  if (res) {
1116
- var allHoles = __spreadArray(__spreadArray(__spreadArray([], __read(this.holes), false), __read(p.holes), false), __read(res.holes), false).map(function (h) { return h.clone(); });
1117
- var _loop_4 = function (a) {
1118
- var e_17, _b;
1119
- var _loop_5 = function (b) {
720
+ let allHoles = [...this.holes, ...p.holes, ...res.holes].map((h) => h.clone());
721
+ for (const a of allHoles) {
722
+ for (const b of allHoles) {
1120
723
  if (a.equal(b)) {
1121
- return "continue";
724
+ continue;
1122
725
  }
1123
- var r = a.simpleUnion(b);
726
+ const r = a.simpleUnion(b);
1124
727
  if (r) {
1125
- allHoles = allHoles.filter(function (v) { return !v.equal(a) && !v.equal(b); });
728
+ allHoles = allHoles.filter((v) => !v.equal(a) && !v.equal(b));
1126
729
  allHoles.push(r);
1127
730
  }
1128
- };
1129
- try {
1130
- for (var allHoles_2 = (e_17 = void 0, __values(allHoles)), allHoles_2_1 = allHoles_2.next(); !allHoles_2_1.done; allHoles_2_1 = allHoles_2.next()) {
1131
- var b = allHoles_2_1.value;
1132
- _loop_5(b);
1133
- }
1134
- }
1135
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1136
- finally {
1137
- try {
1138
- if (allHoles_2_1 && !allHoles_2_1.done && (_b = allHoles_2.return)) _b.call(allHoles_2);
1139
- }
1140
- finally { if (e_17) throw e_17.error; }
1141
- }
1142
- };
1143
- try {
1144
- for (var allHoles_1 = __values(allHoles), allHoles_1_1 = allHoles_1.next(); !allHoles_1_1.done; allHoles_1_1 = allHoles_1.next()) {
1145
- var a = allHoles_1_1.value;
1146
- _loop_4(a);
1147
731
  }
1148
732
  }
1149
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
1150
- finally {
1151
- try {
1152
- if (allHoles_1_1 && !allHoles_1_1.done && (_a = allHoles_1.return)) _a.call(allHoles_1);
1153
- }
1154
- finally { if (e_16) throw e_16.error; }
1155
- }
1156
733
  res.holes = allHoles;
1157
734
  }
1158
735
  return res;
1159
- };
1160
- DPolygon.prototype.toTriangles = function () {
1161
- var innerAndNotIntersect = function (poly, p1, p2) {
1162
- var l = p1.findLine(p2);
1163
- var center = l.center;
1164
- var intersections = poly.holes.reduce(function (a, hole) { return a && Boolean(hole.clone().close()
1165
- .intersection(l, true).length); }, Boolean(poly.clone().close()
736
+ }
737
+ toTriangles() {
738
+ const innerAndNotIntersect = (poly, p1, p2) => {
739
+ const l = p1.findLine(p2);
740
+ const { center } = l;
741
+ const intersections = poly.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
742
+ .intersection(l, true).length), Boolean(poly.clone().close()
1166
743
  .intersection(l, true).length));
1167
- var contain = poly.holes.reduce(function (a, hole) { return a && !hole
1168
- .contain(center); }, poly.contain(center));
744
+ const contain = poly.holes.reduce((a, hole) => a && !hole
745
+ .contain(center), poly.contain(center));
1169
746
  return !intersections && contain;
1170
747
  };
1171
- var getTriangle = function (poly) {
1172
- for (var i = 0; i < poly.length; i++) {
1173
- var p0 = poly.at(0);
1174
- var p1 = poly.at(1);
1175
- var p2 = poly.at(2);
748
+ const getTriangle = (poly) => {
749
+ for (let i = 0; i < poly.length; i++) {
750
+ const p0 = poly.at(0);
751
+ const p1 = poly.at(1);
752
+ const p2 = poly.at(2);
1176
753
  if (innerAndNotIntersect(poly, p0, p2)) {
1177
754
  poly.removePart(0, 1);
1178
755
  return new DPolygon([
@@ -1185,47 +762,47 @@ var DPolygon = (function () {
1185
762
  }
1186
763
  return undefined;
1187
764
  };
1188
- var p = this.clone().clockWise.open();
765
+ const p = this.clone().clockWise.open();
1189
766
  while (p.holes.length) {
1190
- var h = p.holes.shift()
767
+ const h = p.holes.shift()
1191
768
  .clone()
1192
769
  .clockWise
1193
770
  .reverse()
1194
771
  .close();
1195
- for (var i = 0; i < p.length; i++) {
772
+ for (let i = 0; i < p.length; i++) {
1196
773
  if (innerAndNotIntersect(p, p.first, h.first)) {
1197
- p.insertAfter.apply(p, __spreadArray(__spreadArray([0], __read(h.points), false), [p.first], false));
774
+ p.insertAfter(0, ...h.points, p.first);
1198
775
  break;
1199
776
  }
1200
777
  p.push(p.shift());
1201
778
  }
1202
779
  }
1203
- var res = [];
780
+ const res = [];
1204
781
  while (p.length > 3) {
1205
- var triangle = getTriangle(p);
782
+ const triangle = getTriangle(p);
1206
783
  if (triangle) {
1207
784
  res.push(triangle);
1208
785
  }
1209
786
  }
1210
787
  res.push(p);
1211
788
  return res;
1212
- };
1213
- DPolygon.prototype.getTrianglesPointIndexes = function () {
1214
- var innerAndNotIntersect = function (poly, p1, p2) {
1215
- var l = p1.findLine(p2);
1216
- var center = l.center;
1217
- var intersections = poly.holes.reduce(function (a, hole) { return a && Boolean(hole.clone().close()
1218
- .intersection(l, true).length); }, Boolean(poly.clone().close()
789
+ }
790
+ getTrianglesPointIndexes() {
791
+ const innerAndNotIntersect = (poly, p1, p2) => {
792
+ const l = p1.findLine(p2);
793
+ const { center } = l;
794
+ const intersections = poly.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
795
+ .intersection(l, true).length), Boolean(poly.clone().close()
1219
796
  .intersection(l, true).length));
1220
- var contain = poly.holes.reduce(function (a, hole) { return a && !hole
1221
- .contain(center); }, poly.contain(center));
797
+ const contain = poly.holes.reduce((a, hole) => a && !hole
798
+ .contain(center), poly.contain(center));
1222
799
  return !intersections && contain;
1223
800
  };
1224
- var getTriangle = function (poly) {
1225
- for (var i = 0; i < poly.length; i++) {
1226
- var p0 = poly.at(0);
1227
- var p1 = poly.at(1);
1228
- var p2 = poly.at(2);
801
+ const getTriangle = (poly) => {
802
+ for (let i = 0; i < poly.length; i++) {
803
+ const p0 = poly.at(0);
804
+ const p1 = poly.at(1);
805
+ const p2 = poly.at(2);
1229
806
  if (innerAndNotIntersect(poly, p0, p2)) {
1230
807
  poly.removePart(0, 1);
1231
808
  return [
@@ -1238,186 +815,147 @@ var DPolygon = (function () {
1238
815
  }
1239
816
  return undefined;
1240
817
  };
1241
- var p = this.clone();
1242
- var index = 0;
1243
- p.points.forEach(function (f) {
818
+ let p = this.clone();
819
+ let index = 0;
820
+ p.points.forEach((f) => {
1244
821
  f.properties.index = index++;
1245
822
  });
1246
- p.holes.forEach(function (h) {
1247
- h.pPoints.forEach(function (f) {
823
+ p.holes.forEach((h) => {
824
+ h.pPoints.forEach((f) => {
1248
825
  f.properties.index = index++;
1249
826
  });
1250
827
  });
1251
828
  p = p.clockWise.open();
1252
829
  while (p.holes.length) {
1253
- var h = p.holes.shift()
830
+ const h = p.holes.shift()
1254
831
  .clone()
1255
832
  .clockWise
1256
833
  .reverse()
1257
834
  .close();
1258
- for (var i = 0; i < p.length; i++) {
835
+ for (let i = 0; i < p.length; i++) {
1259
836
  if (innerAndNotIntersect(p, p.first, h.first)) {
1260
- p.insertAfter.apply(p, __spreadArray(__spreadArray([0], __read(h.points), false), [p.first], false));
837
+ p.insertAfter(0, ...h.points, p.first);
1261
838
  break;
1262
839
  }
1263
840
  p.push(p.shift());
1264
841
  }
1265
842
  }
1266
- var res = [];
843
+ const res = [];
1267
844
  while (p.length > 3) {
1268
- var triangle = getTriangle(p);
845
+ const triangle = getTriangle(p);
1269
846
  if (triangle) {
1270
- res.push.apply(res, __spreadArray([], __read(triangle), false));
847
+ res.push(...triangle);
1271
848
  }
1272
849
  }
1273
- res.push.apply(res, __spreadArray([], __read(p.points.map(function (f) { return f.properties.index; })), false));
850
+ res.push(...p.points.map((f) => f.properties.index));
1274
851
  return res;
1275
- };
1276
- Object.defineProperty(DPolygon.prototype, "closed", {
1277
- get: function () {
1278
- return this.first.equal(this.last);
1279
- },
1280
- enumerable: false,
1281
- configurable: true
1282
- });
1283
- DPolygon.prototype.buffer = function (v, quadrantSegments, type) {
1284
- if (quadrantSegments === void 0) { quadrantSegments = 64; }
1285
- if (type === void 0) { type = DPolygon.CAP_ROUND; }
1286
- var reader = new jsts_1.io.WKTReader();
1287
- var _a = this, noHoles = _a.noHoles, closed = _a.closed;
1288
- var points = reader
852
+ }
853
+ get closed() {
854
+ return this.first.equal(this.last);
855
+ }
856
+ buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
857
+ const reader = new jsts_1.io.WKTReader();
858
+ const { noHoles, closed } = this;
859
+ const points = reader
1289
860
  .read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
1290
861
  .buffer(v, quadrantSegments, type)
1291
862
  .getCoordinates();
1292
- return new DPolygon(points.map(function (_a) {
1293
- var x = _a.x, y = _a.y;
1294
- return new DPoint_1.DPoint(x, y);
1295
- }));
1296
- };
1297
- DPolygon.prototype.sideBuffers = function (v, quadrantSegments) {
1298
- if (quadrantSegments === void 0) { quadrantSegments = 64; }
1299
- var _a = this, first = _a.first, last = _a.last;
1300
- var buffer = this.buffer(v, quadrantSegments, DPolygon.CAP_FLAT).open();
1301
- var _b = __read(first.sortByDistance(buffer).points.map(function (r) { return r.properties.index; }), 2), start0 = _b[0], start1 = _b[1];
1302
- var _c = __read(last.sortByDistance(buffer).points.map(function (r) { return r.properties.index; }), 2), end0 = _c[0], end1 = _c[1];
1303
- var fromPoint = Math.min(Math.max(start0, start1), Math.max(end0, end1));
1304
- var toPoint = Math.max(Math.min(start0, start1), Math.min(end0, end1));
1305
- var linePart = new DPolygon(buffer.removePart(fromPoint - 1, toPoint - fromPoint + 1));
863
+ return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
864
+ }
865
+ sideBuffers(v, quadrantSegments = 64) {
866
+ const { first, last } = this;
867
+ const buffer = this.buffer(v, quadrantSegments, DPolygon.CAP_FLAT).open();
868
+ const [start0, start1] = first.sortByDistance(buffer).points.map((r) => r.properties.index);
869
+ const [end0, end1] = last.sortByDistance(buffer).points.map((r) => r.properties.index);
870
+ const fromPoint = Math.min(Math.max(start0, start1), Math.max(end0, end1));
871
+ const toPoint = Math.max(Math.min(start0, start1), Math.min(end0, end1));
872
+ const linePart = new DPolygon(buffer.removePart(fromPoint - 1, toPoint - fromPoint + 1));
1306
873
  buffer.unshift(buffer.pop());
1307
874
  return [linePart.reverse(), buffer];
1308
- };
1309
- DPolygon.prototype.bezier = function (step) {
1310
- if (step === void 0) { step = 0.1; }
1311
- var res = new DPolygon();
1312
- for (var i = 0; i < 1; i += step) {
875
+ }
876
+ bezier(step = 0.1) {
877
+ const res = new DPolygon();
878
+ for (let i = 0; i < 1; i += step) {
1313
879
  res.push(this.clone().getBezierPoint(i));
1314
880
  }
1315
881
  return res;
1316
- };
1317
- DPolygon.prototype.setGrowingHeight = function (from, to) {
1318
- var fullLength = this.fullLength;
1319
- var prevPoint = this.first;
1320
- var d = to - from;
1321
- var currentDistance = 0;
882
+ }
883
+ setGrowingHeight(from, to) {
884
+ const { fullLength } = this;
885
+ let { first: prevPoint } = this;
886
+ const d = to - from;
887
+ let currentDistance = 0;
1322
888
  this.loop()
1323
- .setZ(function (p) {
889
+ .setZ((p) => {
1324
890
  currentDistance += prevPoint.distance(p);
1325
891
  prevPoint = p;
1326
892
  return from + currentDistance / fullLength * d;
1327
893
  })
1328
894
  .run();
1329
895
  return this;
1330
- };
1331
- DPolygon.prototype.loopPointsGenerator = function (withLine) {
1332
- if (withLine === void 0) { withLine = false; }
1333
- var that = this;
1334
- return function () {
1335
- var i, p1, p2;
1336
- return __generator(this, function (_a) {
1337
- switch (_a.label) {
1338
- case 0:
1339
- i = 0;
1340
- _a.label = 1;
1341
- case 1:
1342
- if (!(i < that.length - 1)) return [3, 4];
1343
- p1 = that.at(i);
1344
- p2 = that.at(i + 1);
1345
- return [4, [p1, p2, withLine ? p1.findLine(p2) : undefined, i]];
1346
- case 2:
1347
- _a.sent();
1348
- _a.label = 3;
1349
- case 3:
1350
- i++;
1351
- return [3, 1];
1352
- case 4: return [2];
1353
- }
1354
- });
896
+ }
897
+ loopPointsGenerator(withLine = false) {
898
+ const that = this;
899
+ return function* () {
900
+ for (let i = 0; i < that.length - 1; i++) {
901
+ const p1 = that.at(i);
902
+ const p2 = that.at(i + 1);
903
+ yield [p1, p2, withLine ? p1.findLine(p2) : undefined, i];
904
+ }
1355
905
  };
1356
- };
1357
- DPolygon.prototype.getBezierPoint = function (v) {
1358
- var e_18, _a;
906
+ }
907
+ getBezierPoint(v) {
1359
908
  if (this.length === 1) {
1360
909
  return this.first;
1361
910
  }
1362
- try {
1363
- for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
1364
- var _d = __read(_c.value, 2), p1 = _d[0], p2 = _d[1];
1365
- p1.move(p2.clone().move(p1.clone().minus())
1366
- .scale(v));
1367
- }
1368
- }
1369
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1370
- finally {
1371
- try {
1372
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1373
- }
1374
- finally { if (e_18) throw e_18.error; }
911
+ for (const [p1, p2] of this.loopPointsGenerator()()) {
912
+ p1.move(p2.clone().move(p1.clone().minus())
913
+ .scale(v));
1375
914
  }
1376
915
  this.pop();
1377
916
  return this.getBezierPoint(v);
1378
- };
1379
- DPolygon.prototype.simpleIncludeX = function (p) {
1380
- var x = p.x;
917
+ }
918
+ simpleIncludeX(p) {
919
+ const { x } = p;
1381
920
  return this.minX <= x && this.maxX >= x;
1382
- };
1383
- DPolygon.prototype.simpleIncludeY = function (p) {
1384
- var y = p.y;
921
+ }
922
+ simpleIncludeY(p) {
923
+ const { y } = p;
1385
924
  return this.minY <= y && this.maxY >= y;
1386
- };
1387
- DPolygon.prototype.douglasPeucker = function (points, e) {
1388
- var dMax = 0;
1389
- var index = 0;
1390
- var end = points.length - 1;
1391
- var line = points[0].findLine(points[end]);
1392
- for (var i = 1; i < end; i++) {
1393
- var d = line.perpendicularDistance(points[i]);
925
+ }
926
+ douglasPeucker(points, e) {
927
+ let dMax = 0;
928
+ let index = 0;
929
+ const end = points.length - 1;
930
+ const line = points[0].findLine(points[end]);
931
+ for (let i = 1; i < end; i++) {
932
+ const d = line.perpendicularDistance(points[i]);
1394
933
  if (d > dMax) {
1395
934
  index = i;
1396
935
  dMax = d;
1397
936
  }
1398
937
  }
1399
938
  if (dMax >= e) {
1400
- var recResult1 = this.douglasPeucker(points.slice(0, index + 1), e);
1401
- var recResult2 = this.douglasPeucker(points.slice(index), e);
939
+ const recResult1 = this.douglasPeucker(points.slice(0, index + 1), e);
940
+ const recResult2 = this.douglasPeucker(points.slice(index), e);
1402
941
  recResult1.pop();
1403
- return __spreadArray(__spreadArray([], __read(recResult1), false), __read(recResult2), false);
942
+ return [...recResult1, ...recResult2];
1404
943
  }
1405
944
  return [points[0], points[end]];
1406
- };
1407
- DPolygon.prototype.goByPath = function (ctx, steps) {
1408
- if (steps === void 0) { steps = this.length - 1; }
1409
- var start = this.first;
945
+ }
946
+ goByPath(ctx, steps = this.length - 1) {
947
+ const start = this.first;
1410
948
  ctx.moveTo(start.x, start.y);
1411
- for (var i = 1; i <= (steps % this.length); i++) {
1412
- var _a = this.at(i), x = _a.x, y = _a.y;
949
+ for (let i = 1; i <= (steps % this.length); i++) {
950
+ const { x, y } = this.at(i);
1413
951
  ctx.lineTo(x, y);
1414
952
  }
1415
- };
1416
- DPolygon.prototype.getJSTSGeometry = function (p, unionThis, unionThat) {
1417
- var unionOrIntersection = unionThat === unionThis;
1418
- var reader = new jsts_1.io.WKTReader();
1419
- var a = reader.read(this.noHoles.toWKT());
1420
- var b = reader.read(p.noHoles.toWKT());
953
+ }
954
+ getJSTSGeometry(p, unionThis, unionThat) {
955
+ const unionOrIntersection = unionThat === unionThis;
956
+ const reader = new jsts_1.io.WKTReader();
957
+ const a = reader.read(this.noHoles.toWKT());
958
+ const b = reader.read(p.noHoles.toWKT());
1421
959
  if (!unionOrIntersection) {
1422
960
  return a.difference(b);
1423
961
  }
@@ -1428,21 +966,19 @@ var DPolygon = (function () {
1428
966
  return a.intersection(b);
1429
967
  }
1430
968
  return undefined;
1431
- };
1432
- DPolygon.prototype.simpleLogicFunction = function (p, unionThis, unionThat) {
1433
- var e_19, _a, e_20, _b, e_21, _c, e_22, _d;
1434
- var c = this.getJSTSGeometry(p, unionThis, unionThat);
969
+ }
970
+ simpleLogicFunction(p, unionThis, unionThat) {
971
+ const c = this.getJSTSGeometry(p, unionThis, unionThat);
1435
972
  if (c) {
1436
- var coordinates_1 = c.getCoordinates();
1437
- if (coordinates_1.length) {
1438
- var result = coordinates_1.reduce(function (ak, _a, index) {
1439
- var x = _a.x, y = _a.y;
1440
- var lastIndex = ak.length - 1;
1441
- var t = new DPoint_1.DPoint(x, y);
1442
- var first = ak[lastIndex].first;
973
+ const coordinates = c.getCoordinates();
974
+ if (coordinates.length) {
975
+ let result = coordinates.reduce((ak, { x, y }, index) => {
976
+ const lastIndex = ak.length - 1;
977
+ const t = new DPoint_1.DPoint(x, y);
978
+ const { first } = ak[lastIndex];
1443
979
  if (t.equal(first)) {
1444
- if (coordinates_1[index + 1]) {
1445
- var nextPoint = new DPoint_1.DPoint(coordinates_1[index + 1].x, coordinates_1[index + 1].y);
980
+ if (coordinates[index + 1]) {
981
+ const nextPoint = new DPoint_1.DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
1446
982
  if (ak[lastIndex].length > 1) {
1447
983
  ak.push(new DPolygon([nextPoint]));
1448
984
  }
@@ -1452,92 +988,41 @@ var DPolygon = (function () {
1452
988
  ak[lastIndex].push(t);
1453
989
  }
1454
990
  return ak;
1455
- }, [new DPolygon([new DPoint_1.DPoint(coordinates_1[0].x, coordinates_1[0].y)])]);
991
+ }, [new DPolygon([new DPoint_1.DPoint(coordinates[0].x, coordinates[0].y)])]);
1456
992
  if (unionThat && unionThis && result.length > 1) {
1457
- try {
1458
- for (var result_1 = __values(result), result_1_1 = result_1.next(); !result_1_1.done; result_1_1 = result_1.next()) {
1459
- var q = result_1_1.value;
1460
- var _loop_6 = function (r) {
1461
- var _e;
1462
- if (q.has(r.first) && !q.equal(r)) {
1463
- var index = q.findIndex(r.first);
1464
- (_e = q.points).splice.apply(_e, __spreadArray([index, 0], __read(r.points), false));
1465
- result = result.filter(function (h) { return !h.equal(r); });
1466
- return "continue";
1467
- }
1468
- if (result.length < 2) {
1469
- return "break";
1470
- }
1471
- };
1472
- try {
1473
- for (var result_2 = (e_20 = void 0, __values(result)), result_2_1 = result_2.next(); !result_2_1.done; result_2_1 = result_2.next()) {
1474
- var r = result_2_1.value;
1475
- var state_1 = _loop_6(r);
1476
- if (state_1 === "break")
1477
- break;
1478
- }
1479
- }
1480
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1481
- finally {
1482
- try {
1483
- if (result_2_1 && !result_2_1.done && (_b = result_2.return)) _b.call(result_2);
1484
- }
1485
- finally { if (e_20) throw e_20.error; }
993
+ for (const q of result) {
994
+ for (const r of result) {
995
+ if (q.has(r.first) && !q.equal(r)) {
996
+ const index = q.findIndex(r.first);
997
+ q.points.splice(index, 0, ...r.points);
998
+ result = result.filter((h) => !h.equal(r));
999
+ continue;
1486
1000
  }
1487
1001
  if (result.length < 2) {
1488
1002
  break;
1489
1003
  }
1490
1004
  }
1491
- }
1492
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1493
- finally {
1494
- try {
1495
- if (result_1_1 && !result_1_1.done && (_a = result_1.return)) _a.call(result_1);
1005
+ if (result.length < 2) {
1006
+ break;
1496
1007
  }
1497
- finally { if (e_19) throw e_19.error; }
1498
1008
  }
1499
1009
  }
1500
- result = result.filter(function (h) { return h.length > 2; }).map(function (h) { return h.close(); });
1501
- try {
1502
- for (var result_3 = __values(result), result_3_1 = result_3.next(); !result_3_1.done; result_3_1 = result_3.next()) {
1503
- var q = result_3_1.value;
1504
- var _loop_7 = function (r) {
1505
- if (result.length < 2) {
1506
- return "break";
1507
- }
1508
- if (!q.equal(r)) {
1509
- if (q.contain(r.first, true)) {
1510
- q.holes.push(r);
1511
- result = result.filter(function (h) { return !h.equal(r); });
1512
- }
1513
- }
1514
- };
1515
- try {
1516
- for (var result_4 = (e_22 = void 0, __values(result)), result_4_1 = result_4.next(); !result_4_1.done; result_4_1 = result_4.next()) {
1517
- var r = result_4_1.value;
1518
- var state_2 = _loop_7(r);
1519
- if (state_2 === "break")
1520
- break;
1521
- }
1522
- }
1523
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
1524
- finally {
1525
- try {
1526
- if (result_4_1 && !result_4_1.done && (_d = result_4.return)) _d.call(result_4);
1527
- }
1528
- finally { if (e_22) throw e_22.error; }
1529
- }
1010
+ result = result.filter((h) => h.length > 2).map((h) => h.close());
1011
+ for (const q of result) {
1012
+ for (const r of result) {
1530
1013
  if (result.length < 2) {
1531
1014
  break;
1532
1015
  }
1016
+ if (!q.equal(r)) {
1017
+ if (q.contain(r.first, true)) {
1018
+ q.holes.push(r);
1019
+ result = result.filter((h) => !h.equal(r));
1020
+ }
1021
+ }
1533
1022
  }
1534
- }
1535
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1536
- finally {
1537
- try {
1538
- if (result_3_1 && !result_3_1.done && (_c = result_3.return)) _c.call(result_3);
1023
+ if (result.length < 2) {
1024
+ break;
1539
1025
  }
1540
- finally { if (e_21) throw e_21.error; }
1541
1026
  }
1542
1027
  if (result.length === 0) {
1543
1028
  return null;
@@ -1545,16 +1030,15 @@ var DPolygon = (function () {
1545
1030
  if (result.length === 1) {
1546
1031
  return result[0].close();
1547
1032
  }
1548
- return result.map(function (g) { return g.close(); });
1033
+ return result.map((g) => g.close());
1549
1034
  }
1550
1035
  }
1551
1036
  return null;
1552
- };
1553
- DPolygon.CAP_ROUND = CAP_ROUND;
1554
- DPolygon.CAP_FLAT = CAP_FLAT;
1555
- DPolygon.CAP_SQUARE = CAP_SQUARE;
1556
- DPolygon.WKT_LINESTRING = 'LINESTRING';
1557
- DPolygon.WKT_POLYGON = 'POLYGON';
1558
- return DPolygon;
1559
- }());
1037
+ }
1038
+ }
1560
1039
  exports.DPolygon = DPolygon;
1040
+ DPolygon.CAP_ROUND = CAP_ROUND;
1041
+ DPolygon.CAP_FLAT = CAP_FLAT;
1042
+ DPolygon.CAP_SQUARE = CAP_SQUARE;
1043
+ DPolygon.WKT_LINESTRING = 'LINESTRING';
1044
+ DPolygon.WKT_POLYGON = 'POLYGON';