Skip to content

Commit 0552008

Browse files
committed
Removed unnecessary else blocks by using early return pattern in shape rendering functions
1 parent c3ffe0e commit 0552008

1 file changed

Lines changed: 44 additions & 46 deletions

File tree

src/core/p5.Renderer2D.js

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -746,16 +746,15 @@ class Renderer2D extends Renderer {
746746
const relativeTransform = clipBaseTransform.multiply(currentTransform);
747747
this.clipPath.addPath(tempPath, relativeTransform);
748748
return this;
749-
} else {
750-
ctx.beginPath();
751-
ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
752-
ctx.closePath();
753-
if (doFill) {
754-
ctx.fill();
755-
}
756-
if (doStroke) {
757-
ctx.stroke();
758-
}
749+
}
750+
ctx.beginPath();
751+
ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
752+
ctx.closePath();
753+
if (doFill) {
754+
ctx.fill();
755+
}
756+
if (doStroke) {
757+
ctx.stroke();
759758
}
760759

761760
return this;
@@ -777,12 +776,12 @@ class Renderer2D extends Renderer {
777776
const relativeTransform = clipBaseTransform.multiply(currentTransform);
778777
this.clipPath.addPath(tempPath, relativeTransform);
779778
return this;
780-
} else {
781-
ctx.beginPath();
782-
ctx.moveTo(x1, y1);
783-
ctx.lineTo(x2, y2);
784-
ctx.stroke();
785779
}
780+
ctx.beginPath();
781+
ctx.moveTo(x1, y1);
782+
ctx.lineTo(x2, y2);
783+
ctx.stroke();
784+
786785
return this;
787786
}
788787

@@ -804,13 +803,13 @@ class Renderer2D extends Renderer {
804803
const relativeTransform = clipBaseTransform.multiply(currentTransform);
805804
this.clipPath.addPath(tempPath, relativeTransform);
806805
return this;
807-
} else {
808-
this._setFill(s);
809-
ctx.beginPath();
810-
ctx.arc(x, y, ctx.lineWidth / 2, 0, constants.TWO_PI, false);
811-
ctx.fill();
812-
this._setFill(f);
813806
}
807+
this._setFill(s);
808+
ctx.beginPath();
809+
ctx.arc(x, y, ctx.lineWidth / 2, 0, constants.TWO_PI, false);
810+
ctx.fill();
811+
this._setFill(f);
812+
814813
return this;
815814
}
816815

@@ -839,19 +838,18 @@ class Renderer2D extends Renderer {
839838
const relativeTransform = clipBaseTransform.multiply(currentTransform);
840839
this.clipPath.addPath(tempPath, relativeTransform);
841840
return this;
842-
} else{
843-
ctx.beginPath();
844-
ctx.moveTo(x1, y1);
845-
ctx.lineTo(x2, y2);
846-
ctx.lineTo(x3, y3);
847-
ctx.lineTo(x4, y4);
848-
ctx.closePath();
849-
if (doFill) {
850-
ctx.fill();
851-
}
852-
if (doStroke) {
853-
ctx.stroke();
854-
}
841+
}
842+
ctx.beginPath();
843+
ctx.moveTo(x1, y1);
844+
ctx.lineTo(x2, y2);
845+
ctx.lineTo(x3, y3);
846+
ctx.lineTo(x4, y4);
847+
ctx.closePath();
848+
if (doFill) {
849+
ctx.fill();
850+
}
851+
if (doStroke) {
852+
ctx.stroke();
855853
}
856854
return this;
857855
}
@@ -981,19 +979,19 @@ class Renderer2D extends Renderer {
981979
const relativeTransform = clipBaseTransform.multiply(currentTransform);
982980
this.clipPath.addPath(tempPath, relativeTransform);
983981
return this;
984-
} else {
985-
ctx.beginPath();
986-
ctx.moveTo(x1, y1);
987-
ctx.lineTo(x2, y2);
988-
ctx.lineTo(x3, y3);
989-
ctx.closePath();
990-
if (doFill) {
991-
ctx.fill();
992-
}
993-
if (doStroke) {
994-
ctx.stroke();
995-
}
996982
}
983+
ctx.beginPath();
984+
ctx.moveTo(x1, y1);
985+
ctx.lineTo(x2, y2);
986+
ctx.lineTo(x3, y3);
987+
ctx.closePath();
988+
if (doFill) {
989+
ctx.fill();
990+
}
991+
if (doStroke) {
992+
ctx.stroke();
993+
}
994+
997995
return this;
998996
}
999997

0 commit comments

Comments
 (0)