Re: Rounding with #xywh=percent:25,25,50,50

On Wed, 06 Apr 2011 16:01:20 +0200, Jack Jansen <Jack.Jansen@cwi.nl> wrote:

>
> On Apr 6, 2011, at 15:14 , Raphaël Troncy wrote:
>
>>> Yeah, I think we need to be more specific. My suggestion is to round
>>> up, but am curious what ppl think.
>>
>> +1 ... and added to list of items to discuss next week.
>
>
> ... And just after I pressed "send" I realised that "rounding up" isn't  
> the right term. I think we should round in such a way that we enclose at  
> least the specified region. Therefore, X and Y should be numerically  
> rounded down, and width and height numerically up.

The doesn't quite have the effect of enclosing the specified region, as  
(10.5, 10.5, 20, 20) would get clamped to (10, 10, 20, 20), which misses  
0.5 px on the right and bottom. Similarly, (10.9, 10.9, 10.9, 10.9) would  
get clamped to (10, 10, 11, 11), which misses 0.8 px on the right and  
bottom. (The worst case with .999999 goes towards missing a whole  
row/column.)

The formula for always enclosing the region would be:

x' = floor(x)
y' = floor(y)
w' = ceil(x+w) - floor(x)
h' = ceil(y+h) - floor(y)

-- 
Philip Jägenstedt
Core Developer
Opera Software

Received on Wednesday, 6 April 2011 16:12:58 UTC