From e5372d11ae0826c393c230d0c031fb34f861e7fa Mon Sep 17 00:00:00 2001 From: Preet <833927+pshihn@users.noreply.github.com> Date: Wed, 1 Dec 2021 11:52:26 -0800 Subject: [PATCH] Fix rounding errors when generating ellipse (#198) * . * fix for solid arc fill when arc angle is > 180 * fix dot rendering when roughness < 1 * fix rounding error when computing ellipse points --- src/renderer.ts | 2 +- visual-tests/canvas/ellipse2.html | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index fd1d45e..23731c1 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -74,7 +74,7 @@ export function ellipse(x: number, y: number, width: number, height: number, o: export function generateEllipseParams(width: number, height: number, o: ResolvedOptions): EllipseParams { const psq = Math.sqrt(Math.PI * 2 * Math.sqrt((Math.pow(width / 2, 2) + Math.pow(height / 2, 2)) / 2)); - const stepCount = Math.max(o.curveStepCount, (o.curveStepCount / Math.sqrt(200)) * psq); + const stepCount = Math.ceil(Math.max(o.curveStepCount, (o.curveStepCount / Math.sqrt(200)) * psq)); const increment = (Math.PI * 2) / stepCount; let rx = Math.abs(width / 2); let ry = Math.abs(height / 2); diff --git a/visual-tests/canvas/ellipse2.html b/visual-tests/canvas/ellipse2.html index b4b78b7..7c99f18 100644 --- a/visual-tests/canvas/ellipse2.html +++ b/visual-tests/canvas/ellipse2.html @@ -17,7 +17,9 @@ rc.ellipse(300, 350, 380, 280, { roughness: 2 }); rc.ellipse(200, 150, 380, 280, { roughness: 1 }); - rc.ellipse(400, 150, 380, 280, { roughness: 0 }); + rc.ellipse(400, 150, 100.65800865800863, 17.70129870129859, { roughness: 0 }); + rc.ellipse(200, 150, 100, 17, { roughness: 0, fill: 'red' }); + rc.ellipse(200, 50, 100, 17, { roughness: 0, fill: 'pink', fillStyle: 'solid' });