Skip to content

Commit

Permalink
Merge pull request #6499 from tuminzee/main
Browse files Browse the repository at this point in the history
Addresses #6485 Refactor ellipse drawing logic in p5.Renderer2D.js
  • Loading branch information
limzykenneth committed Jan 21, 2024
2 parents 5878df5 + b73af84 commit b2c29b6
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/core/p5.Renderer2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,24 +654,14 @@ class Renderer2D extends p5.Renderer {
return this;
}
}
const kappa = 0.5522847498,
// control point offset horizontal
ox = w / 2 * kappa,
// control point offset vertical
oy = h / 2 * kappa,
// x-end
xe = x + w,
// y-end
ye = y + h,
// x-middle
xm = x + w / 2,
ym = y + h / 2; // y-middle
const centerX = x + w / 2,
centerY = y + h / 2,
radiusX = w / 2,
radiusY = h / 2;
if (!this._clipping) ctx.beginPath();
ctx.moveTo(x, ym);
ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);

ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);

if (!this._clipping && doFill) {
ctx.fill();
}
Expand Down

0 comments on commit b2c29b6

Please sign in to comment.