Skip to content

Commit

Permalink
opt: opt line render
Browse files Browse the repository at this point in the history
  • Loading branch information
liihuu committed May 29, 2024
1 parent a2c1977 commit 3fa9ce8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/extension/figure/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,22 @@ export function drawLine (ctx: CanvasRenderingContext2D, attrs: LineAttrs | Line
lines.forEach(({ coordinates }) => {
if (coordinates.length > 1) {
ctx.beginPath()
ctx.moveTo(coordinates[0].x, coordinates[0].y)
lineTo(ctx, coordinates, smooth)
if (coordinates.length === 2) {
const correction = (size % 2 === 1) ? 0.5 : 0
if (coordinates[0].x === coordinates[1].x) {
ctx.moveTo(coordinates[0].x + correction, coordinates[0].y)
ctx.lineTo(coordinates[1].x + correction, coordinates[1].y)
} else if (coordinates[0].y === coordinates[1].y) {
ctx.moveTo(coordinates[0].x, coordinates[0].y + correction)
ctx.lineTo(coordinates[1].x, coordinates[1].y + correction)
} else {
ctx.moveTo(coordinates[0].x, coordinates[0].y)
ctx.lineTo(coordinates[1].x, coordinates[1].y)
}
} else {
ctx.moveTo(coordinates[0].x, coordinates[0].y)
lineTo(ctx, coordinates, smooth)
}
ctx.stroke()
ctx.closePath()
}
Expand Down

0 comments on commit 3fa9ce8

Please sign in to comment.