dgeoutils 2.2.19 → 2.2.22
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/dist/DLine.js +1 -1
- package/dist/DPolygon.js +77 -18
- package/package.json +2 -2
package/dist/DLine.js
CHANGED
|
@@ -50,7 +50,7 @@ class DLine {
|
|
|
50
50
|
intersectionWithCircle(circle) {
|
|
51
51
|
const { center, r } = circle;
|
|
52
52
|
const per = this.findPerpendicular(center);
|
|
53
|
-
const t = this.
|
|
53
|
+
const t = this.findPoint(per);
|
|
54
54
|
let distance = t.distance(center);
|
|
55
55
|
if (this.begin.equal(center)) {
|
|
56
56
|
distance = 0;
|
package/dist/DPolygon.js
CHANGED
|
@@ -13,6 +13,48 @@ exports.MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
|
13
13
|
const APPROXIMATION_VALUE = 0.1;
|
|
14
14
|
const MAX_CONVEX_ITERATIONS = 100;
|
|
15
15
|
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
16
|
+
const containCalculator = (poly, p) => {
|
|
17
|
+
const hasSamePoint = poly.points.some((point) => point.equal(p));
|
|
18
|
+
if (hasSamePoint) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
for (let i = 0; i < poly.length - 1; i++) {
|
|
22
|
+
const p0 = poly.at(i);
|
|
23
|
+
const p1 = poly.at(i + 1);
|
|
24
|
+
const polygonLine = p0.findLine(p1);
|
|
25
|
+
const onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
|
|
26
|
+
if (onBorder) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let totalFi = 0;
|
|
31
|
+
for (let i = 0; i < poly.length - 1; i++) {
|
|
32
|
+
const p1 = poly.at(i);
|
|
33
|
+
const p2 = poly.at(i + 1);
|
|
34
|
+
const line1 = new DLine_1.DLine(p1.x - p.x, p1.y - p.y, 0);
|
|
35
|
+
const line2 = new DLine_1.DLine(p2.x - p.x, p2.y - p.y, 0);
|
|
36
|
+
const fiDif = line1.findFi(line2);
|
|
37
|
+
if (line1.vectorProduct(line2).c > 0) {
|
|
38
|
+
totalFi += fiDif;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
totalFi -= fiDif;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const eps = Math.PI / 10000;
|
|
45
|
+
let result = false;
|
|
46
|
+
const absTotalFi = Math.abs(totalFi);
|
|
47
|
+
if (absTotalFi < eps) {
|
|
48
|
+
result = false;
|
|
49
|
+
}
|
|
50
|
+
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
51
|
+
result = true;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new Error('contains2 faild');
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
16
58
|
class DPolygon {
|
|
17
59
|
constructor(pPoints = []) {
|
|
18
60
|
this.pPoints = pPoints;
|
|
@@ -172,8 +214,12 @@ class DPolygon {
|
|
|
172
214
|
return Math.abs(sum / 2) - this.holes.reduce((a, hole) => a + hole.area, 0);
|
|
173
215
|
}
|
|
174
216
|
get deintersection() {
|
|
175
|
-
|
|
217
|
+
let p = this.clone().close();
|
|
218
|
+
const store = {};
|
|
176
219
|
for (let i = 0; i < p.length - 1; i++) {
|
|
220
|
+
const k = p.at(i).toString();
|
|
221
|
+
store[k] = store[k] || [];
|
|
222
|
+
store[k].push(i);
|
|
177
223
|
for (let j = i + 2; j < p.length - 1; j++) {
|
|
178
224
|
const firstLine = p.at(i).findLine(p.at(i + 1));
|
|
179
225
|
const secondLine = p.at(j).findLine(p.at(j + 1));
|
|
@@ -187,6 +233,24 @@ class DPolygon {
|
|
|
187
233
|
}
|
|
188
234
|
}
|
|
189
235
|
}
|
|
236
|
+
for (const key of Object.keys(store)) {
|
|
237
|
+
const record = store[key];
|
|
238
|
+
if (record.length > 1) {
|
|
239
|
+
for (let j = record.length - 1; j > 0; j--) {
|
|
240
|
+
const origin = p.clone();
|
|
241
|
+
const d = record[j] - record[j - 1];
|
|
242
|
+
if (d > 1) {
|
|
243
|
+
const part = new DPolygon(origin.removePart(record[j - 1], d));
|
|
244
|
+
const allInside = part.points
|
|
245
|
+
.reduce((a, e) => a && containCalculator(origin, e), true);
|
|
246
|
+
if (allInside && origin.isClockwise === part.isClockwise) {
|
|
247
|
+
origin.insertAfter(record[j - 1] - 1, ...part.reverse().points);
|
|
248
|
+
p = origin;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
190
254
|
return p;
|
|
191
255
|
}
|
|
192
256
|
get valid() {
|
|
@@ -522,18 +586,14 @@ class DPolygon {
|
|
|
522
586
|
}
|
|
523
587
|
}
|
|
524
588
|
const eps = Math.PI / 10000;
|
|
525
|
-
let result = false;
|
|
526
589
|
const absTotalFi = Math.abs(totalFi);
|
|
527
590
|
if (absTotalFi < eps) {
|
|
528
|
-
|
|
591
|
+
return false;
|
|
529
592
|
}
|
|
530
593
|
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
531
|
-
|
|
594
|
+
return true;
|
|
532
595
|
}
|
|
533
|
-
|
|
534
|
-
throw new Error('contains2 faild');
|
|
535
|
-
}
|
|
536
|
-
return result;
|
|
596
|
+
throw new Error('contains2 faild');
|
|
537
597
|
}
|
|
538
598
|
onBorder(p) {
|
|
539
599
|
const simpleInclude = this.simpleInclude(p);
|
|
@@ -582,26 +642,25 @@ class DPolygon {
|
|
|
582
642
|
const { fullLength } = this;
|
|
583
643
|
const pieceLength = fullLength / piecesCount;
|
|
584
644
|
let currentPieceLength = pieceLength;
|
|
585
|
-
for (let i =
|
|
586
|
-
const p1 = this.
|
|
587
|
-
const p2 = this.
|
|
588
|
-
|
|
645
|
+
for (let i = 1; i < this.length; i++) {
|
|
646
|
+
const p1 = this.at(i - 1);
|
|
647
|
+
const p2 = this.at(i);
|
|
648
|
+
const d = p1.distance(p2);
|
|
649
|
+
if (d === currentPieceLength) {
|
|
589
650
|
p2.properties.pieceBorder = true;
|
|
590
651
|
currentPieceLength = pieceLength;
|
|
591
|
-
continue;
|
|
592
652
|
}
|
|
593
|
-
if (
|
|
653
|
+
else if (d - currentPieceLength > 0) {
|
|
594
654
|
const circle = new DCircle_1.DCircle(p1, currentPieceLength);
|
|
595
655
|
const line = p1.findLine(p2);
|
|
596
656
|
const intersectionPoint = line.intersectionWithCircle(circle)
|
|
597
657
|
.filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
|
|
598
658
|
intersectionPoint.properties.pieceBorder = true;
|
|
599
|
-
this.insertAfter(i, intersectionPoint);
|
|
659
|
+
this.insertAfter(i - 1, intersectionPoint);
|
|
600
660
|
currentPieceLength = pieceLength;
|
|
601
|
-
continue;
|
|
602
661
|
}
|
|
603
|
-
|
|
604
|
-
currentPieceLength -=
|
|
662
|
+
else {
|
|
663
|
+
currentPieceLength -= d;
|
|
605
664
|
}
|
|
606
665
|
}
|
|
607
666
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dgeoutils",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.22",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node_modules/.bin/tsc",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"jest-html-reporter": "^3.4.2",
|
|
46
46
|
"jsdom": "^17.0.0",
|
|
47
47
|
"ts-jest": "^27.0.4",
|
|
48
|
-
"typedoc": "^0.
|
|
48
|
+
"typedoc": "^0.22.11",
|
|
49
49
|
"typescript": "^4.4.3"
|
|
50
50
|
},
|
|
51
51
|
"jest": {
|