From c6918e33fafa800f114215428b824b9fa8c3c283 Mon Sep 17 00:00:00 2001 From: liihuu Date: Wed, 13 Mar 2024 22:26:43 +0800 Subject: [PATCH] opt: opt figure `line` render. --- src/extension/figure/line.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension/figure/line.ts b/src/extension/figure/line.ts index b3c37e5a8..c77b2f280 100644 --- a/src/extension/figure/line.ts +++ b/src/extension/figure/line.ts @@ -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 @@ -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]]))