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.
@@ -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, move?: DPoint): 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, move = DPoint_1.DPoint.zero()) {
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
- const intersectionPoints = [];
505
+ let totalFi = 0;
507
506
  for (let i = 0; i < poly.length - 1; i++) {
508
- const polygonLine = poly.at(i).findLine(poly.at(i + 1));
509
- const intersection = line.intersection(polygonLine, CLOSE_TO_INTERSECTION_DISTANCE);
510
- if (intersection) {
511
- intersectionPoints.push(intersection);
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
- const hasCorners = intersectionPoints.some((z) => poly.has(z));
515
- if (hasCorners) {
516
- return this.contain2(p, isBorderInside);
528
+ else {
529
+ throw new Error('contains2 faild');
517
530
  }
518
- return intersectionPoints.length % 2 === 1;
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgeoutils",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "node_modules/.bin/tsc",