dgeoutils 2.4.38 → 2.4.40
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 +1 -1
- package/dist/cjs/DPolygon.d.ts +1 -0
- package/dist/cjs/DPolygon.js +28 -1
- package/dist/es2015/DPolygon.js +24 -1
- package/dist/esm/DPolygon.js +28 -1
- package/dist/umd/dgeoutils.js +29 -2
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
[ESLint Report](https://edejin.github.io/DGeoUtils/media/eslit.html)
|
|
20
20
|
|
|
21
21
|
```html
|
|
22
|
-
<script src="https://unpkg.com/jsts@
|
|
22
|
+
<script src="https://unpkg.com/jsts@2.7.1/dist/jsts.js"></script>
|
|
23
23
|
<script src="https://unpkg.com/dgeoutils@latest/dist/umd/dgeoutils.js"></script>
|
|
24
24
|
```
|
|
25
25
|
|
package/dist/cjs/DPolygon.d.ts
CHANGED
package/dist/cjs/DPolygon.js
CHANGED
|
@@ -87,6 +87,12 @@ exports.MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
|
87
87
|
var APPROXIMATION_VALUE = 0.1;
|
|
88
88
|
var MAX_CONVEX_ITERATIONS = 100;
|
|
89
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
|
+
};
|
|
90
96
|
var containCalculator = function (poly, p) {
|
|
91
97
|
var e_1, _a, e_2, _b;
|
|
92
98
|
var hasSamePoint = poly.points.some(function (point) { return point.equal(p); });
|
|
@@ -275,6 +281,19 @@ var DPolygon = (function () {
|
|
|
275
281
|
enumerable: false,
|
|
276
282
|
configurable: true
|
|
277
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
|
+
});
|
|
278
297
|
Object.defineProperty(DPolygon.prototype, "center", {
|
|
279
298
|
get: function () {
|
|
280
299
|
return this.leftTop.move(this.size.divide(2));
|
|
@@ -1278,6 +1297,14 @@ var DPolygon = (function () {
|
|
|
1278
1297
|
return res;
|
|
1279
1298
|
};
|
|
1280
1299
|
DPolygon.prototype.toTriangles = function () {
|
|
1300
|
+
var q = this.clone().removeDuplicates()
|
|
1301
|
+
.open();
|
|
1302
|
+
if (q.length < 3) {
|
|
1303
|
+
return [];
|
|
1304
|
+
}
|
|
1305
|
+
if (q.length === 3) {
|
|
1306
|
+
return [q];
|
|
1307
|
+
}
|
|
1281
1308
|
var innerAndNotIntersect = function (poly, p1, p2) {
|
|
1282
1309
|
var l = p1.findLine(p2);
|
|
1283
1310
|
var center = l.center;
|
|
@@ -1305,7 +1332,7 @@ var DPolygon = (function () {
|
|
|
1305
1332
|
}
|
|
1306
1333
|
return undefined;
|
|
1307
1334
|
};
|
|
1308
|
-
var p = this.clone().clockWise.open();
|
|
1335
|
+
var p = this.clone().removeDuplicates().clockWise.open();
|
|
1309
1336
|
while (p.holes.length) {
|
|
1310
1337
|
var h = p.holes.shift()
|
|
1311
1338
|
.clone()
|
package/dist/es2015/DPolygon.js
CHANGED
|
@@ -10,6 +10,12 @@ export const MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
|
10
10
|
const APPROXIMATION_VALUE = 0.1;
|
|
11
11
|
const MAX_CONVEX_ITERATIONS = 100;
|
|
12
12
|
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
13
|
+
const triangleCenter = (triangle) => {
|
|
14
|
+
const p0 = triangle.at(0);
|
|
15
|
+
const p1 = triangle.at(1);
|
|
16
|
+
const p2 = triangle.at(2);
|
|
17
|
+
return new DPoint((p0.x + p1.x + p2.x) / 3, (p0.y + p1.y + p2.y) / 3);
|
|
18
|
+
};
|
|
13
19
|
const containCalculator = (poly, p) => {
|
|
14
20
|
const hasSamePoint = poly.points.some((point) => point.equal(p));
|
|
15
21
|
if (hasSamePoint) {
|
|
@@ -145,6 +151,15 @@ export class DPolygon {
|
|
|
145
151
|
get minY() {
|
|
146
152
|
return this.reduce((a, r) => Math.min(a, r.y), Infinity);
|
|
147
153
|
}
|
|
154
|
+
get innerCenter() {
|
|
155
|
+
const { center } = this;
|
|
156
|
+
return this.toTriangles().map((t) => {
|
|
157
|
+
const c = triangleCenter(t);
|
|
158
|
+
c.properties.score = Math.min(c.distance(t.at(0)), c.distance(t.at(1)), c.distance(t.at(2))) + c.distance(center);
|
|
159
|
+
return c;
|
|
160
|
+
})
|
|
161
|
+
.sort((a, b) => a.properties.score - b.properties.score)[0];
|
|
162
|
+
}
|
|
148
163
|
get center() {
|
|
149
164
|
return this.leftTop.move(this.size.divide(2));
|
|
150
165
|
}
|
|
@@ -829,6 +844,14 @@ export class DPolygon {
|
|
|
829
844
|
return res;
|
|
830
845
|
}
|
|
831
846
|
toTriangles() {
|
|
847
|
+
const q = this.clone().removeDuplicates()
|
|
848
|
+
.open();
|
|
849
|
+
if (q.length < 3) {
|
|
850
|
+
return [];
|
|
851
|
+
}
|
|
852
|
+
if (q.length === 3) {
|
|
853
|
+
return [q];
|
|
854
|
+
}
|
|
832
855
|
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
833
856
|
const l = p1.findLine(p2);
|
|
834
857
|
const { center } = l;
|
|
@@ -856,7 +879,7 @@ export class DPolygon {
|
|
|
856
879
|
}
|
|
857
880
|
return undefined;
|
|
858
881
|
};
|
|
859
|
-
const p = this.clone().clockWise.open();
|
|
882
|
+
const p = this.clone().removeDuplicates().clockWise.open();
|
|
860
883
|
while (p.holes.length) {
|
|
861
884
|
const h = p.holes.shift()
|
|
862
885
|
.clone()
|
package/dist/esm/DPolygon.js
CHANGED
|
@@ -84,6 +84,12 @@ export var MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
|
84
84
|
var APPROXIMATION_VALUE = 0.1;
|
|
85
85
|
var MAX_CONVEX_ITERATIONS = 100;
|
|
86
86
|
var CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
87
|
+
var triangleCenter = function (triangle) {
|
|
88
|
+
var p0 = triangle.at(0);
|
|
89
|
+
var p1 = triangle.at(1);
|
|
90
|
+
var p2 = triangle.at(2);
|
|
91
|
+
return new DPoint((p0.x + p1.x + p2.x) / 3, (p0.y + p1.y + p2.y) / 3);
|
|
92
|
+
};
|
|
87
93
|
var containCalculator = function (poly, p) {
|
|
88
94
|
var e_1, _a, e_2, _b;
|
|
89
95
|
var hasSamePoint = poly.points.some(function (point) { return point.equal(p); });
|
|
@@ -272,6 +278,19 @@ var DPolygon = (function () {
|
|
|
272
278
|
enumerable: false,
|
|
273
279
|
configurable: true
|
|
274
280
|
});
|
|
281
|
+
Object.defineProperty(DPolygon.prototype, "innerCenter", {
|
|
282
|
+
get: function () {
|
|
283
|
+
var center = this.center;
|
|
284
|
+
return this.toTriangles().map(function (t) {
|
|
285
|
+
var c = triangleCenter(t);
|
|
286
|
+
c.properties.score = Math.min(c.distance(t.at(0)), c.distance(t.at(1)), c.distance(t.at(2))) + c.distance(center);
|
|
287
|
+
return c;
|
|
288
|
+
})
|
|
289
|
+
.sort(function (a, b) { return a.properties.score - b.properties.score; })[0];
|
|
290
|
+
},
|
|
291
|
+
enumerable: false,
|
|
292
|
+
configurable: true
|
|
293
|
+
});
|
|
275
294
|
Object.defineProperty(DPolygon.prototype, "center", {
|
|
276
295
|
get: function () {
|
|
277
296
|
return this.leftTop.move(this.size.divide(2));
|
|
@@ -1275,6 +1294,14 @@ var DPolygon = (function () {
|
|
|
1275
1294
|
return res;
|
|
1276
1295
|
};
|
|
1277
1296
|
DPolygon.prototype.toTriangles = function () {
|
|
1297
|
+
var q = this.clone().removeDuplicates()
|
|
1298
|
+
.open();
|
|
1299
|
+
if (q.length < 3) {
|
|
1300
|
+
return [];
|
|
1301
|
+
}
|
|
1302
|
+
if (q.length === 3) {
|
|
1303
|
+
return [q];
|
|
1304
|
+
}
|
|
1278
1305
|
var innerAndNotIntersect = function (poly, p1, p2) {
|
|
1279
1306
|
var l = p1.findLine(p2);
|
|
1280
1307
|
var center = l.center;
|
|
@@ -1302,7 +1329,7 @@ var DPolygon = (function () {
|
|
|
1302
1329
|
}
|
|
1303
1330
|
return undefined;
|
|
1304
1331
|
};
|
|
1305
|
-
var p = this.clone().clockWise.open();
|
|
1332
|
+
var p = this.clone().removeDuplicates().clockWise.open();
|
|
1306
1333
|
while (p.holes.length) {
|
|
1307
1334
|
var h = p.holes.shift()
|
|
1308
1335
|
.clone()
|