Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segmentArcFactory 分段过多导致计算耗时 #92

Open
xiaoiver opened this issue Aug 30, 2022 · 1 comment
Open

segmentArcFactory 分段过多导致计算耗时 #92

xiaoiver opened this issue Aug 30, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented Aug 30, 2022

Path 部分有两点需要优化:

  • 计算 Arc 的包围盒与长度时,目前会分成 100 段,导致耗时很大。合理的做法是提供 sampleSize 参数,这样当需要高精度时就增加分段,反之可以减少
  • 目前 getPathBBoxTotalLength() 是一个二合一的方法,但有时仅需要计算包围盒或者长度。例如初始化 Path 时仅需要包围盒,此时计算长度就会造成浪费。可以通过参数控制,例如:
// 仅计算包围盒
const { x, y, width, height } = getPathBBoxTotalLength(absolutePath, { bbox: true, length: false });

// 计算时减少采样数,牺牲精度提升性能
const { x, y, width, height } = getPathBBoxTotalLength(absolutePath, { bbox: true, length: false, sampleSize: 10 });

另外需要性能测试。

@xiaoiver
Copy link
Contributor Author

xiaoiver commented Sep 1, 2022

在计算 Arc 长度 / 包围盒时,使用 10 段会造成结果精度差很多,暂时使用 30。

目前使用的分段方法似乎并不高效,需要对比下其他方式,例如:
https://github.com/mondeja/svg-path-bbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant