GNOME Bugzilla – Bug 143887
selection rectangle "move" when start at the top-right corner
Last modified: 2005-03-18 01:59:38 UTC
create a picture (say 64 x 64) zoom a lit bit. start a rectangle selection which from the top right corner of the picture. you can see the right side of the selection doesn't stay on the right border of the picture. (the pb appears when you extend the selction on the left, not to bottom). Hope you will understand the problem.
Difficult to understand since you need to start exactly at the right edge of the image (not in the canvas beyond the right edge). This isn't really common usage so I am lowering the severity of this report to minor.
This problem occurs when selection goes in any direction except down-right from the starting point and the starting point is close to a pixel center. It doesn't matter where the on the canvas the selection starts. The easiest way to reproduce it is the create a picture and zoom to 200% and select in a up-left direction. You may have to try a few times to trigger it. Ellipse selection is also affected. The cause is rounding errors in gimprectselecttool.c, I have a patch that fixes the problem and IMO cleans up the code. I'm a gimp coding newbie however, so it is probably full of errors =).
Created attachment 38366 [details] [review] selection tool rewrite
The patch looks reasonable but it would be nice if you could add a short explanation of the approach that your patch takes.
Sure, the first thing I did was to add a starting point that keeps the coordinate where the mouse button was first pressed. In the motion function the selection coordinate, width and height are calculated from the starting point and the current cursor coordinate. This is unlike previously when the selection coordinate, width and height where calculated from the previous coordinate, width and height and the current coordinate. I wanted to avoid this because of the risk of rounding errors stacking up. It also made the code simpler. Second change was to keep the calculation of absolute width and height separate from the direction of the selection to simplify the code. Third change was to add proper rounding to fix the bug. Fourth change was changing variable types from gdoubles to gints as they would always have integer values anyway.
Applied to the HEAD branch so that it gets some testing: 2005-03-07 Sven Neumann <sven@gimp.org> * app/tools/gimpellipseselecttool.c * app/tools/gimprectselecttool.[ch]: applied a patch by Nils Bjorklund that should fix bug #143887 (selection rectangle "moves" when starting at the top-right corner).
I've merged this change into the gimp-2-2 branch now. Closing as FIXED. Nils, thanks a lot for the patch.