dgeoutils 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
  <script src="https://unpkg.com/dgeoutils@latest/dist/umd/dgeoutils.js"></script>
24
24
  ```
25
25
 
26
- [Sandbox](https://jsbin.com/yaxaqif/edit?js,output)
26
+ [Sandbox](https://jsbin.com/dapakixeba/edit?html,js,output)
27
27
 
28
28
  ### For new release
29
29
  ```
@@ -46,6 +46,7 @@ export declare class DPolygon {
46
46
  get fullLength(): number;
47
47
  get fullLengthLatLon(): number;
48
48
  get perimeter(): number;
49
+ get pointsDistanceProportions(): number[];
49
50
  get perimeterLatLon(): number;
50
51
  get area(): number;
51
52
  get filledDeintersection(): DPolygon;
@@ -128,6 +129,8 @@ export declare class DPolygon {
128
129
  setGrowingHeight(from: number, to: number): DPolygon;
129
130
  loopPointsGenerator(): () => Generator<[DPoint, DPoint, undefined, number]>;
130
131
  loopPointsGenerator(withLine: True): () => Generator<[DPoint, DPoint, DLine, number]>;
132
+ cloneByDistanceProportions(proportions: number[]): DPolygon;
133
+ middleLinestring(line: DPolygon): DPolygon;
131
134
  private getBezierPoint;
132
135
  private simpleIncludeX;
133
136
  private simpleIncludeY;
@@ -424,14 +424,16 @@ var DPolygon = (function () {
424
424
  enumerable: false,
425
425
  configurable: true
426
426
  });
427
- Object.defineProperty(DPolygon.prototype, "perimeterLatLon", {
427
+ Object.defineProperty(DPolygon.prototype, "pointsDistanceProportions", {
428
428
  get: function () {
429
429
  var e_5, _a;
430
430
  var p = 0;
431
+ var res = [0];
431
432
  try {
432
433
  for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
433
434
  var _d = __read(_c.value, 2), p1 = _d[0], p2 = _d[1];
434
- p += p1.distanceLatLon(p2);
435
+ p += p1.distance(p2);
436
+ res.push(p);
435
437
  }
436
438
  }
437
439
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
@@ -441,6 +443,28 @@ var DPolygon = (function () {
441
443
  }
442
444
  finally { if (e_5) throw e_5.error; }
443
445
  }
446
+ return res.map(function (v) { return v / p; });
447
+ },
448
+ enumerable: false,
449
+ configurable: true
450
+ });
451
+ Object.defineProperty(DPolygon.prototype, "perimeterLatLon", {
452
+ get: function () {
453
+ var e_6, _a;
454
+ var p = 0;
455
+ try {
456
+ for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
457
+ var _d = __read(_c.value, 2), p1 = _d[0], p2 = _d[1];
458
+ p += p1.distanceLatLon(p2);
459
+ }
460
+ }
461
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
462
+ finally {
463
+ try {
464
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
465
+ }
466
+ finally { if (e_6) throw e_6.error; }
467
+ }
444
468
  return p;
445
469
  },
446
470
  enumerable: false,
@@ -448,7 +472,7 @@ var DPolygon = (function () {
448
472
  });
449
473
  Object.defineProperty(DPolygon.prototype, "area", {
450
474
  get: function () {
451
- var e_6, _a;
475
+ var e_7, _a;
452
476
  var sum = 0;
453
477
  try {
454
478
  for (var _b = __values(this.deintersection.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -456,12 +480,12 @@ var DPolygon = (function () {
456
480
  sum += x * b - y * a;
457
481
  }
458
482
  }
459
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
483
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
460
484
  finally {
461
485
  try {
462
486
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
463
487
  }
464
- finally { if (e_6) throw e_6.error; }
488
+ finally { if (e_7) throw e_7.error; }
465
489
  }
466
490
  return Math.abs(sum / 2) - this.holes.reduce(function (a, hole) { return a + hole.area; }, 0);
467
491
  },
@@ -504,7 +528,7 @@ var DPolygon = (function () {
504
528
  });
505
529
  Object.defineProperty(DPolygon.prototype, "deintersection", {
506
530
  get: function () {
507
- var e_7, _a;
531
+ var e_8, _a;
508
532
  var p = this.clone().close();
509
533
  var store = {};
510
534
  for (var i = 0; i < p.length - 1; i++) {
@@ -550,12 +574,12 @@ var DPolygon = (function () {
550
574
  }
551
575
  }
552
576
  }
553
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
577
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
554
578
  finally {
555
579
  try {
556
580
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
557
581
  }
558
- finally { if (e_7) throw e_7.error; }
582
+ finally { if (e_8) throw e_8.error; }
559
583
  }
560
584
  return p;
561
585
  },
@@ -592,7 +616,7 @@ var DPolygon = (function () {
592
616
  });
593
617
  Object.defineProperty(DPolygon.prototype, "minAreaRectangle", {
594
618
  get: function () {
595
- var e_8, _a, e_9, _b;
619
+ var e_9, _a, e_10, _b;
596
620
  var p = this.convex;
597
621
  var resultPolygon = new DPolygon();
598
622
  var resultArea = Infinity;
@@ -605,7 +629,7 @@ var DPolygon = (function () {
605
629
  var maxHeight = 0;
606
630
  var maxHeightPoint = null;
607
631
  try {
608
- for (var _f = (e_9 = void 0, __values(p.loopPointsGenerator()())), _g = _f.next(); !_g.done; _g = _f.next()) {
632
+ for (var _f = (e_10 = void 0, __values(p.loopPointsGenerator()())), _g = _f.next(); !_g.done; _g = _f.next()) {
609
633
  var _h = __read(_g.value, 4), z = _h[0], i = _h[3];
610
634
  var p1 = l.findPoint(l.findPerpendicular(z));
611
635
  var h = p1.distance(z);
@@ -624,12 +648,12 @@ var DPolygon = (function () {
624
648
  }
625
649
  }
626
650
  }
627
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
651
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
628
652
  finally {
629
653
  try {
630
654
  if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
631
655
  }
632
- finally { if (e_9) throw e_9.error; }
656
+ finally { if (e_10) throw e_10.error; }
633
657
  }
634
658
  if (!maxWidthPoint1 || !maxWidthPoint2 || !maxHeightPoint) {
635
659
  continue;
@@ -649,12 +673,12 @@ var DPolygon = (function () {
649
673
  }
650
674
  }
651
675
  }
652
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
676
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
653
677
  finally {
654
678
  try {
655
679
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
656
680
  }
657
- finally { if (e_8) throw e_8.error; }
681
+ finally { if (e_9) throw e_9.error; }
658
682
  }
659
683
  return resultPolygon;
660
684
  },
@@ -707,7 +731,7 @@ var DPolygon = (function () {
707
731
  });
708
732
  Object.defineProperty(DPolygon.prototype, "isClockwise", {
709
733
  get: function () {
710
- var e_10, _a;
734
+ var e_11, _a;
711
735
  var sum = 0;
712
736
  try {
713
737
  for (var _b = __values(this.clone().close()
@@ -716,12 +740,12 @@ var DPolygon = (function () {
716
740
  sum += (a - x) * (b + y);
717
741
  }
718
742
  }
719
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
743
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
720
744
  finally {
721
745
  try {
722
746
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
723
747
  }
724
- finally { if (e_10) throw e_10.error; }
748
+ finally { if (e_11) throw e_11.error; }
725
749
  }
726
750
  return sum < 0;
727
751
  },
@@ -751,7 +775,7 @@ var DPolygon = (function () {
751
775
  return this.pPoints.reduce(f, v);
752
776
  };
753
777
  DPolygon.prototype.intersection = function (l, includeOnly) {
754
- var e_11, _a;
778
+ var e_12, _a;
755
779
  if (includeOnly === void 0) { includeOnly = false; }
756
780
  var res = [];
757
781
  try {
@@ -763,12 +787,12 @@ var DPolygon = (function () {
763
787
  }
764
788
  }
765
789
  }
766
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
790
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
767
791
  finally {
768
792
  try {
769
793
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
770
794
  }
771
- finally { if (e_11) throw e_11.error; }
795
+ finally { if (e_12) throw e_12.error; }
772
796
  }
773
797
  return res;
774
798
  };
@@ -974,7 +998,7 @@ var DPolygon = (function () {
974
998
  ctx.globalCompositeOperation = old;
975
999
  };
976
1000
  DPolygon.prototype.contain = function (p, isBorderInside) {
977
- var e_12, _a;
1001
+ var e_13, _a;
978
1002
  if (isBorderInside === void 0) { isBorderInside = false; }
979
1003
  var simpleInclude = this.simpleInclude(p);
980
1004
  if (!simpleInclude) {
@@ -1000,12 +1024,12 @@ var DPolygon = (function () {
1000
1024
  }
1001
1025
  }
1002
1026
  }
1003
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
1027
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1004
1028
  finally {
1005
1029
  try {
1006
1030
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1007
1031
  }
1008
- finally { if (e_12) throw e_12.error; }
1032
+ finally { if (e_13) throw e_13.error; }
1009
1033
  }
1010
1034
  var eps = Math.PI / 10000;
1011
1035
  var absTotalFi = Math.abs(totalFi);
@@ -1018,7 +1042,7 @@ var DPolygon = (function () {
1018
1042
  throw new Error('contains2 faild');
1019
1043
  };
1020
1044
  DPolygon.prototype.onBorder = function (p) {
1021
- var e_13, _a;
1045
+ var e_14, _a;
1022
1046
  var simpleInclude = this.simpleInclude(p);
1023
1047
  if (simpleInclude) {
1024
1048
  var poly = this.deintersection;
@@ -1035,12 +1059,12 @@ var DPolygon = (function () {
1035
1059
  }
1036
1060
  }
1037
1061
  }
1038
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
1062
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
1039
1063
  finally {
1040
1064
  try {
1041
1065
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1042
1066
  }
1043
- finally { if (e_13) throw e_13.error; }
1067
+ finally { if (e_14) throw e_14.error; }
1044
1068
  }
1045
1069
  }
1046
1070
  return false;
@@ -1164,7 +1188,7 @@ var DPolygon = (function () {
1164
1188
  };
1165
1189
  };
1166
1190
  DPolygon.prototype.divideToPieces = function (piecesCount, withAltitude) {
1167
- var e_14, _a;
1191
+ var e_15, _a;
1168
1192
  if (withAltitude === void 0) { withAltitude = false; }
1169
1193
  var fullLength = this.fullLength;
1170
1194
  var pieceLength = fullLength / piecesCount;
@@ -1199,17 +1223,17 @@ var DPolygon = (function () {
1199
1223
  _loop_3(p1, p2, i);
1200
1224
  }
1201
1225
  }
1202
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1226
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1203
1227
  finally {
1204
1228
  try {
1205
1229
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1206
1230
  }
1207
- finally { if (e_14) throw e_14.error; }
1231
+ finally { if (e_15) throw e_15.error; }
1208
1232
  }
1209
1233
  return this;
1210
1234
  };
1211
1235
  DPolygon.prototype.prepareToFastSearch = function () {
1212
- var e_15, _a;
1236
+ var e_16, _a;
1213
1237
  this.searchStore = {};
1214
1238
  try {
1215
1239
  for (var _b = __values(this.points), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -1223,12 +1247,12 @@ var DPolygon = (function () {
1223
1247
  this.searchStore[x][y][z || 'undefined'] = true;
1224
1248
  }
1225
1249
  }
1226
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1250
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
1227
1251
  finally {
1228
1252
  try {
1229
1253
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1230
1254
  }
1231
- finally { if (e_15) throw e_15.error; }
1255
+ finally { if (e_16) throw e_16.error; }
1232
1256
  }
1233
1257
  };
1234
1258
  DPolygon.prototype.fastHas = function (_a) {
@@ -1248,8 +1272,8 @@ var DPolygon = (function () {
1248
1272
  get: function () {
1249
1273
  var polygon = this;
1250
1274
  return function () {
1251
- var r, _a, _b, p, e_16_1;
1252
- var e_16, _c;
1275
+ var r, _a, _b, p, e_17_1;
1276
+ var e_17, _c;
1253
1277
  return __generator(this, function (_d) {
1254
1278
  switch (_d.label) {
1255
1279
  case 0:
@@ -1273,14 +1297,14 @@ var DPolygon = (function () {
1273
1297
  return [3, 2];
1274
1298
  case 5: return [3, 8];
1275
1299
  case 6:
1276
- e_16_1 = _d.sent();
1277
- e_16 = { error: e_16_1 };
1300
+ e_17_1 = _d.sent();
1301
+ e_17 = { error: e_17_1 };
1278
1302
  return [3, 8];
1279
1303
  case 7:
1280
1304
  try {
1281
1305
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1282
1306
  }
1283
- finally { if (e_16) throw e_16.error; }
1307
+ finally { if (e_17) throw e_17.error; }
1284
1308
  return [7];
1285
1309
  case 8: return [2, r.clone()];
1286
1310
  }
@@ -1312,12 +1336,12 @@ var DPolygon = (function () {
1312
1336
  return this.simpleLogicFunction(p, true, false);
1313
1337
  };
1314
1338
  DPolygon.prototype.smartUnion = function (p) {
1315
- var e_17, _a;
1339
+ var e_18, _a;
1316
1340
  var res = this.clone().simpleUnion(p);
1317
1341
  if (res) {
1318
1342
  var allHoles = __spreadArray(__spreadArray(__spreadArray([], __read(this.holes), false), __read(p.holes), false), __read(res.holes), false).map(function (h) { return h.clone(); });
1319
1343
  var _loop_4 = function (a) {
1320
- var e_18, _b;
1344
+ var e_19, _b;
1321
1345
  var _loop_5 = function (b) {
1322
1346
  if (a.equal(b)) {
1323
1347
  return "continue";
@@ -1329,17 +1353,17 @@ var DPolygon = (function () {
1329
1353
  }
1330
1354
  };
1331
1355
  try {
1332
- for (var allHoles_2 = (e_18 = void 0, __values(allHoles)), allHoles_2_1 = allHoles_2.next(); !allHoles_2_1.done; allHoles_2_1 = allHoles_2.next()) {
1356
+ for (var allHoles_2 = (e_19 = void 0, __values(allHoles)), allHoles_2_1 = allHoles_2.next(); !allHoles_2_1.done; allHoles_2_1 = allHoles_2.next()) {
1333
1357
  var b = allHoles_2_1.value;
1334
1358
  _loop_5(b);
1335
1359
  }
1336
1360
  }
1337
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1361
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1338
1362
  finally {
1339
1363
  try {
1340
1364
  if (allHoles_2_1 && !allHoles_2_1.done && (_b = allHoles_2.return)) _b.call(allHoles_2);
1341
1365
  }
1342
- finally { if (e_18) throw e_18.error; }
1366
+ finally { if (e_19) throw e_19.error; }
1343
1367
  }
1344
1368
  };
1345
1369
  try {
@@ -1348,12 +1372,12 @@ var DPolygon = (function () {
1348
1372
  _loop_4(a);
1349
1373
  }
1350
1374
  }
1351
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1375
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1352
1376
  finally {
1353
1377
  try {
1354
1378
  if (allHoles_1_1 && !allHoles_1_1.done && (_a = allHoles_1.return)) _a.call(allHoles_1);
1355
1379
  }
1356
- finally { if (e_17) throw e_17.error; }
1380
+ finally { if (e_18) throw e_18.error; }
1357
1381
  }
1358
1382
  res.holes = allHoles;
1359
1383
  }
@@ -1568,8 +1592,74 @@ var DPolygon = (function () {
1568
1592
  });
1569
1593
  };
1570
1594
  };
1595
+ DPolygon.prototype.cloneByDistanceProportions = function (proportions) {
1596
+ var e_20, _a;
1597
+ var resultedPolygon = new DPolygon();
1598
+ var resultProportions = Array.from(new Set(__spreadArray(__spreadArray([], __read(this.pointsDistanceProportions), false), __read(proportions), false)))
1599
+ .sort(function (a, b) { return a - b; });
1600
+ var fullLength = this.fullLength;
1601
+ resultedPolygon.push(this.at(0));
1602
+ var index = 1;
1603
+ var path = 0;
1604
+ try {
1605
+ for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
1606
+ var _d = __read(_c.value, 2), p1_ = _d[0], p2 = _d[1];
1607
+ var p1 = p1_;
1608
+ var _loop_6 = function () {
1609
+ var distance = p1.distance(p2);
1610
+ var currentProportion = (path + distance) / fullLength;
1611
+ if (Math.abs(currentProportion - resultProportions[index]) < 1e-7) {
1612
+ path += distance;
1613
+ resultedPolygon.push(p2.clone());
1614
+ index++;
1615
+ return "break";
1616
+ }
1617
+ else {
1618
+ var radius = (resultProportions[index] - resultProportions[index - 1]) * fullLength;
1619
+ var circle = new DCircle_1.DCircle(p1, radius);
1620
+ var line_2 = p1.findLine(p2);
1621
+ var intersectionPoint = line_2.intersectionWithCircle(circle)
1622
+ .filter(function (p) { return line_2.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE); })[0];
1623
+ resultedPolygon.push(intersectionPoint);
1624
+ index++;
1625
+ path += p1.distance(intersectionPoint);
1626
+ p1 = intersectionPoint;
1627
+ }
1628
+ };
1629
+ while (true) {
1630
+ var state_1 = _loop_6();
1631
+ if (state_1 === "break")
1632
+ break;
1633
+ }
1634
+ }
1635
+ }
1636
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
1637
+ finally {
1638
+ try {
1639
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1640
+ }
1641
+ finally { if (e_20) throw e_20.error; }
1642
+ }
1643
+ return resultedPolygon;
1644
+ };
1645
+ DPolygon.prototype.middleLinestring = function (line) {
1646
+ var thisClone = this.cloneByDistanceProportions(line.pointsDistanceProportions);
1647
+ var thatClone = line.cloneByDistanceProportions(this.pointsDistanceProportions);
1648
+ return thisClone
1649
+ .loop()
1650
+ .setX(function (_a, index) {
1651
+ var x = _a.x;
1652
+ return x + thatClone.at(index).x;
1653
+ })
1654
+ .setY(function (_a, index) {
1655
+ var y = _a.y;
1656
+ return y + thatClone.at(index).y;
1657
+ })
1658
+ .divide(2)
1659
+ .run();
1660
+ };
1571
1661
  DPolygon.prototype.getBezierPoint = function (v) {
1572
- var e_19, _a;
1662
+ var e_21, _a;
1573
1663
  if (this.length === 1) {
1574
1664
  return this.first;
1575
1665
  }
@@ -1580,12 +1670,12 @@ var DPolygon = (function () {
1580
1670
  .scale(v));
1581
1671
  }
1582
1672
  }
1583
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1673
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
1584
1674
  finally {
1585
1675
  try {
1586
1676
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1587
1677
  }
1588
- finally { if (e_19) throw e_19.error; }
1678
+ finally { if (e_21) throw e_21.error; }
1589
1679
  }
1590
1680
  this.pop();
1591
1681
  return this.getBezierPoint(v);
@@ -1644,7 +1734,7 @@ var DPolygon = (function () {
1644
1734
  return undefined;
1645
1735
  };
1646
1736
  DPolygon.prototype.simpleLogicFunction = function (p, unionThis, unionThat) {
1647
- var e_20, _a, e_21, _b, e_22, _c, e_23, _d;
1737
+ var e_22, _a, e_23, _b, e_24, _c, e_25, _d;
1648
1738
  var c = this.getJSTSGeometry(p, unionThis, unionThat);
1649
1739
  if (c) {
1650
1740
  var coordinates_1 = c.getCoordinates();
@@ -1671,7 +1761,7 @@ var DPolygon = (function () {
1671
1761
  try {
1672
1762
  for (var result_1 = __values(result), result_1_1 = result_1.next(); !result_1_1.done; result_1_1 = result_1.next()) {
1673
1763
  var q = result_1_1.value;
1674
- var _loop_6 = function (r) {
1764
+ var _loop_7 = function (r) {
1675
1765
  var _e;
1676
1766
  if (q.has(r.first) && !q.equal(r)) {
1677
1767
  var index = q.findIndex(r.first);
@@ -1684,38 +1774,38 @@ var DPolygon = (function () {
1684
1774
  }
1685
1775
  };
1686
1776
  try {
1687
- for (var result_2 = (e_21 = void 0, __values(result)), result_2_1 = result_2.next(); !result_2_1.done; result_2_1 = result_2.next()) {
1777
+ for (var result_2 = (e_23 = void 0, __values(result)), result_2_1 = result_2.next(); !result_2_1.done; result_2_1 = result_2.next()) {
1688
1778
  var r = result_2_1.value;
1689
- var state_1 = _loop_6(r);
1690
- if (state_1 === "break")
1779
+ var state_2 = _loop_7(r);
1780
+ if (state_2 === "break")
1691
1781
  break;
1692
1782
  }
1693
1783
  }
1694
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1784
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
1695
1785
  finally {
1696
1786
  try {
1697
1787
  if (result_2_1 && !result_2_1.done && (_b = result_2.return)) _b.call(result_2);
1698
1788
  }
1699
- finally { if (e_21) throw e_21.error; }
1789
+ finally { if (e_23) throw e_23.error; }
1700
1790
  }
1701
1791
  if (result.length < 2) {
1702
1792
  break;
1703
1793
  }
1704
1794
  }
1705
1795
  }
1706
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1796
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
1707
1797
  finally {
1708
1798
  try {
1709
1799
  if (result_1_1 && !result_1_1.done && (_a = result_1.return)) _a.call(result_1);
1710
1800
  }
1711
- finally { if (e_20) throw e_20.error; }
1801
+ finally { if (e_22) throw e_22.error; }
1712
1802
  }
1713
1803
  }
1714
1804
  result = result.filter(function (h) { return h.length > 2; }).map(function (h) { return h.close(); });
1715
1805
  try {
1716
1806
  for (var result_3 = __values(result), result_3_1 = result_3.next(); !result_3_1.done; result_3_1 = result_3.next()) {
1717
1807
  var q = result_3_1.value;
1718
- var _loop_7 = function (r) {
1808
+ var _loop_8 = function (r) {
1719
1809
  if (result.length < 2) {
1720
1810
  return "break";
1721
1811
  }
@@ -1727,31 +1817,31 @@ var DPolygon = (function () {
1727
1817
  }
1728
1818
  };
1729
1819
  try {
1730
- for (var result_4 = (e_23 = void 0, __values(result)), result_4_1 = result_4.next(); !result_4_1.done; result_4_1 = result_4.next()) {
1820
+ for (var result_4 = (e_25 = void 0, __values(result)), result_4_1 = result_4.next(); !result_4_1.done; result_4_1 = result_4.next()) {
1731
1821
  var r = result_4_1.value;
1732
- var state_2 = _loop_7(r);
1733
- if (state_2 === "break")
1822
+ var state_3 = _loop_8(r);
1823
+ if (state_3 === "break")
1734
1824
  break;
1735
1825
  }
1736
1826
  }
1737
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
1827
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
1738
1828
  finally {
1739
1829
  try {
1740
1830
  if (result_4_1 && !result_4_1.done && (_d = result_4.return)) _d.call(result_4);
1741
1831
  }
1742
- finally { if (e_23) throw e_23.error; }
1832
+ finally { if (e_25) throw e_25.error; }
1743
1833
  }
1744
1834
  if (result.length < 2) {
1745
1835
  break;
1746
1836
  }
1747
1837
  }
1748
1838
  }
1749
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
1839
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
1750
1840
  finally {
1751
1841
  try {
1752
1842
  if (result_3_1 && !result_3_1.done && (_c = result_3.return)) _c.call(result_3);
1753
1843
  }
1754
- finally { if (e_22) throw e_22.error; }
1844
+ finally { if (e_24) throw e_24.error; }
1755
1845
  }
1756
1846
  if (result.length === 0) {
1757
1847
  return null;
@@ -219,6 +219,15 @@ export class DPolygon {
219
219
  }
220
220
  return p;
221
221
  }
222
+ get pointsDistanceProportions() {
223
+ let p = 0;
224
+ const res = [0];
225
+ for (const [p1, p2] of this.loopPointsGenerator()()) {
226
+ p += p1.distance(p2);
227
+ res.push(p);
228
+ }
229
+ return res.map((v) => v / p);
230
+ }
222
231
  get perimeterLatLon() {
223
232
  let p = 0;
224
233
  for (const [p1, p2] of this.loopPointsGenerator()()) {
@@ -1064,6 +1073,50 @@ export class DPolygon {
1064
1073
  }
1065
1074
  };
1066
1075
  }
1076
+ cloneByDistanceProportions(proportions) {
1077
+ const resultedPolygon = new DPolygon();
1078
+ const resultProportions = Array.from(new Set([...this.pointsDistanceProportions, ...proportions]))
1079
+ .sort((a, b) => a - b);
1080
+ const { fullLength } = this;
1081
+ resultedPolygon.push(this.at(0));
1082
+ let index = 1;
1083
+ let path = 0;
1084
+ for (const [p1_, p2] of this.loopPointsGenerator()()) {
1085
+ let p1 = p1_;
1086
+ while (true) {
1087
+ const distance = p1.distance(p2);
1088
+ const currentProportion = (path + distance) / fullLength;
1089
+ if (Math.abs(currentProportion - resultProportions[index]) < 1e-7) {
1090
+ path += distance;
1091
+ resultedPolygon.push(p2.clone());
1092
+ index++;
1093
+ break;
1094
+ }
1095
+ else {
1096
+ const radius = (resultProportions[index] - resultProportions[index - 1]) * fullLength;
1097
+ const circle = new DCircle(p1, radius);
1098
+ const line = p1.findLine(p2);
1099
+ const intersectionPoint = line.intersectionWithCircle(circle)
1100
+ .filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
1101
+ resultedPolygon.push(intersectionPoint);
1102
+ index++;
1103
+ path += p1.distance(intersectionPoint);
1104
+ p1 = intersectionPoint;
1105
+ }
1106
+ }
1107
+ }
1108
+ return resultedPolygon;
1109
+ }
1110
+ middleLinestring(line) {
1111
+ const thisClone = this.cloneByDistanceProportions(line.pointsDistanceProportions);
1112
+ const thatClone = line.cloneByDistanceProportions(this.pointsDistanceProportions);
1113
+ return thisClone
1114
+ .loop()
1115
+ .setX(({ x }, index) => x + thatClone.at(index).x)
1116
+ .setY(({ y }, index) => y + thatClone.at(index).y)
1117
+ .divide(2)
1118
+ .run();
1119
+ }
1067
1120
  getBezierPoint(v) {
1068
1121
  if (this.length === 1) {
1069
1122
  return this.first;