|
Boost : |
From: Dave Harris (brangdon_at_[hidden])
Date: 2004-12-16 15:48:25
In-Reply-To: <BAY101-F20FDD5860C530B8D6ADE17A0AC0_at_phx.gbl>
msclrhd_at_[hidden] (Reece Dunn) wrote (abridged):
> struct position{ float x; float y; };
> struct size{ float dx; float dy; };
> struct area
> {
> float top; float left;
> float width; float height;
> };
Why float rather than double?
I'd want to avoid unnecessary conversions, so I'd want to use the same
units all the way through. At the moment my document model uses integers,
scaled not to 96 dpi pixels but to logical units which are 72,000 dpi.
With 32-bit ints that gives a drawing area of about 30,000 inches. Using
floats would give only 23 bits of precision, which reduces the drawing
area to around 60 inches, which is getting a bit small. I'd prefer to
avoid using fractional units because of exactness issues with 1/3 etc.
I don't have a strong opinion on floating point generally. Sometimes I
want to use pixel rounding, and sometimes I want to transform coordinates
without losing accuracy. Adobe's PDF is an example which uses a floating
point coordinates, albeit at 72 dpi rather than 72,000.
I do know that most of the time, using integers works fine. You don't lose
precision because you only ever transform the coordinates once. For
bounding box transforms you round left/top with floor and right/bottom
with ceil. For anti-aliasing you transform, eg, from 72,000 dpi to 384 dpi
to get 1/4 pixel precision.
-- Dave Harris, Nottingham, UK
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk