Skip to content

Commit

Permalink
Use native method for drawing ellipse
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Apr 22, 2024
1 parent c1433e5 commit e46a163
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/jcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2837,9 +2837,7 @@ $.fn.drawArc = function drawArc(args) {
// Draws ellipse
$.fn.drawEllipse = function drawEllipse(args) {
var $canvases = this, e, ctx,
params,
controlW,
controlH;
params;

for (e = 0; e < $canvases.length; e += 1) {
ctx = _getContext($canvases[e]);
Expand All @@ -2852,18 +2850,17 @@ $.fn.drawEllipse = function drawEllipse(args) {
_transformShape($canvases[e], ctx, params, params.width, params.height);
_setGlobalProps($canvases[e], ctx, params);

// Calculate control width and height
controlW = params.width * (4 / 3);
controlH = params.height;

// Create ellipse using curves
ctx.beginPath();
ctx.moveTo(params.x, params.y - (controlH / 2));
// Left side
ctx.bezierCurveTo(params.x - (controlW / 2), params.y - (controlH / 2), params.x - (controlW / 2), params.y + (controlH / 2), params.x, params.y + (controlH / 2));
// Right side
ctx.bezierCurveTo(params.x + (controlW / 2), params.y + (controlH / 2), params.x + (controlW / 2), params.y - (controlH / 2), params.x, params.y - (controlH / 2));
// Check for jCanvas events
ctx.ellipse(
params.x,
params.y,
params.width / 2,
params.height / 2,
0,
0,
2 * Math.PI,
);
_detectEvents($canvases[e], ctx, params);
// Always close path
params.closed = true;
Expand Down

0 comments on commit e46a163

Please sign in to comment.