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

getPointAtLength 计算有误,且命中后应提前终止 #87

Closed
xiaoiver opened this issue Jul 18, 2022 · 0 comments
Closed

getPointAtLength 计算有误,且命中后应提前终止 #87

xiaoiver opened this issue Jul 18, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented Jul 18, 2022

该方法与 SVG 同名方法保持一致,返回 Path 指定距离处的点:
https://developer.mozilla.org/zh-CN/docs/Web/API/SVGGeometryElement/getPointAtLength

在计算 A / C / Q 这样的曲线时,使用分段逼近的方法,段数越多得到的点自然越精确,在计算总长度时也会越精确,但显然性能就会下降。

目前的实现有两个问题:

  1. 在判定距离是否满足要求时未考虑相等的情况,例如下面的路径虽然使用了 Q,但实际是一条直线:
[
  ["M", 968, 400],
  ["Q", 913, 400, 858, 400]
]
  1. 命中后未提前终止,导致后续分段的计算实际都是多余的,除非需要计算整个路径的长度。
@xiaoiver xiaoiver added the bug Something isn't working label Jul 18, 2022
@xiaoiver xiaoiver self-assigned this Jul 18, 2022
xiaoiver added a commit that referenced this issue Jul 18, 2022
Co-authored-by: yuqi.pyq <yuqi.pyq@antgroup.com>
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