From b7a5e572f7d2517f31ffeb953de7f85542c2f6cb Mon Sep 17 00:00:00 2001 From: tuminzee Date: Thu, 26 Oct 2023 14:30:01 +0200 Subject: [PATCH 1/2] fix #6485 Refactor ellipse drawing logic in p5.Renderer2D.js --- src/core/p5.Renderer2D.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/core/p5.Renderer2D.js b/src/core/p5.Renderer2D.js index 7935255b49..5ab53b3aa5 100644 --- a/src/core/p5.Renderer2D.js +++ b/src/core/p5.Renderer2D.js @@ -621,24 +621,19 @@ 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 xm = x + w / 2, // x-middle + ym = y + h / 2, // y-middle + 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.moveTo(x, y); + // 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); + + this.drawingContext.ellipse(xm, ym,radiusX, radiusY, 0, 0, 2 * Math.PI); + if (!this._clipping && doFill) { ctx.fill(); } From b73af847cc0c949630710fa162e1f95316cd3d63 Mon Sep 17 00:00:00 2001 From: tuminzee Date: Fri, 27 Oct 2023 12:31:24 +0200 Subject: [PATCH 2/2] Refactor variable names and simplify ellipse drawing logic in p5.Renderer2D.js --- src/core/p5.Renderer2D.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/core/p5.Renderer2D.js b/src/core/p5.Renderer2D.js index 5ab53b3aa5..c1897b2afd 100644 --- a/src/core/p5.Renderer2D.js +++ b/src/core/p5.Renderer2D.js @@ -621,18 +621,13 @@ class Renderer2D extends p5.Renderer{ return this; } } - const xm = x + w / 2, // x-middle - 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, y); - // 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); - this.drawingContext.ellipse(xm, ym,radiusX, radiusY, 0, 0, 2 * Math.PI); + ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI); if (!this._clipping && doFill) { ctx.fill();