8000 Fix moving of first/last vertex of polygons added in ring mode by Czaki · Pull Request #7942 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix moving of first/last vertex of polygons added in ring mode #7942

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 4 commits into from
Jun 21, 2025

Conversation

Czaki
Copy link
Collaborator
@Czaki Czaki commented May 17, 2025

References and relevant issues

Address problem pointed in #5770 (comment)

Description

If a polygon is added with same point as start and begin (implicit close) ring (same as geoJSON) and we use direct mode for edit, we move only one of this point, effectively adding an additional point to the polygon that is unexpected.

This PR fixes this, by moving both points at the same time.

@Czaki Czaki requested a review from psobolewskiPhD May 17, 2025 22:55
@Czaki Czaki added the bugfix PR with bugfix label May 17, 2025
@jni
Copy link
Member
jni commented May 19, 2025

I don't mind this as a band-aid, but I think we should consider using normalised vertex coordinates, without duplicates, when selecting vertices, and then using the inverse map from np.unique (or whatever function we've used to deduplicate vertices) to move all the corresponding vertices.

Happy to leave that for future PRs though.

@jni jni added this to the 0.6.2 milestone May 19, 2025
@jni jni changed the title Fix moving of first/last vertex of polygona added in ring mode Fix moving of first/last vertex of polygons added in ring mode May 19, 2025
@Czaki
Copy link
Collaborator Author
Czaki commented May 19, 2025

I don't mind this as a band-aid, but I think we should consider using normalised vertex coordinates, without duplicates, when selecting vertices, and then using the inverse map from np.unique (or whatever function we've used to deduplicate vertices) to move all the corresponding vertices.

We need to rewrite many aspects of the Shapes layer, so get this simple PR to address the problem and left rewrite for the future.

@Czaki Czaki modified the milestone: 0.6.2 May 19, 2025
Copy link
codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.96%. Comparing base (183e9fc) to head (ea05efb).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/napari/layers/shapes/_shapes_mouse_bindings.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7942      +/-   ##
==========================================
+ Coverage   92.93%   92.96%   +0.03%     
==========================================
  Files         647      647              
  Lines       60975    60979       +4     
==========================================
+ Hits        56665    56689      +24     
+ Misses       4310     4290      -20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@psobolewskiPhD
Copy link
Member
psobolewskiPhD commented May 19, 2025

When moving that double-vertex I still get
image

@Czaki
Copy link
Collaborator Author
Czaki commented May 19, 2025

Yes. It only fix problem of duplicated first/last point. Not interna 8000 l point for holes

@psobolewskiPhD
Copy link
Member

I think it's still letting me move just 1 though.

@psobolewskiPhD
Copy link
Member

Like here i just move the one that I think is the first/last based on coords (it's hard though):
image

notice the original vertex is there and the duplicate has moved -- or vice versa, but there is an extra one now

@psobolewskiPhD
Copy link
Member
psobolewskiPhD commented May 19, 2025

Or look at the outer ring, again I think this is the duplicate?
Untitled

@jni
Copy link
Member
jni commented May 20, 2025

@psobolewskiPhD this polygon is not a ring. Compare the first and last vertices:

[[-28.58, 196.34], [-28.08, 196.82], [-28.36, 197.22], [-28.78, 197.39],

[-29.26, 209.33], [-28.96, 208.98]]

@psobolewskiPhD
Copy link
Member

I wanted to loop back to this, but pulling it down it seems broken by the src layout change. 😢

@Czaki Czaki requested a review from a team as a code owner June 15, 2025 15:05
@psobolewskiPhD
Copy link
Member

OK I tested with
viewer.layers[0].add_polygons([[[0, 0], [100, 0], [100, 100], [0, 100], [0,0]]])
And everything appears to work as advertised.

@TimMonko TimMonko added the ready to merge Last chance for comments! Will be merged in ~24h label Jun 19, 2025
@TimMonko TimMonko merged commit fe473b7 into napari:main Jun 21, 2025
41 checks passed
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR with bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0