Skip to content

Fix for #2009 (empty rectangle issue)#2022

Open
Lehonti wants to merge 3 commits intoPintaProject:masterfrom
Lehonti:fix/zero_rectangle_select
Open

Fix for #2009 (empty rectangle issue)#2022
Lehonti wants to merge 3 commits intoPintaProject:masterfrom
Lehonti:fix/zero_rectangle_select

Conversation

@Lehonti
Copy link
Contributor

@Lehonti Lehonti commented Mar 7, 2026

Closes #2009

Notice that OnMouseDown rounds the coordinates and OnMouseUp doesn't, so when testing for equality the coordinates are different, which shouldn't happen

@cameronwhite
Copy link
Member

Yeah this definitely contributes to the issue - we should have a common function for doing this rounding (it also happens inside the handle for the OnMouseMove event, which is inconsistent )

In my testing I was still able to occasionally get it to produce a zero-size rectangle, by tapping my laptop's trackpad while zoomed in.
After adding some printouts the (before rounding) mouse up position is slightly different, and there wasn't a mouse move event.

down 476.6666666666667, 246.66666666666666
up 476.6666666666667, 246.33333333333334

The logic in HasDragged for transforming to view coordinates is suspicious, because when you're zoomed in you can move the mouse by one unit in view space, and still end up with a zero size rectangle in canvas space

@Lehonti
Copy link
Contributor Author

Lehonti commented Mar 9, 2026

@cameronwhite I see. Maybe after these new changes it will work better

@cameronwhite
Copy link
Member

Thanks! Having the common function is much nicer

I can still reproduce the same issue though so I think it's somewhat separate from the rounding - being zoomed in far makes it much easier to hit.
I can do some more investigation, but from the printouts I added yesterday it seemed that the issue is that the mouse-up event might be at a slightly different location without reporting that first as a mouse move (and this might be different enough to round to a different canvas coordinate). So HasDragged() can return true (especially when zoomed since it does its comparison in screen coordinates, rather than canvas coordinates) but we don't actually expand the initial empty rectangle with the new position from the mouse up event.

Maybe this needs to be handled at a lower level like BaseTool or the canvas event handlers though. Very likely there are other tools which also have similar assumptions that the "mouse up" event happens at the same position as the last "mouse move" event, and sending out an extra "mouse move" event could work?

@Lehonti Lehonti changed the title Fix for #2009 Fix for #2009 (empty rectangle issue) Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Select Tool] Clicking with the select tool when zoomed in selects an area of 0 pixels

2 participants