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

From: Philip Jägenstedt <philipj@opera.com>
Date: Tue, 03 Jan 2012 15:18:00 +0100
To: Raphaël Troncy <raphael.troncy@eurecom.fr>

```On Tue, 03 Jan 2012 14:31:08 +0100, Raphaël Troncy
<raphael.troncy@eurecom.fr> wrote:

> Hi Philip,
>
>> xywh=percent:a,b,c,d with a+c <= 100, b+d <= 100: the UA displays a
>> spatial fragment with coordinates (in pixel xywh format) floor(a/w*100),
>> floor(b/h*100), ceil(c/w*100), ceil(d/h*100) (the normal percent case).
>>
>> Unfortunately, the formula is wrong for the right and bottom edge, as
>> ceil(w) != ceil(x+w) - floor(x), try e.g. x=12.5 and w=50:
>>
>> ceil(50) = 50
>> ceil(12.5+50) - floor(12.5) = 63 - 12 = 51
>>
>> In other words, it is the right/bottom edge that must be ceil'd, not the
>> width/height.
>
> Arg! Thanks for the careful reading!
> So, would this text work?
>
>    xywh=percent:a,b,c,d with a+c <= 100, b+d <= 100:
>    the UA displays a  spatial fragment with coordinates (in pixel xywh
> format)
>      floor(a/w*100), floor(b/h*100), ceil((c+w)/w*100)-floor(a/w*100),
> ceil((d+h)/h*100)-floor(b/h*100)

It's actually very hard to parse this for me, I have to break it down to
make sense of it:

x_float = w*a/100
y_float = h*b/100
w_float = w*c/100
h_float = h*d/100

x_int = floor(x_float)
y_int = floor(y_float)
w_int = ceil(x_float+w_float) - floor(x_float)
h_int = ceil(y_float+h_float) - floor(y_float)

The most compact form I can make out of this is:

floor(w*a/100), floor(h*b/100), ceil(w*(a+c)/100)-floor(w*a/100),
ceil(h*(b+d)/100)-floor(h*b/100)

I think the spec would be better off with something less terse, and a
non-normative note that this is effectively rounding each edge outwards in
the image.

--
Philip Jägenstedt
Core Developer
Opera Software
```
Received on Tuesday, 3 January 2012 14:18:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 3 January 2012 14:18:28 GMT