dgeoutils 2.4.39 → 2.4.41

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.
@@ -46,6 +46,7 @@ export declare class DPolygon {
46
46
  get fullLength(): number;
47
47
  get perimeter(): number;
48
48
  get area(): number;
49
+ get filledDeintersection(): DPolygon;
49
50
  get deintersection(): DPolygon;
50
51
  get valid(): boolean;
51
52
  get first(): DPoint;
@@ -439,6 +439,40 @@ var DPolygon = (function () {
439
439
  enumerable: false,
440
440
  configurable: true
441
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
+ });
442
476
  Object.defineProperty(DPolygon.prototype, "deintersection", {
443
477
  get: function () {
444
478
  var e_6, _a;
@@ -1297,6 +1331,14 @@ var DPolygon = (function () {
1297
1331
  return res;
1298
1332
  };
1299
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
+ }
1300
1342
  var innerAndNotIntersect = function (poly, p1, p2) {
1301
1343
  var l = p1.findLine(p2);
1302
1344
  var center = l.center;
@@ -1324,7 +1366,7 @@ var DPolygon = (function () {
1324
1366
  }
1325
1367
  return undefined;
1326
1368
  };
1327
- var p = this.clone().clockWise.open();
1369
+ var p = this.clone().removeDuplicates().clockWise.open();
1328
1370
  while (p.holes.length) {
1329
1371
  var h = p.holes.shift()
1330
1372
  .clone()
@@ -223,6 +223,35 @@ export class DPolygon {
223
223
  }
224
224
  return Math.abs(sum / 2) - this.holes.reduce((a, hole) => a + hole.area, 0);
225
225
  }
226
+ get filledDeintersection() {
227
+ const p = this.clone().deintersection.removeDuplicates().clockWise.open();
228
+ const findSameCorners = (startIndex = 0) => {
229
+ const store = {};
230
+ for (let i = startIndex; i < p.length; i++) {
231
+ const key = p.at(i).toString();
232
+ if (typeof store[key] === 'number') {
233
+ return [store[key], i];
234
+ }
235
+ store[key] = i;
236
+ }
237
+ return undefined;
238
+ };
239
+ let indexes = findSameCorners();
240
+ const holes = [];
241
+ while (indexes) {
242
+ const a = new DPolygon(p.clone().removePart(indexes[0], indexes[1] - indexes[0]));
243
+ if (a.isClockwise) {
244
+ indexes = findSameCorners(indexes[0] + 1);
245
+ }
246
+ else {
247
+ holes.push(a.close());
248
+ p.removePart(indexes[0], indexes[1] - indexes[0]);
249
+ indexes = findSameCorners();
250
+ }
251
+ }
252
+ p.holes = holes;
253
+ return p.close();
254
+ }
226
255
  get deintersection() {
227
256
  let p = this.clone().close();
228
257
  const store = {};
@@ -844,6 +873,14 @@ export class DPolygon {
844
873
  return res;
845
874
  }
846
875
  toTriangles() {
876
+ const q = this.clone().removeDuplicates()
877
+ .open();
878
+ if (q.length < 3) {
879
+ return [];
880
+ }
881
+ if (q.length === 3) {
882
+ return [q];
883
+ }
847
884
  const innerAndNotIntersect = (poly, p1, p2) => {
848
885
  const l = p1.findLine(p2);
849
886
  const { center } = l;
@@ -871,7 +908,7 @@ export class DPolygon {
871
908
  }
872
909
  return undefined;
873
910
  };
874
- const p = this.clone().clockWise.open();
911
+ const p = this.clone().removeDuplicates().clockWise.open();
875
912
  while (p.holes.length) {
876
913
  const h = p.holes.shift()
877
914
  .clone()
@@ -436,6 +436,40 @@ var DPolygon = (function () {
436
436
  enumerable: false,
437
437
  configurable: true
438
438
  });
439
+ Object.defineProperty(DPolygon.prototype, "filledDeintersection", {
440
+ get: function () {
441
+ var p = this.clone().deintersection.removeDuplicates().clockWise.open();
442
+ var findSameCorners = function (startIndex) {
443
+ if (startIndex === void 0) { startIndex = 0; }
444
+ var store = {};
445
+ for (var i = startIndex; i < p.length; i++) {
446
+ var key = p.at(i).toString();
447
+ if (typeof store[key] === 'number') {
448
+ return [store[key], i];
449
+ }
450
+ store[key] = i;
451
+ }
452
+ return undefined;
453
+ };
454
+ var indexes = findSameCorners();
455
+ var holes = [];
456
+ while (indexes) {
457
+ var a = new DPolygon(p.clone().removePart(indexes[0], indexes[1] - indexes[0]));
458
+ if (a.isClockwise) {
459
+ indexes = findSameCorners(indexes[0] + 1);
460
+ }
461
+ else {
462
+ holes.push(a.close());
463
+ p.removePart(indexes[0], indexes[1] - indexes[0]);
464
+ indexes = findSameCorners();
465
+ }
466
+ }
467
+ p.holes = holes;
468
+ return p.close();
469
+ },
470
+ enumerable: false,
471
+ configurable: true
472
+ });
439
473
  Object.defineProperty(DPolygon.prototype, "deintersection", {
440
474
  get: function () {
441
475
  var e_6, _a;
@@ -1294,6 +1328,14 @@ var DPolygon = (function () {
1294
1328
  return res;
1295
1329
  };
1296
1330
  DPolygon.prototype.toTriangles = function () {
1331
+ var q = this.clone().removeDuplicates()
1332
+ .open();
1333
+ if (q.length < 3) {
1334
+ return [];
1335
+ }
1336
+ if (q.length === 3) {
1337
+ return [q];
1338
+ }
1297
1339
  var innerAndNotIntersect = function (poly, p1, p2) {
1298
1340
  var l = p1.findLine(p2);
1299
1341
  var center = l.center;
@@ -1321,7 +1363,7 @@ var DPolygon = (function () {
1321
1363
  }
1322
1364
  return undefined;
1323
1365
  };
1324
- var p = this.clone().clockWise.open();
1366
+ var p = this.clone().removeDuplicates().clockWise.open();
1325
1367
  while (p.holes.length) {
1326
1368
  var h = p.holes.shift()
1327
1369
  .clone()