fix(canvas): make line and two-point linestrip selectable by click - #2107
Merged
Merged
Conversation
Rename _shape.contains_point to is_hit_by_point and route line/linestrip through nearest_edge_index so clicks on (or near) an edge select the shape. Polygon, point, circle, and mask branches keep their existing behavior; "points" shapes remain unselectable.
wkentaro
force-pushed
the
fix/line-linestrip-selectable
branch
from
May 27, 2026 12:40
e5c49cc to
910bd3a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
lineand 2-pointlinestripshapes had no interior, so the old_shape.contains_pointalways returnedFalseand_find_shape_at_pointnever picked them up — clicking on them did nothing, making it hard to select or delete them._shape.contains_point→_shape.is_hit_by_point(now takesepsilon) and routeline/linestripthroughnearest_edge_index, so clicks withinepsilonof an edge select the shape. Polygon, point, circle, and mask branches are unchanged;points(plural) stays unselectable.Re-addresses the gap left after #1502 (the
pointcase was already handled there;lineand 2-pointlinestripstill needed work).Test plan
uv run pytest tests/e2e/canvas_interaction_test.py— 25 passed, including newtest_select_nonpolygon_shape[line]and[two-point-linestrip]casesuv run ruff check+uv run ruff format --checkon changed filesuv run ty check labelme/_shape.py labelme/widgets/canvas.py