W3C home > Mailing lists > Public > www-style@w3.org > March 2013

Re: [css3-background] round(N+0.5) with background-repeat: round

From: Simon Sapin <simon.sapin@exyr.org>
Date: Sat, 30 Mar 2013 22:47:27 +0100
Message-ID: <51575D6F.1030505@exyr.org>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
CC: Lea Verou <lea@w3.org>, www-style list <www-style@w3.org>
Le 26/03/2013 20:36, Tab Atkins Jr. a écrit :
> On Tue, Mar 26, 2013 at 12:13 PM, Lea Verou<lea@w3.org>  wrote:
>> >On Mar 26, 2013, at 19:20, Tab Atkins Jr. wrote:
>>> >>I believe in other cases, we've explicitly specified that it rounds up.
>> >
>> >What was the rationale? Usually images look better scaled down than scaled up.
> By "it", I meant "a number being rounded that is halfway between the
> two round targets", not images specifically.
>
> Given that this is deciding the behavior solely for the .5 case, not
> saying "all non-integer ratios round up to the next integer", the
> exact behavior doesn't really matter, and we should match what we do
> elsewhere in CSS.
>
> Finally, rounding up here means scaling the image down further, since
> a higher number means more repetitions, and less space per repeat. ^_^


Here is a test case:

http://hg.csswg.org/test/raw-file/5b86c3badd15/contributors/kozea/background-repeat-round-halfway-roundup.html

Both Trident and Presto round up. (Gecko and WebKit do not implement 
'round' yet.)

Rounding up (positive values) also matches the behavior of the "round()" 
function commonly found in programming languages:

C’s libm: http://linux.die.net/man/3/round
> round halfway cases away from zero

Python: http://docs.python.org/2/library/functions.html#round
> if two multiples are equally close, rounding is done away from 0

Javascript: 
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/round
> If the fractional portion of number is .5 or greater, the argument is
> rounded to the next higher integer.


I’m gonna go ahead and implement it that way in WeasyPrint.

Suggested spec change: add "Halfway cases are rounded up." after this 
sentence in the description of 'background-size':

> where round() is a function that returns the nearest natural number
> (integer greater than zero).


Note: implementations probably need something like max(round(v), 1) as 
most round(v) functions happily return 0 for v in [0, 0.5[

-- 
Simon Sapin
Received on Saturday, 30 March 2013 21:47:57 UTC

This archive was generated by hypermail 2.3.1 : Saturday, 30 March 2013 21:47:58 UTC