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

Klaus Förster klaus.foerster at uibk.ac.at
Thu Nov 20 02:58:24 PST 2008


yes Mark, I know that the axis is reversed, but I don't get the point 
why the if clause is needed: fabs(pt->y) always returns a positive value 
or 0 and multiplying 0 with -1 doesn't do any harm. So why not use 
sprintf(y, "%.*f", precision, pt->y * -1) and skip the test?

Klaus

Mark Cave-Ayland wrote:
> 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.
> 

-- 
Klaus Förster
Institut für Geographie
Universität Innsbruck
A-6020 Innsbruck, Innrain 52
Tel.: +43 (0)512 507 5434



More information about the postgis-users mailing list