Skip to content

Commit

Permalink
opt: opt figure line render.
Browse files Browse the repository at this point in the history
  • Loading branch information
liihuu committed Mar 13, 2024
1 parent dc60228 commit c6918e3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/extension/figure/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getDistance (coordinate1: Coordinate, coordinate2: Coordinate): number
return Math.sqrt(Math.pow(coordinate1.x + coordinate2.x, 2) + Math.pow(coordinate1.y + coordinate2.y, 2))
}

function getSmoothControlCoordinate (coordinates: Coordinate[]): Coordinate[] {
function getSmoothControlCoordinate (coordinates: [Coordinate, Coordinate, Coordinate]): Coordinate[] {
const d01 = getDistance(coordinates[0], coordinates[1])
const d12 = getDistance(coordinates[1], coordinates[2])
const d02 = d01 + d12
Expand Down Expand Up @@ -110,7 +110,7 @@ export function drawLine (ctx: CanvasRenderingContext2D, attrs: LineAttrs, style
ctx.beginPath()
ctx.moveTo(coordinates[0].x, coordinates[0].y)

if (smooth ?? false) {
if ((smooth ?? false) && length > 2) {
let controlCoordinates: Coordinate[] = []
for (let i = 1; i < length - 1; i++) {
controlCoordinates = controlCoordinates.concat(getSmoothControlCoordinate([coordinates[i - 1], coordinates[i], coordinates[i + 1]]))
Expand Down

0 comments on commit c6918e3

Please sign in to comment.