Skip to content

fix(core): 修复 polyline 与多边形节点的交点不正确的问题 #1947

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

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

Yuan-ZW
Copy link
Contributor

@Yuan-ZW Yuan-ZW commented Nov 5, 2024

修改了下面这个算法。这个算法只考虑到了endPoint的x,y均比startPoint的x,y大的情况,逻辑不严谨,从而间接导致了polyline与多边形的交点位置与预期不符

/* 判断一个点是否在线段中
入参点:point, 线段起终点,start,end,
返回值: 在线段中true,否则false
*/
export const isInSegment = (point: Point, start: Point, end: Point) => {
const { x, y } = point
const { x: startX, y: startY } = start
const { x: endX, y: endY } = end
const k = (endY - startY) / (endX - startX)
const b = startY - k * startX
return (
x >= startX &&
x <= endX &&
y >= startY &&
y <= endY &&
Math.abs(y - k * x + b) < Number.EPSILON
)
}

详见:#1945 (comment)

Copy link

changeset-bot bot commented Nov 5, 2024

⚠️ No Changeset found

Latest commit: 7481130

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@DymoneLewis
Copy link
Collaborator

来了,代码看起来没问题,稍等这边把代码拉下来验证一下功能是否有问题哈

Copy link
Collaborator

@DymoneLewis DymoneLewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o( ̄▽ ̄)d好顶赞

@DymoneLewis DymoneLewis merged commit 9b1a4ab into didi:master Nov 7, 2024
@Yuan-ZW
Copy link
Contributor Author

Yuan-ZW commented Nov 7, 2024

o( ̄▽ ̄)ブ

@DymoneLewis
Copy link
Collaborator

发了2.0.7版本,可以升级试下了( ̄▽ ̄)V

@Yuan-ZW Yuan-ZW deleted the yzw/fix/cross-point-with-polygon branch November 8, 2024 00:31
@Yuan-ZW
Copy link
Contributor Author

Yuan-ZW commented Nov 8, 2024

发现还有一行代码漏改了

Math.abs(y - k * x + b) < Number.EPSILON

y - k * x + b应该改成 y - k * x - b, 我之前使用的时候发现的, 提PR的时候漏了😂

我再提一个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants