Skip to content

fix: point shapes are now selectable and deletable by clicking#1860

Merged
wkentaro merged 1 commit intomainfrom
fix/point-shape-click-selection
Mar 10, 2026
Merged

fix: point shapes are now selectable and deletable by clicking#1860
wkentaro merged 1 commit intomainfrom
fix/point-shape-click-selection

Conversation

@wkentaro
Copy link
Owner

@wkentaro wkentaro commented Mar 9, 2026

Problem

Point shapes placed on the canvas cannot be selected or deleted by clicking on them. Shape.containsPoint() calls self.makePath().contains(point), but a point shape's path is zero-area (a single zero-length line), so QPainterPath.contains() always returns False.

This makes point annotations effectively stuck — impossible to select, move, or delete after creation.

Fixes #1524.

Solution

Add an early return in containsPoint() for shape_type == "point" that uses the actual rendered hit radius (point_size / 2) instead of path containment:

if self.shape_type == "point":
    if not self.points:
        return False
    return labelme.utils.distance(point - self.points[0]) <= self.point_size / 2

This mirrors the visual size of the drawn point handle and gives users a natural click target.

Tests

Added tests/unit/shape_contains_point_test.py with 4 cases:

  • Clicking exactly on the center → True
  • Clicking within point_size / 2True
  • Clicking more than point_size / 2 away → False
  • Empty points list → False (no crash)

All 40 unit tests pass.

@wkentaro wkentaro force-pushed the fix/point-shape-click-selection branch from 0dc68d1 to 0891737 Compare March 10, 2026 12:46
@wkentaro wkentaro force-pushed the fix/point-shape-click-selection branch from 0891737 to 23371dd Compare March 10, 2026 22:25
@wkentaro wkentaro self-assigned this Mar 10, 2026
@wkentaro wkentaro added the fix label Mar 10, 2026
@wkentaro wkentaro added this to the v6.0.0 milestone Mar 10, 2026
@wkentaro wkentaro merged commit b3e06e9 into main Mar 10, 2026
4 checks passed
@wkentaro wkentaro deleted the fix/point-shape-click-selection branch March 10, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shape whose shape_type is "point" cannot be easily deleted

1 participant