From ab0cbb7ad7de7bed50d9660e90ab4840ca042a18 Mon Sep 17 00:00:00 2001 From: Caleb Hearon Date: Mon, 20 Jan 2025 21:47:32 -0500 Subject: [PATCH] unnecessary rounding in the canvas painter Should've been done in 57d1cbe9639ba5b5b2753bb37be364d9662e5c1a --- src/paint-canvas.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/paint-canvas.ts b/src/paint-canvas.ts index e077d87..fa19631 100644 --- a/src/paint-canvas.ts +++ b/src/paint-canvas.ts @@ -139,19 +139,13 @@ export default class CanvasPaintBackend implements PaintBackend { // TODO: pass in border-radius edge(x: number, y: number, length: number, side: 'top' | 'right' | 'bottom' | 'left') { const {r, g, b, a} = this.strokeColor; - const lw2 = this.lineWidth/2; - const rx = Math.round(x - lw2) + lw2; - const ry = Math.round(y - lw2) + lw2; this.ctx.beginPath(); this.ctx.strokeStyle = `rgba(${r}, ${g}, ${b}, ${a})`; this.ctx.lineWidth = this.lineWidth; - this.ctx.moveTo( - side === 'left' || side === 'right' ? rx : Math.round(x), - side === 'top' || side === 'bottom' ? ry : Math.round(y) - ); + this.ctx.moveTo(x, y); this.ctx.lineTo( - side === 'top' || side === 'bottom' ? Math.round(x + length) : rx, - side === 'left' || side === 'right' ? Math.round(y + length) : ry + side === 'top' || side === 'bottom' ? x + length : x, + side === 'left' || side === 'right' ? y + length : y ); this.ctx.stroke(); } @@ -242,15 +236,9 @@ export default class CanvasPaintBackend implements PaintBackend { rect(x: number, y: number, w: number, h: number) { const {r, g, b, a} = this.fillColor; - const rx = Math.round(x); - const ry = Math.round(y); - const right = Math.round(x + w); - const bottom = Math.round(y + h); - const rw = right - rx; - const rh = bottom - ry; this.ctx.beginPath(); this.ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`; - this.ctx.fillRect(rx, ry, rw, rh); + this.ctx.fillRect(x, y, w, h); } pushClip(x: number, y: number, w: number, h: number) {