dgeoutils 2.4.1 → 2.4.4

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,44 +1,128 @@
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
+ };
2
65
  Object.defineProperty(exports, "__esModule", { value: true });
3
66
  exports.DPolygon = exports.MIN_POINTS_IN_VALID_POLYGON = void 0;
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;
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;
12
75
  exports.MIN_POINTS_IN_VALID_POLYGON = 3;
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));
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); });
18
82
  if (hasSamePoint) {
19
83
  return true;
20
84
  }
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;
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
+ }
25
92
  }
26
93
  }
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;
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
+ }
34
114
  }
35
- else {
36
- totalFi -= fiDif;
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);
37
120
  }
121
+ finally { if (e_2) throw e_2.error; }
38
122
  }
39
- const eps = Math.PI / 10000;
40
- let result = false;
41
- const absTotalFi = Math.abs(totalFi);
123
+ var eps = Math.PI / 10000;
124
+ var result = false;
125
+ var absTotalFi = Math.abs(totalFi);
42
126
  if (absTotalFi < eps) {
43
127
  result = false;
44
128
  }
@@ -50,46 +134,58 @@ const containCalculator = (poly, p) => {
50
134
  }
51
135
  return result;
52
136
  };
53
- class DPolygon {
54
- constructor(pPoints = []) {
137
+ var DPolygon = (function () {
138
+ function DPolygon(pPoints) {
139
+ if (pPoints === void 0) { pPoints = []; }
55
140
  this.pPoints = pPoints;
56
141
  this.properties = {};
57
142
  this.holes = [];
58
143
  this.searchStore = {};
59
144
  }
60
- static arrayOfTrianglesToVertices(triangles, height) {
61
- return triangles.map((v) => ((0, utils_1.isDefAndNotNull)(height) ? v
145
+ DPolygon.arrayOfTrianglesToVertices = function (triangles, height) {
146
+ return triangles.map(function (v) { return ((0, utils_1.isDefAndNotNull)(height) ? v
62
147
  .loop()
63
148
  .height(height)
64
149
  .run() : v)
65
- .toArrayOfCoords())
150
+ .toArrayOfCoords(); })
66
151
  .flat(2);
67
- }
68
- static minAreaRectangleSize(poly) {
69
- const { first, second, last } = poly.clone().open();
152
+ };
153
+ DPolygon.minAreaRectangleSize = function (poly) {
154
+ var _a = poly.clone().open(), first = _a.first, second = _a.second, last = _a.last;
70
155
  return new DPoint_1.DPoint(first.distance(second), first.distance(last));
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;
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;
82
165
  if (trigger) {
83
- p = new DPolygon();
84
- result.push(p);
85
166
  p.push(point.clone());
86
167
  }
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
+ }
87
176
  }
88
177
  }
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
+ }
89
185
  return result;
90
- }
91
- static minAreaRectangleDirection(poly) {
92
- const { first, second, last } = poly.clone().open();
186
+ };
187
+ DPolygon.minAreaRectangleDirection = function (poly) {
188
+ var _a = poly.clone().open(), first = _a.first, second = _a.second, last = _a.last;
93
189
  if (!first || !second || !last) {
94
190
  return 0;
95
191
  }
@@ -97,374 +193,581 @@ class DPolygon {
97
193
  return first.findLine(second).getFi();
98
194
  }
99
195
  return first.findLine(last).getFi();
100
- }
101
- static parseFromWKT(wkt) {
102
- const data = wkt.trim().toUpperCase();
103
- let res = new DPolygon();
196
+ };
197
+ DPolygon.parseFromWKT = function (wkt) {
198
+ var data = wkt.trim().toUpperCase();
199
+ var res = new DPolygon();
104
200
  if (data.indexOf('POLYGON') === 0) {
105
- const regexp = /POLYGON \(\((?<data>(?:(?!\)\)$).)*?)\)\)$/miu;
106
- const reg = regexp.exec(data);
107
- const [path, ...holes] = reg.groups.data
201
+ var regexp = /POLYGON \(\((?<data>(?:(?!\)\)$).)*?)\)\)$/miu;
202
+ var reg = regexp.exec(data);
203
+ var _a = __read(reg.groups.data
108
204
  .split('), (')
109
- .map((p) => new DPolygon(p.split(', ')
110
- .map((pares) => DPoint_1.DPoint.parse(pares.split(' ').map(Number)))));
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);
111
207
  if (holes && holes.length) {
112
208
  path.holes = holes;
113
209
  }
114
210
  res = path;
115
211
  }
116
212
  if (data.indexOf('LINESTRING') === 0) {
117
- const regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
118
- const reg = regexp.exec(data);
213
+ var regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
214
+ var reg = regexp.exec(data);
119
215
  res = new DPolygon(reg.groups.data
120
- .split(', ').map((t) => DPoint_1.DPoint.parse(t.split(' ').map(Number))));
216
+ .split(', ').map(function (t) { return DPoint_1.DPoint.parse(t.split(' ').map(Number)); }));
121
217
  }
122
218
  if (data.indexOf('POINT') === 0) {
123
219
  res = new DPolygon([DPoint_1.DPoint.parseFromWKT(data)]);
124
220
  }
125
221
  return res;
126
- }
127
- static createSquareBySize(size) {
222
+ };
223
+ DPolygon.createSquareBySize = function (size) {
128
224
  return new DPolygon([DPoint_1.DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
129
- }
130
- loop() {
225
+ };
226
+ DPolygon.prototype.loop = function () {
131
227
  return new DPolygonLoop_1.DPolygonLoop(this);
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);
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);
225
362
  }
226
363
  }
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;
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);
421
+ }
422
+ }
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);
240
442
  }
241
443
  }
242
444
  }
243
445
  }
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;
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);
275
450
  }
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;
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;
283
542
  }
284
543
  }
285
544
  }
286
- if (!maxWidthPoint1 || !maxWidthPoint2 || !maxHeightPoint) {
287
- continue;
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; }
288
551
  }
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;
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();
301
563
  }
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);
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();
319
595
  }
320
- else {
321
- break;
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
+ }
322
611
  }
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);
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);
336
616
  }
617
+ finally { if (e_9) throw e_9.error; }
337
618
  }
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();
356
- }
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) {
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();
628
+ }
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) {
365
644
  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);
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);
656
+ }
373
657
  }
374
658
  }
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);
663
+ }
664
+ finally { if (e_10) throw e_10.error; }
665
+ }
375
666
  return res;
376
- }
377
- setCenter(newCenter) {
667
+ };
668
+ DPolygon.prototype.setCenter = function (newCenter) {
378
669
  return this.loop()
379
670
  .move(newCenter.clone().move(this.center.minus()))
380
671
  .run();
381
- }
382
- toWKT(type = DPolygon.WKT_POLYGON, withZ = false) {
672
+ };
673
+ DPolygon.prototype.toWKT = function (type, withZ) {
674
+ if (type === void 0) { type = DPolygon.WKT_POLYGON; }
675
+ if (withZ === void 0) { withZ = false; }
383
676
  if (type === DPolygon.WKT_POLYGON) {
384
- let h = '';
677
+ var h = '';
385
678
  if (this.holes && this.holes.length) {
386
- h = `, ${this.holes.map((hole) => hole.toString())
387
- .join(', ')}`;
679
+ h = ", ".concat(this.holes.map(function (hole) { return hole.toString(); })
680
+ .join(', '));
388
681
  }
389
- return `POLYGON ((${this.deintersection.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
390
- .join(', ')})${h})`;
682
+ return "POLYGON ((".concat(this.deintersection.mapArray(function (r) { return "".concat(r.x, " ").concat(r.y).concat(withZ ? " ".concat(r.z) : ''); })
683
+ .join(', '), ")").concat(h, ")");
391
684
  }
392
- return `LINESTRING (${this.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
393
- .join(', ')})`;
394
- }
395
- filter(f) {
685
+ return "LINESTRING (".concat(this.mapArray(function (r) { return "".concat(r.x, " ").concat(r.y).concat(withZ ? " ".concat(r.z) : ''); })
686
+ .join(', '), ")");
687
+ };
688
+ DPolygon.prototype.filter = function (f) {
396
689
  this.pPoints = this.pPoints.filter(f);
397
690
  return this;
398
- }
399
- map(f) {
691
+ };
692
+ DPolygon.prototype.map = function (f) {
400
693
  this.pPoints = this.mapArray(f);
401
- this.holes = this.holes.map((h) => h.map(f));
694
+ this.holes = this.holes.map(function (h) { return h.map(f); });
402
695
  return this;
403
- }
404
- mapArray(f) {
696
+ };
697
+ DPolygon.prototype.mapArray = function (f) {
405
698
  return this.pPoints.map(f);
406
- }
407
- sort(f) {
699
+ };
700
+ DPolygon.prototype.sort = function (f) {
408
701
  this.points.sort(f);
409
702
  return this;
410
- }
411
- at(index) {
412
- const { length } = this;
703
+ };
704
+ DPolygon.prototype.at = function (index) {
705
+ var length = this.length;
413
706
  return this.points[(index % length + length) % length];
414
- }
415
- pop() {
707
+ };
708
+ DPolygon.prototype.pop = function () {
416
709
  return this.pPoints.pop();
417
- }
418
- push(...args) {
419
- return this.pPoints.push(...args);
420
- }
421
- shift() {
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 () {
422
720
  return this.pPoints.shift();
423
- }
424
- unshift(...args) {
425
- return this.pPoints.unshift(...args);
426
- }
427
- reverse() {
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 () {
428
731
  this.pPoints = this.pPoints.reverse();
429
- this.holes = this.holes.map((h) => h.reverse());
732
+ this.holes = this.holes.map(function (h) { return h.reverse(); });
430
733
  return this;
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;
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 "(".concat(this.mapArray(function (r) { return r.toString(); }).join(', '), ")");
741
+ };
742
+ DPolygon.prototype.close = function () {
743
+ var p0 = this.first;
441
744
  if (p0 && !this.closed) {
442
745
  this.push(p0.clone());
443
746
  }
444
747
  return this;
445
- }
446
- open() {
447
- const p = this.first;
748
+ };
749
+ DPolygon.prototype.open = function () {
750
+ var p = this.first;
448
751
  if (this.length > 2 && p && this.closed) {
449
752
  this.pop();
450
753
  }
451
754
  return this;
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());
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(); });
456
759
  return res;
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());
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(); });
464
767
  res.properties = this.properties;
465
768
  return res;
466
- }
467
- equal(p) {
769
+ };
770
+ DPolygon.prototype.equal = function (p) {
468
771
  if (!(p instanceof DPolygon)) {
469
772
  return false;
470
773
  }
@@ -472,14 +775,14 @@ class DPolygon {
472
775
  return false;
473
776
  }
474
777
  return (this.same(p) &&
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()
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()
480
783
  .close()
481
784
  .toString();
482
- for (let i = 0; i < pClone.length; i++) {
785
+ for (var i = 0; i < pClone.length; i++) {
483
786
  if (thisAsString === pClone.toString() || thisAsString === pClone.clone().reverse()
484
787
  .toString()) {
485
788
  return true;
@@ -487,37 +790,45 @@ class DPolygon {
487
790
  pClone.nextStart();
488
791
  }
489
792
  return false;
490
- }
491
- findIndex(a) {
793
+ };
794
+ DPolygon.prototype.findIndex = function (a) {
492
795
  if (a instanceof DPoint_1.DPoint) {
493
- return this.points.findIndex((t) => t.equal(a));
796
+ return this.points.findIndex(function (t) { return t.equal(a); });
494
797
  }
495
798
  return this.points.findIndex(a);
496
- }
497
- approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
799
+ };
800
+ DPolygon.prototype.approximation = function (e) {
801
+ if (e === void 0) { e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE; }
498
802
  return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
499
- }
500
- insertAfter(index, ...points) {
501
- this.pPoints.splice(index + 1, 0, ...points);
502
- }
503
- removePart(index, count) {
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) {
504
813
  return this.pPoints.splice(index + 1, count);
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));
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); });
513
822
  return in1 || in2;
514
- }
515
- simpleInclude(p) {
823
+ };
824
+ DPolygon.prototype.simpleInclude = function (p) {
516
825
  return this.simpleIncludeX(p) && this.simpleIncludeY(p);
517
- }
518
- drawPolygonOnCanvas(canvas, fillColor, strokeColor, shadowColor, lineWidth = 1, steps = this.length - 1) {
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; }
519
830
  if (this.length > 1) {
520
- const ctx = canvas.getContext('2d');
831
+ var ctx = canvas.getContext('2d');
521
832
  if (fillColor) {
522
833
  ctx.fillStyle = fillColor;
523
834
  }
@@ -546,39 +857,51 @@ class DPolygon {
546
857
  }
547
858
  }
548
859
  return this;
549
- }
550
- clearPolygonOnCanvas(canvas) {
551
- const ctx = canvas.getContext('2d');
552
- const old = ctx.globalCompositeOperation;
860
+ };
861
+ DPolygon.prototype.clearPolygonOnCanvas = function (canvas) {
862
+ var ctx = canvas.getContext('2d');
863
+ var old = ctx.globalCompositeOperation;
553
864
  ctx.globalCompositeOperation = 'destination-out';
554
865
  this.goByPath(ctx);
555
866
  ctx.fill();
556
867
  ctx.globalCompositeOperation = old;
557
- }
558
- contain(p, isBorderInside = false) {
559
- const simpleInclude = this.simpleInclude(p);
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);
560
873
  if (!simpleInclude) {
561
874
  return false;
562
875
  }
563
- const onBorder = this.onBorder(p);
876
+ var onBorder = this.onBorder(p);
564
877
  if (onBorder) {
565
878
  return isBorderInside;
566
879
  }
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;
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
+ }
575
894
  }
576
- else {
577
- totalFi -= fiDif;
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);
578
900
  }
901
+ finally { if (e_11) throw e_11.error; }
579
902
  }
580
- const eps = Math.PI / 10000;
581
- const absTotalFi = Math.abs(totalFi);
903
+ var eps = Math.PI / 10000;
904
+ var absTotalFi = Math.abs(totalFi);
582
905
  if (absTotalFi < eps) {
583
906
  return false;
584
907
  }
@@ -586,66 +909,79 @@ class DPolygon {
586
909
  return true;
587
910
  }
588
911
  throw new Error('contains2 faild');
589
- }
590
- onBorder(p) {
591
- const simpleInclude = this.simpleInclude(p);
912
+ };
913
+ DPolygon.prototype.onBorder = function (p) {
914
+ var e_12, _a;
915
+ var simpleInclude = this.simpleInclude(p);
592
916
  if (simpleInclude) {
593
- const poly = this.deintersection;
594
- const hasSamePoint = this.points.some((point) => point.equal(p));
917
+ var poly = this.deintersection;
918
+ var hasSamePoint = this.points.some(function (point) { return point.equal(p); });
595
919
  if (hasSamePoint) {
596
920
  return true;
597
921
  }
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;
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);
602
935
  }
936
+ finally { if (e_12) throw e_12.error; }
603
937
  }
604
938
  }
605
939
  return false;
606
- }
607
- nextStart() {
940
+ };
941
+ DPolygon.prototype.nextStart = function () {
608
942
  this.open();
609
943
  this.push(this.shift());
610
944
  this.close();
611
945
  return this;
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);
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);
617
951
  if (p1.equal(p2)) {
618
952
  this.removePart(i, 1);
619
953
  i--;
620
954
  }
621
955
  }
622
956
  return this;
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);
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);
636
972
  if (d === currentPieceLength) {
637
973
  p2.properties.pieceBorder = true;
638
974
  currentPieceLength = pieceLength;
639
975
  }
640
976
  else if (d - currentPieceLength > 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];
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];
645
981
  intersectionPoint.properties.pieceBorder = true;
646
- this.insertAfter(i, intersectionPoint);
982
+ this_1.insertAfter(i, intersectionPoint);
647
983
  if (withAltitude) {
648
- const p1z = p1.z;
984
+ var p1z = p1.z;
649
985
  intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
650
986
  }
651
987
  currentPieceLength = pieceLength;
@@ -653,22 +989,48 @@ class DPolygon {
653
989
  else {
654
990
  currentPieceLength -= d;
655
991
  }
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; }
656
1006
  }
657
1007
  return this;
658
- }
659
- prepareToFastSearch() {
1008
+ };
1009
+ DPolygon.prototype.prepareToFastSearch = function () {
1010
+ var e_14, _a;
660
1011
  this.searchStore = {};
661
- for (const { x, y, z } of this.points) {
662
- if (!this.searchStore[x]) {
663
- this.searchStore[x] = {};
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;
664
1022
  }
665
- if (!this.searchStore[x][y]) {
666
- this.searchStore[x][y] = {};
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);
667
1028
  }
668
- this.searchStore[x][y][z || 'undefined'] = true;
1029
+ finally { if (e_14) throw e_14.error; }
669
1030
  }
670
- }
671
- fastHas({ x, y, z }) {
1031
+ };
1032
+ DPolygon.prototype.fastHas = function (_a) {
1033
+ var x = _a.x, y = _a.y, z = _a.z;
672
1034
  if (!this.searchStore[x]) {
673
1035
  return false;
674
1036
  }
@@ -679,23 +1041,56 @@ class DPolygon {
679
1041
  return false;
680
1042
  }
681
1043
  return this.searchStore[x][y][z || 'undefined'];
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) {
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) {
697
1092
  try {
698
- const res = this.simpleLogicFunction(p, true, true);
1093
+ var res = this.simpleLogicFunction(p, true, true);
699
1094
  if (res === null) {
700
1095
  return null;
701
1096
  }
@@ -707,49 +1102,77 @@ class DPolygon {
707
1102
  catch (ex) {
708
1103
  return null;
709
1104
  }
710
- }
711
- simpleIntersection(p) {
1105
+ };
1106
+ DPolygon.prototype.simpleIntersection = function (p) {
712
1107
  return this.simpleLogicFunction(p, false, false);
713
- }
714
- simpleDifference(p) {
1108
+ };
1109
+ DPolygon.prototype.simpleDifference = function (p) {
715
1110
  return this.simpleLogicFunction(p, true, false);
716
- }
717
- smartUnion(p) {
718
- const res = this.clone().simpleUnion(p);
1111
+ };
1112
+ DPolygon.prototype.smartUnion = function (p) {
1113
+ var e_16, _a;
1114
+ var res = this.clone().simpleUnion(p);
719
1115
  if (res) {
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) {
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) {
723
1120
  if (a.equal(b)) {
724
- continue;
1121
+ return "continue";
725
1122
  }
726
- const r = a.simpleUnion(b);
1123
+ var r = a.simpleUnion(b);
727
1124
  if (r) {
728
- allHoles = allHoles.filter((v) => !v.equal(a) && !v.equal(b));
1125
+ allHoles = allHoles.filter(function (v) { return !v.equal(a) && !v.equal(b); });
729
1126
  allHoles.push(r);
730
1127
  }
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);
731
1147
  }
732
1148
  }
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
+ }
733
1156
  res.holes = allHoles;
734
1157
  }
735
1158
  return res;
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()
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()
743
1166
  .intersection(l, true).length));
744
- const contain = poly.holes.reduce((a, hole) => a && !hole
745
- .contain(center), poly.contain(center));
1167
+ var contain = poly.holes.reduce(function (a, hole) { return a && !hole
1168
+ .contain(center); }, poly.contain(center));
746
1169
  return !intersections && contain;
747
1170
  };
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);
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);
753
1176
  if (innerAndNotIntersect(poly, p0, p2)) {
754
1177
  poly.removePart(0, 1);
755
1178
  return new DPolygon([
@@ -762,47 +1185,47 @@ class DPolygon {
762
1185
  }
763
1186
  return undefined;
764
1187
  };
765
- const p = this.clone().clockWise.open();
1188
+ var p = this.clone().clockWise.open();
766
1189
  while (p.holes.length) {
767
- const h = p.holes.shift()
1190
+ var h = p.holes.shift()
768
1191
  .clone()
769
1192
  .clockWise
770
1193
  .reverse()
771
1194
  .close();
772
- for (let i = 0; i < p.length; i++) {
1195
+ for (var i = 0; i < p.length; i++) {
773
1196
  if (innerAndNotIntersect(p, p.first, h.first)) {
774
- p.insertAfter(0, ...h.points, p.first);
1197
+ p.insertAfter.apply(p, __spreadArray(__spreadArray([0], __read(h.points), false), [p.first], false));
775
1198
  break;
776
1199
  }
777
1200
  p.push(p.shift());
778
1201
  }
779
1202
  }
780
- const res = [];
1203
+ var res = [];
781
1204
  while (p.length > 3) {
782
- const triangle = getTriangle(p);
1205
+ var triangle = getTriangle(p);
783
1206
  if (triangle) {
784
1207
  res.push(triangle);
785
1208
  }
786
1209
  }
787
1210
  res.push(p);
788
1211
  return res;
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()
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()
796
1219
  .intersection(l, true).length));
797
- const contain = poly.holes.reduce((a, hole) => a && !hole
798
- .contain(center), poly.contain(center));
1220
+ var contain = poly.holes.reduce(function (a, hole) { return a && !hole
1221
+ .contain(center); }, poly.contain(center));
799
1222
  return !intersections && contain;
800
1223
  };
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);
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);
806
1229
  if (innerAndNotIntersect(poly, p0, p2)) {
807
1230
  poly.removePart(0, 1);
808
1231
  return [
@@ -815,147 +1238,186 @@ class DPolygon {
815
1238
  }
816
1239
  return undefined;
817
1240
  };
818
- let p = this.clone();
819
- let index = 0;
820
- p.points.forEach((f) => {
1241
+ var p = this.clone();
1242
+ var index = 0;
1243
+ p.points.forEach(function (f) {
821
1244
  f.properties.index = index++;
822
1245
  });
823
- p.holes.forEach((h) => {
824
- h.pPoints.forEach((f) => {
1246
+ p.holes.forEach(function (h) {
1247
+ h.pPoints.forEach(function (f) {
825
1248
  f.properties.index = index++;
826
1249
  });
827
1250
  });
828
1251
  p = p.clockWise.open();
829
1252
  while (p.holes.length) {
830
- const h = p.holes.shift()
1253
+ var h = p.holes.shift()
831
1254
  .clone()
832
1255
  .clockWise
833
1256
  .reverse()
834
1257
  .close();
835
- for (let i = 0; i < p.length; i++) {
1258
+ for (var i = 0; i < p.length; i++) {
836
1259
  if (innerAndNotIntersect(p, p.first, h.first)) {
837
- p.insertAfter(0, ...h.points, p.first);
1260
+ p.insertAfter.apply(p, __spreadArray(__spreadArray([0], __read(h.points), false), [p.first], false));
838
1261
  break;
839
1262
  }
840
1263
  p.push(p.shift());
841
1264
  }
842
1265
  }
843
- const res = [];
1266
+ var res = [];
844
1267
  while (p.length > 3) {
845
- const triangle = getTriangle(p);
1268
+ var triangle = getTriangle(p);
846
1269
  if (triangle) {
847
- res.push(...triangle);
1270
+ res.push.apply(res, __spreadArray([], __read(triangle), false));
848
1271
  }
849
1272
  }
850
- res.push(...p.points.map((f) => f.properties.index));
1273
+ res.push.apply(res, __spreadArray([], __read(p.points.map(function (f) { return f.properties.index; })), false));
851
1274
  return res;
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
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
860
1289
  .read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
861
1290
  .buffer(v, quadrantSegments, type)
862
1291
  .getCoordinates();
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));
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));
873
1306
  buffer.unshift(buffer.pop());
874
1307
  return [linePart.reverse(), buffer];
875
- }
876
- bezier(step = 0.1) {
877
- const res = new DPolygon();
878
- for (let i = 0; i < 1; i += step) {
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) {
879
1313
  res.push(this.clone().getBezierPoint(i));
880
1314
  }
881
1315
  return res;
882
- }
883
- setGrowingHeight(from, to) {
884
- const { fullLength } = this;
885
- let { first: prevPoint } = this;
886
- const d = to - from;
887
- let currentDistance = 0;
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;
888
1322
  this.loop()
889
- .setZ((p) => {
1323
+ .setZ(function (p) {
890
1324
  currentDistance += prevPoint.distance(p);
891
1325
  prevPoint = p;
892
1326
  return from + currentDistance / fullLength * d;
893
1327
  })
894
1328
  .run();
895
1329
  return this;
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
- }
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
+ });
905
1355
  };
906
- }
907
- getBezierPoint(v) {
1356
+ };
1357
+ DPolygon.prototype.getBezierPoint = function (v) {
1358
+ var e_18, _a;
908
1359
  if (this.length === 1) {
909
1360
  return this.first;
910
1361
  }
911
- for (const [p1, p2] of this.loopPointsGenerator()()) {
912
- p1.move(p2.clone().move(p1.clone().minus())
913
- .scale(v));
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; }
914
1375
  }
915
1376
  this.pop();
916
1377
  return this.getBezierPoint(v);
917
- }
918
- simpleIncludeX(p) {
919
- const { x } = p;
1378
+ };
1379
+ DPolygon.prototype.simpleIncludeX = function (p) {
1380
+ var x = p.x;
920
1381
  return this.minX <= x && this.maxX >= x;
921
- }
922
- simpleIncludeY(p) {
923
- const { y } = p;
1382
+ };
1383
+ DPolygon.prototype.simpleIncludeY = function (p) {
1384
+ var y = p.y;
924
1385
  return this.minY <= y && this.maxY >= y;
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]);
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]);
933
1394
  if (d > dMax) {
934
1395
  index = i;
935
1396
  dMax = d;
936
1397
  }
937
1398
  }
938
1399
  if (dMax >= e) {
939
- const recResult1 = this.douglasPeucker(points.slice(0, index + 1), e);
940
- const recResult2 = this.douglasPeucker(points.slice(index), e);
1400
+ var recResult1 = this.douglasPeucker(points.slice(0, index + 1), e);
1401
+ var recResult2 = this.douglasPeucker(points.slice(index), e);
941
1402
  recResult1.pop();
942
- return [...recResult1, ...recResult2];
1403
+ return __spreadArray(__spreadArray([], __read(recResult1), false), __read(recResult2), false);
943
1404
  }
944
1405
  return [points[0], points[end]];
945
- }
946
- goByPath(ctx, steps = this.length - 1) {
947
- const start = this.first;
1406
+ };
1407
+ DPolygon.prototype.goByPath = function (ctx, steps) {
1408
+ if (steps === void 0) { steps = this.length - 1; }
1409
+ var start = this.first;
948
1410
  ctx.moveTo(start.x, start.y);
949
- for (let i = 1; i <= (steps % this.length); i++) {
950
- const { x, y } = this.at(i);
1411
+ for (var i = 1; i <= (steps % this.length); i++) {
1412
+ var _a = this.at(i), x = _a.x, y = _a.y;
951
1413
  ctx.lineTo(x, y);
952
1414
  }
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());
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());
959
1421
  if (!unionOrIntersection) {
960
1422
  return a.difference(b);
961
1423
  }
@@ -966,19 +1428,21 @@ class DPolygon {
966
1428
  return a.intersection(b);
967
1429
  }
968
1430
  return undefined;
969
- }
970
- simpleLogicFunction(p, unionThis, unionThat) {
971
- const c = this.getJSTSGeometry(p, unionThis, unionThat);
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);
972
1435
  if (c) {
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];
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;
979
1443
  if (t.equal(first)) {
980
- if (coordinates[index + 1]) {
981
- const nextPoint = new DPoint_1.DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
1444
+ if (coordinates_1[index + 1]) {
1445
+ var nextPoint = new DPoint_1.DPoint(coordinates_1[index + 1].x, coordinates_1[index + 1].y);
982
1446
  if (ak[lastIndex].length > 1) {
983
1447
  ak.push(new DPolygon([nextPoint]));
984
1448
  }
@@ -988,41 +1452,92 @@ class DPolygon {
988
1452
  ak[lastIndex].push(t);
989
1453
  }
990
1454
  return ak;
991
- }, [new DPolygon([new DPoint_1.DPoint(coordinates[0].x, coordinates[0].y)])]);
1455
+ }, [new DPolygon([new DPoint_1.DPoint(coordinates_1[0].x, coordinates_1[0].y)])]);
992
1456
  if (unionThat && unionThis && result.length > 1) {
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;
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; }
1000
1486
  }
1001
1487
  if (result.length < 2) {
1002
1488
  break;
1003
1489
  }
1004
1490
  }
1005
- if (result.length < 2) {
1006
- break;
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);
1007
1496
  }
1497
+ finally { if (e_19) throw e_19.error; }
1008
1498
  }
1009
1499
  }
1010
- result = result.filter((h) => h.length > 2).map((h) => h.close());
1011
- for (const q of result) {
1012
- for (const r of result) {
1013
- if (result.length < 2) {
1014
- break;
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
+ }
1015
1522
  }
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));
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);
1020
1527
  }
1528
+ finally { if (e_22) throw e_22.error; }
1529
+ }
1530
+ if (result.length < 2) {
1531
+ break;
1021
1532
  }
1022
1533
  }
1023
- if (result.length < 2) {
1024
- break;
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);
1025
1539
  }
1540
+ finally { if (e_21) throw e_21.error; }
1026
1541
  }
1027
1542
  if (result.length === 0) {
1028
1543
  return null;
@@ -1030,15 +1545,16 @@ class DPolygon {
1030
1545
  if (result.length === 1) {
1031
1546
  return result[0].close();
1032
1547
  }
1033
- return result.map((g) => g.close());
1548
+ return result.map(function (g) { return g.close(); });
1034
1549
  }
1035
1550
  }
1036
1551
  return null;
1037
- }
1038
- }
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
+ }());
1039
1560
  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';