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

Fix closest edge and face check in NavigationServer3D.map_get_closest_point_to_segment #93227

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

oshman99
Copy link
Contributor

If the line segment was not intersecting a face, Geometry3D::get_closest_points_between_segments was used. It calculated distance between the line segment and face's edges, instead of the distance between the line segment and face itself.
Since If the line segment is not itersecting a face, closest point to this face will be either beggining or end of this line segment, Face3::get_closest_point_to was used.

@AThousandShips AThousandShips changed the title Fixed the closest edge and face check in NavigationServer3D.map_get_closest_point_to_segment Fix closest edge and face check in NavigationServer3D.map_get_closest_point_to_segment Jun 16, 2024
@AThousandShips AThousandShips requested a review from a team June 16, 2024 12:45
@AThousandShips AThousandShips added this to the 4.3 milestone Jun 16, 2024
Copy link
Contributor

@smix8 smix8 left a comment

Choose a reason for hiding this comment

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

Thanks.

On a different note the NavigationServer3D documentation of that function should be improved to clarify what the collision parameter does.

modules/navigation/nav_map.cpp Outdated Show resolved Hide resolved
modules/navigation/nav_map.cpp Outdated Show resolved Hide resolved
modules/navigation/nav_map.cpp Outdated Show resolved Hide resolved
@oshman99 oshman99 requested a review from AThousandShips June 16, 2024 21:39
@AThousandShips
Copy link
Member

When you've fixed the comment please squash your commits into one, see here

And please also update the commit message to match the PR title to make it a bit clearer

@oshman99
Copy link
Contributor Author

Sorry, my bad. Will follow pull-request guidelines properly next time.

@akien-mga akien-mga merged commit 0ca0b46 into godotengine:master Jun 17, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@kleonc
Copy link
Member

kleonc commented Jun 17, 2024

Since If the line segment is not itersecting a face, closest point to this face will be either beggining or end of this line segment,

This is incorrect statement (and hence this PR is incorrect as well). Counterexample: consider a face [(0, 0, 0), (1, 0, 0), (0, 1, 0)] and a segment [(0, 0, 1), (1, 2, 0)]. Then:

  • Segment's endpoint (0, 0, 1) distance to the face is 1.0, closest on-face point is (0, 0, 0).
  • Segment's endpoint (1, 2, 0) distance to the face is sqrt(2) (approx 1.414), closest on-face point is (0, 1, 0).
  • Distance of on-segment point (5 / 11, 10 / 11, 6 / 11) to on-face point (3 / 11, 8 / 11, 0) (it's on face's edge) is 2 / sqrt(11) (approx 0.603).

@oshman99
Copy link
Contributor Author

@kleonc you're right, completely missed this, thanks! I still would like to try to implement a proper fix with your correction in mind.
@AThousandShips what would be the correct way of handeling this? Should a bug be reopened and a new PR created?

@AThousandShips
Copy link
Member

AThousandShips commented Jun 17, 2024

New PR yes, unsure about a report

@akien-mga
Copy link
Member

A bug report could be good so we make sure to track this for the 4.3 release, and ensure that we can either merge a fix up PR, or revert this one if it's incorrect, to revisit later.

@kleonc
Copy link
Member

kleonc commented Jun 22, 2024

I still would like to try to implement a proper fix with your correction in mind.

@oshman99 So any update on this / are you planning to open a PR? If you are not able to then please say so (in such case I'll address this myself). 🙂

@oshman99
Copy link
Contributor Author

@kleonc yeah you can go ahead and address this. Wanted to tackle it today, but life got in the way. If you don't mind, can you tag me in your PR, when you create one?

@kleonc
Copy link
Member

kleonc commented Jun 23, 2024

@kleonc yeah you can go ahead and address this. Wanted to tackle it today, but life got in the way. If you don't mind, can you tag me in your PR, when you create one?

@oshman99 Oh, I've asked kinda preemptively (seeing no update and just wanting to ensure it will be fixed for 4.3.stable). Aka haven't looked into this myself yet, maybe I'll do so tomorrow/Tuesday. So if you still want to open PR yourself feel free to do so (sorry if I made you not open a PR today etc.!); a simple fix ensuring correctness of the result would be fine for now (there's very likely a more optimal way to do the calculations as we're dealing with convex polygons / triangle fans and currently we're considering/checking each triangle separately).
And sure I'll tag you if I'll end up opening a PR for this.

@oshman99
Copy link
Contributor Author

@oshman99 Oh, I've asked kinda preemptively (seeing no update and just wanting to ensure it will be fixed for 4.3.stable). Aka haven't looked into this myself yet, maybe I'll do so tomorrow/Tuesday. So if you still want to open PR yourself feel free to do so (sorry if I made you not open a PR today etc.!); a simple fix ensuring correctness of the result would be fine for now (there's very likely a more optimal way to do the calculations as we're dealing with convex polygons / triangle fans and currently we're considering/checking each triangle separately). And sure I'll tag you if I'll end up opening a PR for this.

@kleonc oh, hahaha, sorry for causing confusion then. There is MOST DEFINITELY a more optimal way of doing things. My first instinct was to basically add a third shortest distance check, that would compare the current shortest distance with the distance to the edge (basically, a copy-paste of the previous implementation). It works fine, but that's a pretty naive solution. I'll create a PR today and ping you and @smix8 . Feel free to comment on any issues or suggest better ways of doing this :)

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

Successfully merging this pull request may close these issues.

NavigationServer3D.map_get_closest_point_to_segment only returns correct result if segment intersects nav mesh
5 participants