dgeoutils 2.3.1 → 2.3.2

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
@@ -24,6 +24,8 @@
24
24
  <script src="https://unpkg.com/dgeoutils@latest/dist/umd/dgeoutils.js"></script>
25
25
  ```
26
26
 
27
+ [Sandbox](https://jsbin.com/yaxaqif/edit?js,output)
28
+
27
29
  ### For new release
28
30
  ```
29
31
  npm run release-fix
@@ -87,7 +87,7 @@ export declare class DPolygon {
87
87
  removePart(index: number, count: number): DPoint[];
88
88
  hasSimpleIntersection(p: DPolygon): boolean;
89
89
  simpleInclude(p: DPoint): boolean;
90
- drawPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas, fillColor?: string, strokeColor?: string, shadowColor?: string, lineWidth?: number, steps?: number): void;
90
+ drawPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas, fillColor?: string, strokeColor?: string, shadowColor?: string, lineWidth?: number, steps?: number): DPolygon;
91
91
  clearPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): void;
92
92
  contain(p: DPoint, isBorderInside?: boolean): boolean;
93
93
  onBorder(p: DPoint): boolean;
@@ -827,36 +827,36 @@ var DPolygon = (function () {
827
827
  DPolygon.prototype.drawPolygonOnCanvas = function (canvas, fillColor, strokeColor, shadowColor, lineWidth, steps) {
828
828
  if (lineWidth === void 0) { lineWidth = 1; }
829
829
  if (steps === void 0) { steps = this.length - 1; }
830
- if (this.length < 2) {
831
- return;
832
- }
833
- var ctx = canvas.getContext('2d');
834
- if (fillColor) {
835
- ctx.fillStyle = fillColor;
836
- }
837
- if (strokeColor) {
838
- ctx.strokeStyle = strokeColor;
839
- }
840
- if (lineWidth) {
841
- ctx.lineWidth = lineWidth;
842
- }
843
- if (fillColor || strokeColor) {
844
- ctx.beginPath();
845
- }
846
- this.goByPath(ctx, steps % this.length);
847
- if (shadowColor) {
848
- ctx.shadowColor = shadowColor;
849
- ctx.shadowBlur = 0;
850
- ctx.shadowOffsetX = 1;
851
- ctx.shadowOffsetY = 1;
852
- }
853
- if (fillColor) {
854
- ctx.closePath();
855
- ctx.fill();
856
- }
857
- if (strokeColor) {
858
- ctx.stroke();
830
+ if (this.length > 1) {
831
+ var ctx = canvas.getContext('2d');
832
+ if (fillColor) {
833
+ ctx.fillStyle = fillColor;
834
+ }
835
+ if (strokeColor) {
836
+ ctx.strokeStyle = strokeColor;
837
+ }
838
+ if (lineWidth) {
839
+ ctx.lineWidth = lineWidth;
840
+ }
841
+ if (fillColor || strokeColor) {
842
+ ctx.beginPath();
843
+ }
844
+ this.goByPath(ctx, steps % this.length);
845
+ if (shadowColor) {
846
+ ctx.shadowColor = shadowColor;
847
+ ctx.shadowBlur = 0;
848
+ ctx.shadowOffsetX = 1;
849
+ ctx.shadowOffsetY = 1;
850
+ }
851
+ if (fillColor) {
852
+ ctx.closePath();
853
+ ctx.fill();
854
+ }
855
+ if (strokeColor) {
856
+ ctx.stroke();
857
+ }
859
858
  }
859
+ return this;
860
860
  };
861
861
  DPolygon.prototype.clearPolygonOnCanvas = function (canvas) {
862
862
  var ctx = canvas.getContext('2d');
@@ -513,36 +513,36 @@ export class DPolygon {
513
513
  return this.simpleIncludeX(p) && this.simpleIncludeY(p);
514
514
  }
515
515
  drawPolygonOnCanvas(canvas, fillColor, strokeColor, shadowColor, lineWidth = 1, steps = this.length - 1) {
516
- if (this.length < 2) {
517
- return;
518
- }
519
- const ctx = canvas.getContext('2d');
520
- if (fillColor) {
521
- ctx.fillStyle = fillColor;
522
- }
523
- if (strokeColor) {
524
- ctx.strokeStyle = strokeColor;
525
- }
526
- if (lineWidth) {
527
- ctx.lineWidth = lineWidth;
528
- }
529
- if (fillColor || strokeColor) {
530
- ctx.beginPath();
531
- }
532
- this.goByPath(ctx, steps % this.length);
533
- if (shadowColor) {
534
- ctx.shadowColor = shadowColor;
535
- ctx.shadowBlur = 0;
536
- ctx.shadowOffsetX = 1;
537
- ctx.shadowOffsetY = 1;
538
- }
539
- if (fillColor) {
540
- ctx.closePath();
541
- ctx.fill();
542
- }
543
- if (strokeColor) {
544
- ctx.stroke();
516
+ if (this.length > 1) {
517
+ const ctx = canvas.getContext('2d');
518
+ if (fillColor) {
519
+ ctx.fillStyle = fillColor;
520
+ }
521
+ if (strokeColor) {
522
+ ctx.strokeStyle = strokeColor;
523
+ }
524
+ if (lineWidth) {
525
+ ctx.lineWidth = lineWidth;
526
+ }
527
+ if (fillColor || strokeColor) {
528
+ ctx.beginPath();
529
+ }
530
+ this.goByPath(ctx, steps % this.length);
531
+ if (shadowColor) {
532
+ ctx.shadowColor = shadowColor;
533
+ ctx.shadowBlur = 0;
534
+ ctx.shadowOffsetX = 1;
535
+ ctx.shadowOffsetY = 1;
536
+ }
537
+ if (fillColor) {
538
+ ctx.closePath();
539
+ ctx.fill();
540
+ }
541
+ if (strokeColor) {
542
+ ctx.stroke();
543
+ }
545
544
  }
545
+ return this;
546
546
  }
547
547
  clearPolygonOnCanvas(canvas) {
548
548
  const ctx = canvas.getContext('2d');
@@ -824,36 +824,36 @@ var DPolygon = (function () {
824
824
  DPolygon.prototype.drawPolygonOnCanvas = function (canvas, fillColor, strokeColor, shadowColor, lineWidth, steps) {
825
825
  if (lineWidth === void 0) { lineWidth = 1; }
826
826
  if (steps === void 0) { steps = this.length - 1; }
827
- if (this.length < 2) {
828
- return;
829
- }
830
- var ctx = canvas.getContext('2d');
831
- if (fillColor) {
832
- ctx.fillStyle = fillColor;
833
- }
834
- if (strokeColor) {
835
- ctx.strokeStyle = strokeColor;
836
- }
837
- if (lineWidth) {
838
- ctx.lineWidth = lineWidth;
839
- }
840
- if (fillColor || strokeColor) {
841
- ctx.beginPath();
842
- }
843
- this.goByPath(ctx, steps % this.length);
844
- if (shadowColor) {
845
- ctx.shadowColor = shadowColor;
846
- ctx.shadowBlur = 0;
847
- ctx.shadowOffsetX = 1;
848
- ctx.shadowOffsetY = 1;
849
- }
850
- if (fillColor) {
851
- ctx.closePath();
852
- ctx.fill();
853
- }
854
- if (strokeColor) {
855
- ctx.stroke();
827
+ if (this.length > 1) {
828
+ var ctx = canvas.getContext('2d');
829
+ if (fillColor) {
830
+ ctx.fillStyle = fillColor;
831
+ }
832
+ if (strokeColor) {
833
+ ctx.strokeStyle = strokeColor;
834
+ }
835
+ if (lineWidth) {
836
+ ctx.lineWidth = lineWidth;
837
+ }
838
+ if (fillColor || strokeColor) {
839
+ ctx.beginPath();
840
+ }
841
+ this.goByPath(ctx, steps % this.length);
842
+ if (shadowColor) {
843
+ ctx.shadowColor = shadowColor;
844
+ ctx.shadowBlur = 0;
845
+ ctx.shadowOffsetX = 1;
846
+ ctx.shadowOffsetY = 1;
847
+ }
848
+ if (fillColor) {
849
+ ctx.closePath();
850
+ ctx.fill();
851
+ }
852
+ if (strokeColor) {
853
+ ctx.stroke();
854
+ }
856
855
  }
856
+ return this;
857
857
  };
858
858
  DPolygon.prototype.clearPolygonOnCanvas = function (canvas) {
859
859
  var ctx = canvas.getContext('2d');