optmization

This commit is contained in:
jiaming 2018-12-13 18:48:12 +08:00
parent c72e378c29
commit ecbdbe0446
1 changed files with 11 additions and 4 deletions

View File

@ -41,16 +41,23 @@ export function drawPolyline (ctx, points, lineWidth = 2, lineColor = '#000', cl
}
export function drawSmoothlinePath (ctx, points, close = false, newPath = false, moveTo = false) {
if (!ctx || points.length < 3) return
const canDrawPoints = filterNull(points)
if (!ctx || canDrawPoints.length < 2) return
close && canDrawPoints.push(canDrawPoints[0])
const lastPointIndex = canDrawPoints.length - 1
newPath && ctx.beginPath()
if (canDrawPoints.length === 2) {
ctx.moveTo(...canDrawPoints[0])
ctx.lineTo(...canDrawPoints[1])
return
}
const lastPointIndex = canDrawPoints.length - 1
moveTo && ctx.moveTo(...canDrawPoints[0])
canDrawPoints.forEach((t, i) =>