dgeoutils 2.4.38 → 2.4.39

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
@@ -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@latest/dist/jsts.js"></script>
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
 
@@ -30,6 +30,7 @@ export declare class DPolygon {
30
30
  get minX(): number;
31
31
  get maxY(): number;
32
32
  get minY(): number;
33
+ get innerCenter(): DPoint;
33
34
  get center(): DPoint;
34
35
  get h(): number;
35
36
  get w(): number;
@@ -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));
@@ -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
  }
@@ -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));