Skip to content

Commit ab0cbb7

Browse files
committed
unnecessary rounding in the canvas painter
Should've been done in 57d1cbe
1 parent eb16218 commit ab0cbb7

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/paint-canvas.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,13 @@ export default class CanvasPaintBackend implements PaintBackend {
139139
// TODO: pass in border-radius
140140
edge(x: number, y: number, length: number, side: 'top' | 'right' | 'bottom' | 'left') {
141141
const {r, g, b, a} = this.strokeColor;
142-
const lw2 = this.lineWidth/2;
143-
const rx = Math.round(x - lw2) + lw2;
144-
const ry = Math.round(y - lw2) + lw2;
145142
this.ctx.beginPath();
146143
this.ctx.strokeStyle = `rgba(${r}, ${g}, ${b}, ${a})`;
147144
this.ctx.lineWidth = this.lineWidth;
148-
this.ctx.moveTo(
149-
side === 'left' || side === 'right' ? rx : Math.round(x),
150-
side === 'top' || side === 'bottom' ? ry : Math.round(y)
151-
);
145+
this.ctx.moveTo(x, y);
152146
this.ctx.lineTo(
153-
side === 'top' || side === 'bottom' ? Math.round(x + length) : rx,
154-
side === 'left' || side === 'right' ? Math.round(y + length) : ry
147+
side === 'top' || side === 'bottom' ? x + length : x,
148+
side === 'left' || side === 'right' ? y + length : y
155149
);
156150
this.ctx.stroke();
157151
}
@@ -242,15 +236,9 @@ export default class CanvasPaintBackend implements PaintBackend {
242236

243237
rect(x: number, y: number, w: number, h: number) {
244238
const {r, g, b, a} = this.fillColor;
245-
const rx = Math.round(x);
246-
const ry = Math.round(y);
247-
const right = Math.round(x + w);
248-
const bottom = Math.round(y + h);
249-
const rw = right - rx;
250-
const rh = bottom - ry;
251239
this.ctx.beginPath();
252240
this.ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`;
253-
this.ctx.fillRect(rx, ry, rw, rh);
241+
this.ctx.fillRect(x, y, w, h);
254242
}
255243

256244
pushClip(x: number, y: number, w: number, h: number) {

0 commit comments

Comments
 (0)