dgeoutils 2.2.8 → 2.2.9
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/DPolygon.d.ts +1 -2
- package/dist/DPolygon.js +24 -49
- package/package.json +1 -1
package/dist/DPolygon.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare class DPolygon {
|
|
|
81
81
|
simpleInclude(p: DPoint): boolean;
|
|
82
82
|
drawPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas, fillColor?: string, strokeColor?: string, shadowColor?: string, lineWidth?: number, steps?: number): void;
|
|
83
83
|
clearPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): void;
|
|
84
|
-
contain(p: DPoint, isBorderInside?: boolean
|
|
84
|
+
contain(p: DPoint, isBorderInside?: boolean): boolean;
|
|
85
85
|
onBorder(p: DPoint): boolean;
|
|
86
86
|
nextStart(): DPolygon;
|
|
87
87
|
removeDuplicates(): DPolygon;
|
|
@@ -105,7 +105,6 @@ export declare class DPolygon {
|
|
|
105
105
|
private simpleIncludeY;
|
|
106
106
|
private douglasPeucker;
|
|
107
107
|
private goByPath;
|
|
108
|
-
private contain2;
|
|
109
108
|
private getJSTSGeometry;
|
|
110
109
|
private simpleLogicFunction;
|
|
111
110
|
}
|
package/dist/DPolygon.js
CHANGED
|
@@ -492,7 +492,7 @@ class DPolygon {
|
|
|
492
492
|
ctx.fill();
|
|
493
493
|
ctx.globalCompositeOperation = old;
|
|
494
494
|
}
|
|
495
|
-
contain(p, isBorderInside = false
|
|
495
|
+
contain(p, isBorderInside = false) {
|
|
496
496
|
const simpleInclude = this.simpleInclude(p);
|
|
497
497
|
if (!simpleInclude) {
|
|
498
498
|
return false;
|
|
@@ -501,21 +501,34 @@ class DPolygon {
|
|
|
501
501
|
if (onBorder) {
|
|
502
502
|
return isBorderInside;
|
|
503
503
|
}
|
|
504
|
-
const line = p.findLine(this.leftTop.move(move));
|
|
505
504
|
const poly = this.deintersection;
|
|
506
|
-
|
|
505
|
+
let totalFi = 0;
|
|
507
506
|
for (let i = 0; i < poly.length - 1; i++) {
|
|
508
|
-
const
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
507
|
+
const p1 = poly.at(i);
|
|
508
|
+
const p2 = poly.at(i + 1);
|
|
509
|
+
const line1 = new DLine_1.DLine(p1.x - p.x, p1.y - p.y, 0);
|
|
510
|
+
const line2 = new DLine_1.DLine(p2.x - p.x, p2.y - p.y, 0);
|
|
511
|
+
const fiDif = line1.findFi(line2);
|
|
512
|
+
if (line1.vectorProduct(line2).c > 0) {
|
|
513
|
+
totalFi += fiDif;
|
|
512
514
|
}
|
|
515
|
+
else {
|
|
516
|
+
totalFi -= fiDif;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const eps = Math.PI / 10000;
|
|
520
|
+
let result = false;
|
|
521
|
+
const absTotalFi = Math.abs(totalFi);
|
|
522
|
+
if (absTotalFi < eps) {
|
|
523
|
+
result = false;
|
|
524
|
+
}
|
|
525
|
+
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
526
|
+
result = true;
|
|
513
527
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
return this.contain2(p, isBorderInside);
|
|
528
|
+
else {
|
|
529
|
+
throw new Error('contains2 faild');
|
|
517
530
|
}
|
|
518
|
-
return
|
|
531
|
+
return result;
|
|
519
532
|
}
|
|
520
533
|
onBorder(p) {
|
|
521
534
|
const simpleInclude = this.simpleInclude(p);
|
|
@@ -830,44 +843,6 @@ class DPolygon {
|
|
|
830
843
|
ctx.lineTo(x, y);
|
|
831
844
|
}
|
|
832
845
|
}
|
|
833
|
-
contain2(p, isBorderInside = false) {
|
|
834
|
-
const simpleInclude = this.simpleInclude(p);
|
|
835
|
-
if (!simpleInclude) {
|
|
836
|
-
return false;
|
|
837
|
-
}
|
|
838
|
-
const onBorder = this.onBorder(p);
|
|
839
|
-
if (onBorder) {
|
|
840
|
-
return isBorderInside;
|
|
841
|
-
}
|
|
842
|
-
const poly = this.deintersection;
|
|
843
|
-
let totalFi = 0;
|
|
844
|
-
for (let i = 0; i < poly.length - 1; i++) {
|
|
845
|
-
const p1 = poly.at(i);
|
|
846
|
-
const p2 = poly.at(i + 1);
|
|
847
|
-
const line1 = new DLine_1.DLine(p1.x - p.x, p1.y - p.y, 0);
|
|
848
|
-
const line2 = new DLine_1.DLine(p2.x - p.x, p2.y - p.y, 0);
|
|
849
|
-
const fiDif = line1.findFi(line2);
|
|
850
|
-
if (line1.vectorProduct(line2).c > 0) {
|
|
851
|
-
totalFi += fiDif;
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
totalFi -= fiDif;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
const eps = Math.PI / 10000;
|
|
858
|
-
let result = false;
|
|
859
|
-
const absTotalFi = Math.abs(totalFi);
|
|
860
|
-
if (absTotalFi < eps) {
|
|
861
|
-
result = false;
|
|
862
|
-
}
|
|
863
|
-
else if (Math.abs(2 * Math.PI - absTotalFi) < eps) {
|
|
864
|
-
result = true;
|
|
865
|
-
}
|
|
866
|
-
else {
|
|
867
|
-
throw new Error('contains2 faild');
|
|
868
|
-
}
|
|
869
|
-
return result;
|
|
870
|
-
}
|
|
871
846
|
getJSTSGeometry(p, unionThis, unionThat) {
|
|
872
847
|
const unionOrIntersection = unionThat === unionThis;
|
|
873
848
|
const reader = new jsts_1.io.WKTReader();
|