GNOME Bugzilla – Bug 109475
script-fu-selection-round is off by one in certain cases
Last modified: 2004-12-22 21:47:04 UTC
When making a rectangle with round bordes using script-fu-selection-round it sometimes creates a non-antialiased step, clearly visible when activating qmask. How to reproduce: 1. Create a new image. 2. Create a rectangular selection inside it. 3. Select <image>/Script-Fu/Selection/Round... 4. Set the relative radius to 0.2 and press OK. 5. Activate QuickMask. A zoom on the bottom or rightmost part of the rectangle will reveal an aliased step near the end of the circle. It seems to be caused by a problem with rounding in the script. Happens in all versions. Patch follows.
Created attachment 15292 [details] [review] Proposed patch for the off-by-one bug in selection-round.scm
Oops! The patch above breaks it the other way around (e.g. when radius = 0.5). Would need a (truncate x) function, but in its absence the following patch solves the problem. Forget about the +1 in the previous patch.
Created attachment 15293 [details] [review] New patch for the off-by-one selection-round bug
IIRC, SIOD has the trunc procedure. Why doesn't your patch use that instead of the ugly hack?
The SIOD docs say that there is a function called trunc (even if the standard one is truncate, according to r5rs; ref: <http://www.swiss.ai.mit.edu/~jaffer/r5rs_8.html#SEC55>) but it seems not to be implemented in Gimp. Apart from the fact that it does not work in the console, doing `grep -ri "trunc" plug-ins/script-fu' returns no results. I couldn't figure out any other way to do the same.
It seems you are right and we lack the trunc function. It would be worth to add the implementation and I think it should be rather trivial.
Created attachment 15611 [details] [review] Patch to add the trunc function to Script-Fu and solve bug #109475 the right way.
Is there any reason why your patch doesn't use trunc(3) to implement trunc?
Ah, I see, trunc(3) is only in C99. I've applied your patch as is: 2003-04-10 Sven Neumann <sven@gimp.org> * plug-ins/script-fu/interp_sliba.c * plug-ins/script-fu/scripts/selection-round.scm: applied a patch from Pedro Gimeno that adds the trunc() function to our scheme interpreter and fixes bug #109475 the right way.