Skip to content

Commit

Permalink
unnecessary rounding in the canvas painter
Browse files Browse the repository at this point in the history
Should've been done in 57d1cbe
  • Loading branch information
chearon committed Jan 21, 2025
1 parent eb16218 commit ab0cbb7
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/paint-canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ab0cbb7

Please sign in to comment.