dgeoutils 2.2.16 → 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 +11 -14
- package/dist/DPoint.d.ts +1 -1
- package/dist/DPoint.js +9 -11
- package/dist/DPolygon.d.ts +2 -0
- package/dist/DPolygon.js +95 -18
- package/package.json +2 -2
package/dist/DLine.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DLine = void 0;
|
|
4
4
|
const DPoint_1 = require("./DPoint");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
+
const DNumbers_1 = require("./DNumbers");
|
|
6
7
|
class DLine {
|
|
7
8
|
constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()) {
|
|
8
9
|
this.a = a;
|
|
@@ -49,7 +50,7 @@ class DLine {
|
|
|
49
50
|
intersectionWithCircle(circle) {
|
|
50
51
|
const { center, r } = circle;
|
|
51
52
|
const per = this.findPerpendicular(center);
|
|
52
|
-
const t = this.
|
|
53
|
+
const t = this.findPoint(per);
|
|
53
54
|
let distance = t.distance(center);
|
|
54
55
|
if (this.begin.equal(center)) {
|
|
55
56
|
distance = 0;
|
|
@@ -221,19 +222,15 @@ class DLine {
|
|
|
221
222
|
}
|
|
222
223
|
movePoint(p, d) {
|
|
223
224
|
const fi = this.findFi(new DLine(1, 0, 0));
|
|
224
|
-
const td = this.
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const p1T =
|
|
228
|
-
const p2T =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (this.inRange(p1T) || this.inRange(p2T)) {
|
|
234
|
-
return p2;
|
|
235
|
-
}
|
|
236
|
-
return p3;
|
|
225
|
+
const td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
|
|
226
|
+
const sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
|
|
227
|
+
const dt = sinCos.clone().scale(td);
|
|
228
|
+
const p1T = p.clone().move(dt.clone().minus());
|
|
229
|
+
const p2T = p.clone().move(dt);
|
|
230
|
+
if (DNumbers_1.DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers_1.DNumbers.like(this.y(p2T).y, p2T.y)) {
|
|
231
|
+
return p.clone().move(sinCos.scale(d));
|
|
232
|
+
}
|
|
233
|
+
return p.clone().move(sinCos.scale(d).setX(({ x }) => -x));
|
|
237
234
|
}
|
|
238
235
|
findFi({ a, b }, delta = 1.0001) {
|
|
239
236
|
const { a: q, b: w } = this;
|
package/dist/DPoint.d.ts
CHANGED
package/dist/DPoint.js
CHANGED
|
@@ -462,17 +462,15 @@ class DPoint {
|
|
|
462
462
|
return new DPoint(x, y).radiansToDegrees();
|
|
463
463
|
}));
|
|
464
464
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
return res;
|
|
465
|
+
sortByDistance(p) {
|
|
466
|
+
return p
|
|
467
|
+
.clone()
|
|
468
|
+
.map((d, index) => {
|
|
469
|
+
d.properties.distance = d.distance(this);
|
|
470
|
+
d.properties.index = index;
|
|
471
|
+
return d;
|
|
472
|
+
})
|
|
473
|
+
.sort((a, b) => a.properties.distance - b.properties.distance);
|
|
476
474
|
}
|
|
477
475
|
}
|
|
478
476
|
exports.DPoint = DPoint;
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export declare class DPolygon {
|
|
|
58
58
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
59
59
|
map(f: (r: DPoint) => DPoint): DPolygon;
|
|
60
60
|
map(f: (r: DPoint, index: number) => DPoint): DPolygon;
|
|
61
|
+
sort(f: (a: DPoint, b: DPoint) => number): DPolygon;
|
|
61
62
|
at(index: number): DPoint;
|
|
62
63
|
pop(): DPoint;
|
|
63
64
|
push(...args: DPoint[]): number;
|
|
@@ -102,6 +103,7 @@ export declare class DPolygon {
|
|
|
102
103
|
get closed(): boolean;
|
|
103
104
|
buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
|
|
104
105
|
bezier(step?: number): DPolygon;
|
|
106
|
+
setGrowingHeight(from: number, to: number): DPolygon;
|
|
105
107
|
private getBezierPoint;
|
|
106
108
|
private simpleIncludeX;
|
|
107
109
|
private simpleIncludeY;
|
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() {
|
|
@@ -349,6 +413,10 @@ class DPolygon {
|
|
|
349
413
|
this.holes = this.holes.map((h) => h.map(f));
|
|
350
414
|
return this;
|
|
351
415
|
}
|
|
416
|
+
sort(f) {
|
|
417
|
+
this.points.sort(f);
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
352
420
|
at(index) {
|
|
353
421
|
const { length } = this;
|
|
354
422
|
return this.points[(index % length + length) % length];
|
|
@@ -518,18 +586,14 @@ class DPolygon {
|
|
|
518
586
|
}
|
|
519
587
|
}
|
|
520
588
|
const eps = Math.PI / 10000;
|
|
521
|
-
let result = false;
|
|
522
589
|
const absTotalFi = Math.abs(totalFi);
|
|
523
590
|
if (absTotalFi < eps) {
|
|
524
|
-
|
|
591
|
+
return false;
|
|
525
592
|
}
|
|
526
593
|
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
throw new Error('contains2 faild');
|
|
594
|
+
return true;
|
|
531
595
|
}
|
|
532
|
-
|
|
596
|
+
throw new Error('contains2 faild');
|
|
533
597
|
}
|
|
534
598
|
onBorder(p) {
|
|
535
599
|
const simpleInclude = this.simpleInclude(p);
|
|
@@ -578,26 +642,25 @@ class DPolygon {
|
|
|
578
642
|
const { fullLength } = this;
|
|
579
643
|
const pieceLength = fullLength / piecesCount;
|
|
580
644
|
let currentPieceLength = pieceLength;
|
|
581
|
-
for (let i =
|
|
582
|
-
const p1 = this.
|
|
583
|
-
const p2 = this.
|
|
584
|
-
|
|
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) {
|
|
585
650
|
p2.properties.pieceBorder = true;
|
|
586
651
|
currentPieceLength = pieceLength;
|
|
587
|
-
continue;
|
|
588
652
|
}
|
|
589
|
-
if (
|
|
653
|
+
else if (d - currentPieceLength > 0) {
|
|
590
654
|
const circle = new DCircle_1.DCircle(p1, currentPieceLength);
|
|
591
655
|
const line = p1.findLine(p2);
|
|
592
656
|
const intersectionPoint = line.intersectionWithCircle(circle)
|
|
593
657
|
.filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
|
|
594
658
|
intersectionPoint.properties.pieceBorder = true;
|
|
595
|
-
this.insertAfter(i, intersectionPoint);
|
|
659
|
+
this.insertAfter(i - 1, intersectionPoint);
|
|
596
660
|
currentPieceLength = pieceLength;
|
|
597
|
-
continue;
|
|
598
661
|
}
|
|
599
|
-
|
|
600
|
-
currentPieceLength -=
|
|
662
|
+
else {
|
|
663
|
+
currentPieceLength -= d;
|
|
601
664
|
}
|
|
602
665
|
}
|
|
603
666
|
return this;
|
|
@@ -815,6 +878,20 @@ class DPolygon {
|
|
|
815
878
|
}
|
|
816
879
|
return res;
|
|
817
880
|
}
|
|
881
|
+
setGrowingHeight(from, to) {
|
|
882
|
+
const { fullLength } = this;
|
|
883
|
+
let { first: prevPoint } = this;
|
|
884
|
+
const d = to - from;
|
|
885
|
+
let currentDistance = 0;
|
|
886
|
+
this.loop()
|
|
887
|
+
.setZ((p) => {
|
|
888
|
+
currentDistance += prevPoint.distance(p);
|
|
889
|
+
prevPoint = p;
|
|
890
|
+
return from + currentDistance / fullLength * d;
|
|
891
|
+
})
|
|
892
|
+
.run();
|
|
893
|
+
return this;
|
|
894
|
+
}
|
|
818
895
|
getBezierPoint(v) {
|
|
819
896
|
if (this.length === 1) {
|
|
820
897
|
return this.first;
|
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": {
|