[ENH] Line2D.contains() to return additional details
#30946
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
This PR addresses and closes Issue #30944 that I posted earlier. In short, returning more details from the
Line2D.contains()hit test could eliminate additional computational needs during time-constrained mouse events. Specifically, the PR adds'is_vert'boolean array item to thedetailsoutput dict. This item has the same size as the existing'ind'item and its element indicates whether the corresponding'ind'element. Having'is_vert'is handy when the UI requires a different action when user click on a vertex or on an edge. While this check can be done by user later,Line2D.contains()already performs this test internally (vialines.segment_hits()function). So, why not eliminate the redundant geometric computations.This PR implements this change by minimally touching
lines.Line2D.contains()andlines.segment_hits()functions without breaking their backward compatibility:lines.segment_hits()returns the number of vertex hits as an additionalintvalue. This value is only returned if the optionalreturn_is_vertboolean argument is set toTrue.lines.Line2D.contains()composes theis_vertarray and adds it to itsdetailsreturn dict.Usage example:
I have also modified the
pick_event_demo.pyingalleries/example/event_handlingto demonstrate the new feature.Documentation and docstrings have been updated to best of my ability. The docstring of
lines.segment_hits()is not a full-fledged one. So, I just expanded it in the same style.PR checklist
Line2D.contains()to return additional details #30944" is in the body of the PR description to link the related issue