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

1 Aufruf
Direkt zur ersten ungelesenen Nachricht

Klaus Förster

ungelesen,
20.11.2008, 02:43:0920.11.08
an postgi...@postgis.refractions.net
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

--
Klaus Förster
Institut für Geographie
Universität Innsbruck
A-6020 Innsbruck, Innrain 52
Tel.: +43 (0)512 507 5434
_______________________________________________
postgis-users mailing list
postgi...@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Mark Cave-Ayland

ungelesen,
20.11.2008, 05:45:0420.11.08
an PostGIS Users Discussion
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

Klaus Förster

ungelesen,
20.11.2008, 05:58:2420.11.08
an PostGIS Users Discussion
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

Mark Cave-Ayland

ungelesen,
20.11.2008, 06:29:5020.11.08
an PostGIS Users Discussion
Klaus Förster wrote:

> 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


Hi Klaus,

In that case I don't know - the original patch was submitted by Eduin
Carillo so he would be the right person to ask. The only thing I can
think of is that it is supposed to suppress "minus 0" from appearing in
the KML output (as +/- 0 are separate numbers in IEEE-754 floating point
numbers), but even then I'm not 100% convinced by the logic.


ATB,

Mark.

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

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten