Le 26/03/2015 17:00, Enrico Forestieri a écrit :
On Thu, Mar 26, 2015 at 12:09:41PM +0100, Jean-Marc Lasgouttes wrote:

On a related idea, could you tell us what is the intent of the
following code?

        int iconsize = Length(1, Length::EM).inPixels(1);
        percent_scale = (100 * iconsize + imgsize / 2)/imgsize;

Sorry, I thought it was self-explanatory. The first line sets iconsize
to be equal to the number of pixels corresponding to 1em (that should
be the width in pixels of the letter 'M' as shown on screen). The second
line computes how much the actual image should be scaled to match the
wanted size (imgsize is the size in pixels of the image). It would
simply be 100*(iconsize/imgsize), but in that way I round up or down
the result to the integer nearest to the float value of the result.
I mean, 100*10/15 = 66.666, int(100*10/15) = 66, int((100*10+7)/15) = 67.

I understand now. I think this deserves a comment, especially since this looks like you forgot parentheses like "(iconsize + imgsize) /2".
I am not used to this trick in integer arithmetics.

JMarc

Reply via email to