dgeoutils 2.4.41 → 2.4.44

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