[postgis-users] fabs() testing for y-coordinates in lwgeom_svg.c

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Thu Nov 20 02:45:04 PST 2008


Klaus Förster wrote:

> I've just checked the source of lwgeom_svg.c in postgis-1.3.4rc3 and 
> wonder what the fabs() testing in lines 243, 262, 303, 324 and 348 is 
> for. Why is it needed?
> 
> e.g. line 243:
> sprintf(y, "%.*f", precision, fabs(pt->y) > 0 ? (pt->y * -1) : pt->y);
> 
> thanks for any hints,
> 
> Klaus


Hi Klaus,

The trick is the use of the ? operator, and so the above logic reads:

if fabs(pt->y) > 0 then value = (pt->y * -1), otherwise value = pt->y

In other words, it inverts the Y-axis - presumably because SVG has a 
top-left origin point as opposed to a bottom-left origin point used by 
the majority of coordinate systems.


HTH,

Mark.

-- 
Mark Cave-Ayland
Sirius Corporation - The Open Source Experts
http://www.siriusit.co.uk
T: +44 870 608 0063



More information about the postgis-users mailing list