8000 Prevent Shapes corruption when drawing tiny polygons with lasso by Czaki · Pull Request #7914 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prevent Shapes corruption when drawing tiny polygons with lasso #7914

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 6 commits into from
May 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions napari/layers/shapes/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from napari.utils.events import Event
from napari.utils.events.custom_types import Array
from napari.utils.misc import ensure_iterable
from napari.utils.notifications import show_warning
from napari. 8000 utils.translations import trans

DEFAULT_COLOR_CYCLE = np.array([[1, 0, 1, 1], [0, 1, 0, 1]])
Expand Down Expand Up @@ -2642,18 +2643,31 @@ def _finish_drawing(self, event=None) -> None:
self._data_view.edit(index, vertices[:-1])
if self._mode in {Mode.ADD_POLYGON, Mode.ADD_POLYGON_LASSO}:
vertices = self._data_view.shapes[index].data
if self._mode == Mode.ADD_POLYGON_LASSO:
prev_vertices = len(vertices)
vertices = rdp(
vertices,
epsilon=get_settings().experimental.rdp_epsilon,
)
if len(vertices) <= 3 and prev_vertices > 3:
# https://github.com/napari/napari/issues/7903
show_warning(
trans._(
'Polygons must have three or more vertices. '
'Lasso polygons are simplified using the '
'RDP algorithm, which may cause polygons '
'smaller than RDP epsilon to disappear. If '
'you face issues drawing small polygons, '
'try reducing napari > Settings > '
'Experimental > RDP epsilon. '
),
)
if len(vertices) <= 3:
self._data_view.remove(index)
# Clear selected data to prevent issues.
# See https://github.com/napari/napari/pull/6912#discussion_r1601169680
self.selected_data.clear()
elif self._mode == Mode.ADD_POLYGON:
self._data_view.edit(index, vertices[:-1])
else:
vertices = rdp(
vertices,
epsilon=get_settings().experimental.rdp_epsilon,
)
self._data_view.edit(
index,
vertices[:-1],
Expand Down
Loading
0