路径

__updatePath()

自定义路径方法。

以下为星形路径的示例,将路径保存到 path 中可以省去每次计算的消耗。

const { begin, moveTo, lineTo, close } = PathCreator

__updatePath() {

  const { width, height, points, innerRadius } = this.__
  const rx = width / 2, ry = height / 2

  begin(this.__.path = [])
  moveTo(rx, 0)

  for (let i = 1; i < points * 2; i++) {
    lineTo(rx + (i % 2 === 0 ? rx : rx * innerRadius) * sin((i * PI) / points), ry - (i % 2 === 0 ? ry : ry * innerRadius) * cos((i * PI) / points))
  }

  close()

}

__drawPath(_canvas: ILeaferCanvas)

绘制通过__updatePath()得到的原始路径。

__drawRenderPath(_canvas: ILeaferCanvas)

绘制最终用于渲染的路径,如果 path 设置了圆角,绘制的就是经过圆角处理的路径(设计软件中会用到此功能)。

一般用于渲染、裁剪、碰撞中路径的绘制。