Commit 1368a51f authored by Darafei Praliaskouski's avatar Darafei Praliaskouski

Synchronize coordinate output functins.

Closes #3987
Closes https://github.com/postgis/postgis/pull/190


git-svn-id: http://svn.osgeo.org/postgis/trunk@16296 b70326c6-7e19-0410-871a-916f4a2858ee
parent fa6ba585
Pipeline #16140293 passed with stage
in 17 minutes and 4 seconds
......@@ -35,7 +35,7 @@
#include <sys/wait.h> /* for WEXITSTATUS */
#include "liblwgeom.h"
#include "liblwgeom_internal.h" /* for trim_trailing_zeros */
#include "liblwgeom_internal.h"
#include "lwgeom_log.h"
#include "styles.h"
......@@ -46,7 +46,6 @@
// Some global styling variables
char *imageSize = "200x200";
int getStyleName(char **styleName, char* line);
static void
......@@ -70,8 +69,8 @@ checked_system(const char* cmd)
static size_t
pointarrayToString(char *output, POINTARRAY *pa)
{
char x[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1];
char y[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
int i;
char *ptr = output;
......@@ -79,10 +78,10 @@ pointarrayToString(char *output, POINTARRAY *pa)
{
POINT2D pt;
getPoint2d_p(pa, i, &pt);
sprintf(x, "%f", pt.x);
trim_trailing_zeros(x);
sprintf(y, "%f", pt.y);
trim_trailing_zeros(y);
lwprint_double(pt.x, 10, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(pt.y, 10, y, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, " ");
ptr += sprintf(ptr, "%s,%s", x, y);
}
......@@ -102,9 +101,9 @@ pointarrayToString(char *output, POINTARRAY *pa)
static size_t
drawPoint(char *output, LWPOINT *lwp, LAYERSTYLE *styles)
{
char x[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1];
char y1[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1];
char y2[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y1[OUT_DOUBLE_BUFFER_SIZE];
char y2[OUT_DOUBLE_BUFFER_SIZE];
char *ptr = output;
POINTARRAY *pa = lwp->point;
POINT2D p;
......@@ -113,12 +112,9 @@ drawPoint(char *output, LWPOINT *lwp, LAYERSTYLE *styles)
LWDEBUGF(4, "%s", "drawPoint called");
LWDEBUGF( 4, "point = %s", lwgeom_to_ewkt((LWGEOM*)lwp) );
sprintf(x, "%f", p.x);
trim_trailing_zeros(x);
sprintf(y1, "%f", p.y);
trim_trailing_zeros(y1);
sprintf(y2, "%f", p.y + styles->pointSize);
trim_trailing_zeros(y2);
lwprint_double(p.x, 10, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(p.y, 10, y1, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(p.y + styles->pointSize, 10, y1, OUT_DOUBLE_BUFFER_SIZE);
ptr += sprintf(ptr, "-fill %s -strokewidth 0 ", styles->pointColor);
ptr += sprintf(ptr, "-draw \"circle %s,%s %s,%s", x, y1, x, y2);
......
......@@ -406,7 +406,7 @@ test_lwgeom_segmentize2d(void)
LWGEOM *linein = lwgeom_from_wkt("LINESTRING(0 0,10 0)", LW_PARSER_CHECK_NONE);
LWGEOM *lineout = lwgeom_segmentize2d(linein, 5);
char *strout = lwgeom_to_ewkt(lineout);
CU_ASSERT_STRING_EQUAL(strout, "LINESTRING(0 0,5 0,10 0)");
ASSERT_STRING_EQUAL(strout, "LINESTRING(0 0,5 0,10 0)");
lwfree(strout);
lwgeom_free(linein);
lwgeom_free(lineout);
......@@ -446,7 +446,7 @@ test_lwgeom_segmentize2d(void)
/* NOT INTERRUPTED */
lineout = lwgeom_segmentize2d(linein, 5);
strout = lwgeom_to_ewkt(lineout);
CU_ASSERT_STRING_EQUAL(strout, "LINESTRING(20 0,25 0,30 0)");
ASSERT_STRING_EQUAL(strout, "LINESTRING(20 0,25 0,30 0)");
lwfree(strout);
lwgeom_free(linein);
lwgeom_free(lineout);
......@@ -463,19 +463,19 @@ test_lwgeom_locate_along(void)
/* ST_Locatealong(ST_GeomFromText('MULTILINESTRING M ((1 2 3, 5 4 5), (50 50 1, 60 60 200))'), 105) */
geom = lwgeom_from_wkt("MULTILINESTRING M ((1 2 3, 5 4 5), (50 50 1, 60 60 200))", LW_PARSER_CHECK_NONE);
out = lwgeom_locate_along(geom, measure, 0.0);
str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL);
str = lwgeom_to_wkt(out, WKT_ISO, 6, NULL);
lwgeom_free(geom);
lwgeom_free(out);
CU_ASSERT_STRING_EQUAL("MULTIPOINT M (55.226131 55.226131 105)", str);
ASSERT_STRING_EQUAL(str, "MULTIPOINT M (55.226131 55.226131 105)");
lwfree(str);
/* ST_Locatealong(ST_GeomFromText('MULTILINESTRING M ((1 2 3, 5 4 5), (50 50 1, 60 60 200))'), 105) */
geom = lwgeom_from_wkt("MULTILINESTRING M ((1 2 3, 3 4 2, 9 4 3), (1 2 3, 5 4 5), (50 50 1, 60 60 200))", LW_PARSER_CHECK_NONE);
out = lwgeom_locate_along(geom, measure, 0.0);
str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL);
str = lwgeom_to_wkt(out, WKT_ISO, 6, NULL);
lwgeom_free(geom);
lwgeom_free(out);
CU_ASSERT_STRING_EQUAL("MULTIPOINT M (55.226131 55.226131 105)", str);
ASSERT_STRING_EQUAL(str, "MULTIPOINT M (55.226131 55.226131 105)");
lwfree(str);
}
......@@ -959,7 +959,9 @@ test_lw_dist2d_ptarray_ptarrayarc(void)
rv = lw_dist2d_ptarray_ptarrayarc(lwline1->points, lwline2->points, &dl);
//printf("%s\n", cu_error_msg);
CU_ASSERT_EQUAL( rv, LW_FAILURE );
CU_ASSERT_STRING_EQUAL("lw_dist2d_ptarray_ptarrayarc called with non-arc input", cu_error_msg);
ASSERT_STRING_EQUAL(
cu_error_msg,
"lw_dist2d_ptarray_ptarrayarc called with non-arc input");
lwline_free(lwline2);
......@@ -997,10 +999,9 @@ test_lwgeom_tcpa(void)
lwgeom_free(g1);
lwgeom_free(g2);
ASSERT_DOUBLE_EQUAL(m, -1.0);
CU_ASSERT_STRING_EQUAL(
"Both input geometries must have a measure dimension",
cu_error_msg
);
ASSERT_STRING_EQUAL(
cu_error_msg,
"Both input geometries must have a measure dimension");
/* Invalid input, not linestrings */
......@@ -1010,10 +1011,8 @@ test_lwgeom_tcpa(void)
lwgeom_free(g1);
lwgeom_free(g2);
ASSERT_DOUBLE_EQUAL(m, -1.0);
CU_ASSERT_STRING_EQUAL(
"Both input geometries must be linestrings",
cu_error_msg
);
ASSERT_STRING_EQUAL(cu_error_msg,
"Both input geometries must be linestrings");
/* Invalid input, too short linestring */
......@@ -1025,9 +1024,11 @@ test_lwgeom_tcpa(void)
lwgeom_free(g2);
ASSERT_DOUBLE_EQUAL(dist, -77.0); /* not touched */
ASSERT_DOUBLE_EQUAL(m, -1.0);
CU_ASSERT_STRING_EQUAL(
"Both input lines must have at least 2 points", /* should be accepted ? */
cu_error_msg
ASSERT_STRING_EQUAL(
cu_error_msg,
"Both input lines must have at least 2 points" /* should be accepted
? */
);
/* Invalid input, empty linestring */
......@@ -1038,9 +1039,9 @@ test_lwgeom_tcpa(void)
lwgeom_free(g1);
lwgeom_free(g2);
ASSERT_DOUBLE_EQUAL(m, -1.0);
CU_ASSERT_STRING_EQUAL(
"Both input lines must have at least 2 points",
cu_error_msg
ASSERT_STRING_EQUAL(cu_error_msg,
"Both input lines must have at least 2 points"
);
/* Timeranges do not overlap */
......
......@@ -99,11 +99,11 @@ static void out_geojson_test_precision(void)
* only zeroes will be returned
* See http://trac.osgeo.org/postgis/ticket/2051#comment:11
*/
do_geojson_test(
"POINT(1E-300 -2E-200)",
"{\"type\":\"Point\",\"coordinates\":[0,-0]}",
NULL, 300, 0);
do_geojson_test("POINT(1E-300 -2E-200)",
"{\"type\":\"Point\",\"coordinates\":[0,0]}",
NULL,
300,
0);
}
......
......@@ -77,9 +77,7 @@ static void out_x3d3_test_precision(void)
/* huge data */
do_x3d3_test(
"POINT(1E300 -105E-153 4E300)'",
"1e+300 -0 4e+300",
NULL, 0, 0);
"POINT(1E300 -105E-153 4E300)'", "1e+300 0 4e+300", NULL, 0, 0);
}
......@@ -175,8 +173,6 @@ static void out_x3d3_test_option(void)
"SRID=4326;POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
"<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><GeoCoordinate geoSystem='\"GD\" \"WE\" \"latitude_first\"' point='10 15 3 6.464 13.536 3 5 10 3 6.464 6.464 3 10 5 3 13.536 6.464 3 15 10 3 13.536 13.536 3 ' /></IndexedFaceSet>",
NULL, 3, 3);
}
......
......@@ -340,8 +340,6 @@ static void test_ptarray_signed_area()
}
static void test_ptarray_unstroke()
{
LWGEOM *in, *out;
......@@ -391,7 +389,11 @@ static void test_ptarray_unstroke()
out = lwgeom_unstroke(in);
str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL);
// printf("%s\n", str);
ASSERT_STRING_EQUAL(str, "COMPOUNDCURVE((-3 -3,-1 0),CIRCULARSTRING(-1 0,0.70710678 0.70710678,0 -1),(0 -1,0 -1.5,0 -2),CIRCULARSTRING(0 -2,-0.70710678 -3.7071068,1 -3),(1 -3,5 5))");
ASSERT_STRING_EQUAL(
str,
"COMPOUNDCURVE((-3 -3,-1 0),CIRCULARSTRING(-1 0,0.70710678 "
"0.70710678,0 -1),(0 -1,0 -1.5,0 -2),CIRCULARSTRING(0 "
"-2,-0.70710678 -3.70710678,1 -3),(1 -3,5 5))");
lwgeom_free(in);
lwgeom_free(out);
lwfree(str);
......@@ -403,7 +405,10 @@ static void test_ptarray_unstroke()
out = lwgeom_unstroke(in);
str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL);
// printf("%s\n", str);
ASSERT_STRING_EQUAL(str, "COMPOUNDCURVE(CIRCULARSTRING(-1 0,0.70710678 0.70710678,0 -1),CIRCULARSTRING(0 -1,-0.70710678 -2.7071068,1 -2))");
ASSERT_STRING_EQUAL(
str,
"COMPOUNDCURVE(CIRCULARSTRING(-1 0,0.70710678 0.70710678,0 "
"-1),CIRCULARSTRING(0 -1,-0.70710678 -2.70710678,1 -2))");
lwgeom_free(in);
lwgeom_free(out);
lwfree(str);
......@@ -720,14 +725,14 @@ static void test_ptarray_scale()
lwfree(wktout);
factor.x = 1; factor.y = 1; factor.z = -2;
wkt = "LINESTRING ZM (0 3 -4 3,2 6 -6 0,-4 -9 -0 -1,-6 0 2 -2)";
wkt = "LINESTRING ZM (0 3 -4 3,2 6 -6 0,-4 -9 0 -1,-6 0 2 -2)";
ptarray_scale(pa, &factor);
wktout = lwgeom_to_text(lwline_as_lwgeom(line));
ASSERT_STRING_EQUAL(wktout, wkt);
lwfree(wktout);
factor.x = 1; factor.y = 1; factor.z = 1; factor.m = 2;
wkt = "LINESTRING ZM (0 3 -4 6,2 6 -6 0,-4 -9 -0 -2,-6 0 2 -4)";
wkt = "LINESTRING ZM (0 3 -4 6,2 6 -6 0,-4 -9 0 -2,-6 0 2 -4)";
ptarray_scale(pa, &factor);
wktout = lwgeom_to_text(lwline_as_lwgeom(line));
ASSERT_STRING_EQUAL(wktout, wkt);
......
......@@ -141,7 +141,8 @@
#define OUT_SHOW_DIGS_DOUBLE 20
#define OUT_MAX_DOUBLE_PRECISION 15
#define OUT_MAX_DIGS_DOUBLE (OUT_SHOW_DIGS_DOUBLE + 2) /* +2 mean add dot and sign */
#define OUT_DOUBLE_BUFFER_SIZE \
OUT_MAX_DIGS_DOUBLE + OUT_MAX_DOUBLE_PRECISION + 1
/**
* Constants for point-in-polygon return values
......@@ -480,8 +481,7 @@ double gbox_angular_width(const GBOX* gbox);
int gbox_centroid(const GBOX* gbox, POINT2D* out);
/* Utilities */
void trim_trailing_zeros(char *num);
int lwprint_double(double d, int maxdd, char* buf, size_t bufsize);
extern uint8_t MULTITYPE[NUMTYPES];
extern lwinterrupt_callback *_lwgeom_interrupt_callback;
......
......@@ -676,61 +676,19 @@ asgeojson_geom_buf(const LWGEOM *geom, char *output, GBOX *bbox, int precision)
return (ptr-output);
}
/*
* Print an ordinate value using at most the given number of decimal digits
*
* The actual number of printed decimal digits may be less than the
* requested ones if out of significant digits.
*
* The function will not write more than maxsize bytes, including the
* terminating NULL. Returns the number of bytes that would have been
* written if there was enough space (excluding terminating NULL).
* So a return of ``bufsize'' or more means that the string was
* truncated and misses a terminating NULL.
*
* TODO: export ?
*
*/
static int
lwprint_double(double d, int maxdd, char *buf, size_t bufsize)
{
double ad = fabs(d);
int ndd = ad < 1 ? 0 : floor(log10(ad))+1; /* non-decimal digits */
if (fabs(d) < OUT_MAX_DOUBLE)
{
if ( maxdd > (OUT_MAX_DOUBLE_PRECISION - ndd) ) maxdd -= ndd;
return snprintf(buf, bufsize, "%.*f", maxdd, d);
}
else
{
return snprintf(buf, bufsize, "%g", d);
}
}
static size_t
pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
{
uint32_t i;
char *ptr;
#define BUFSIZE OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION
char x[BUFSIZE+1];
char y[BUFSIZE+1];
char z[BUFSIZE+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
char z[OUT_DOUBLE_BUFFER_SIZE];
assert ( precision <= OUT_MAX_DOUBLE_PRECISION );
/* Ensure a terminating NULL at the end of buffers
* so that we don't need to check for truncation
* inprint_double */
x[BUFSIZE] = '\0';
y[BUFSIZE] = '\0';
z[BUFSIZE] = '\0';
ptr = output;
/* TODO: rewrite this loop to be simpler and possibly quicker */
/* TODO: rewrite this loop to be simpler and possibly quicker */
if (!FLAGS_GET_Z(pa->flags))
{
for (i=0; i<pa->npoints; i++)
......@@ -738,10 +696,10 @@ pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
const POINT2D *pt;
pt = getPoint2d_cp(pa, i);
lwprint_double(pt->x, precision, x, BUFSIZE);
trim_trailing_zeros(x);
lwprint_double(pt->y, precision, y, BUFSIZE);
trim_trailing_zeros(y);
lwprint_double(
pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, ",");
ptr += sprintf(ptr, "[%s,%s]", x, y);
......@@ -754,12 +712,12 @@ pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
const POINT3DZ *pt;
pt = getPoint3dz_cp(pa, i);
lwprint_double(pt->x, precision, x, BUFSIZE);
trim_trailing_zeros(x);
lwprint_double(pt->y, precision, y, BUFSIZE);
trim_trailing_zeros(y);
lwprint_double(pt->z, precision, z, BUFSIZE);
trim_trailing_zeros(z);
lwprint_double(
pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->z, precision, z, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, ",");
ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
......@@ -769,8 +727,6 @@ pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
return (ptr-output);
}
/**
* Returns maximum size of rendered pointarray in bytes.
*/
......
......@@ -663,9 +663,9 @@ pointArray_toGML2(POINTARRAY *pa, char *output, int precision)
{
uint32_t i;
char *ptr;
char x[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char y[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char z[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
char z[OUT_DOUBLE_BUFFER_SIZE];
ptr = output;
......@@ -676,17 +676,10 @@ pointArray_toGML2(POINTARRAY *pa, char *output, int precision)
const POINT2D *pt;
pt = getPoint2d_cp(pa, i);
if (fabs(pt->x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt->x);
else
sprintf(x, "%g", pt->x);
trim_trailing_zeros(x);
if (fabs(pt->y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, pt->y);
else
sprintf(y, "%g", pt->y);
trim_trailing_zeros(y);
lwprint_double(
pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, " ");
ptr += sprintf(ptr, "%s,%s", x, y);
......@@ -698,24 +691,12 @@ pointArray_toGML2(POINTARRAY *pa, char *output, int precision)
{
const POINT3DZ *pt;
pt = getPoint3dz_cp(pa, i);
if (fabs(pt->x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt->x);
else
sprintf(x, "%g", pt->x);
trim_trailing_zeros(x);
if (fabs(pt->y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, pt->y);
else
sprintf(y, "%g", pt->y);
trim_trailing_zeros(y);
if (fabs(pt->z) < OUT_MAX_DOUBLE)
sprintf(z, "%.*f", precision, pt->z);
else
sprintf(z, "%g", pt->z);
trim_trailing_zeros(z);
lwprint_double(
pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->z, precision, z, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, " ");
ptr += sprintf(ptr, "%s,%s,%s", x, y, z);
......@@ -1910,9 +1891,9 @@ pointArray_toGML3(POINTARRAY *pa, char *output, int precision, int opts)
{
uint32_t i;
char *ptr;
char x[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char y[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char z[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
char z[OUT_DOUBLE_BUFFER_SIZE];
ptr = output;
......@@ -1922,18 +1903,10 @@ pointArray_toGML3(POINTARRAY *pa, char *output, int precision, int opts)
{
const POINT2D *pt;
pt = getPoint2d_cp(pa, i);
if (fabs(pt->x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt->x);
else
sprintf(x, "%g", pt->x);
trim_trailing_zeros(x);
if (fabs(pt->y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, pt->y);
else
sprintf(y, "%g", pt->y);
trim_trailing_zeros(y);
lwprint_double(
pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, " ");
if (IS_DEGREE(opts))
......@@ -1949,23 +1922,12 @@ pointArray_toGML3(POINTARRAY *pa, char *output, int precision, int opts)
const POINT3DZ *pt;
pt = getPoint3dz_cp(pa, i);
if (fabs(pt->x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt->x);
else
sprintf(x, "%g", pt->x);
trim_trailing_zeros(x);
if (fabs(pt->y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, pt->y);
else
sprintf(y, "%g", pt->y);
trim_trailing_zeros(y);
if (fabs(pt->z) < OUT_MAX_DOUBLE)
sprintf(z, "%.*f", precision, pt->z);
else
sprintf(z, "%g", pt->z);
trim_trailing_zeros(z);
lwprint_double(
pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt->z, precision, z, OUT_DOUBLE_BUFFER_SIZE);
if ( i ) ptr += sprintf(ptr, " ");
if (IS_DEGREE(opts))
......
......@@ -119,24 +119,14 @@ static size_t
assvg_point_buf(const LWPOINT *point, char * output, int circle, int precision)
{
char *ptr=output;
char x[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char y[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
POINT2D pt;
getPoint2d_p(point->point, 0, &pt);
if (fabs(pt.x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt.x);
else
sprintf(x, "%g", pt.x);
trim_trailing_zeros(x);
/* SVG Y axis is reversed, an no need to transform 0 into -0 */
if (fabs(pt.y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, fabs(pt.y) ? pt.y * -1 : pt.y);
else
sprintf(y, "%g", fabs(pt.y) ? pt.y * -1 : pt.y);
trim_trailing_zeros(y);
lwprint_double(pt.x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(-pt.y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
if (circle) ptr += sprintf(ptr, "x=\"%s\" y=\"%s\"", x, y);
else ptr += sprintf(ptr, "cx=\"%s\" cy=\"%s\"", x, y);
......@@ -561,8 +551,8 @@ pointArray_svg_rel(POINTARRAY *pa, char *output, int close_ring, int precision)
{
int i, end;
char *ptr;
char sx[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char sy[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char sx[OUT_DOUBLE_BUFFER_SIZE];
char sy[OUT_DOUBLE_BUFFER_SIZE];
const POINT2D *pt;
double f = 1.0;
......@@ -584,18 +574,8 @@ pointArray_svg_rel(POINTARRAY *pa, char *output, int close_ring, int precision)
x = round(pt->x*f)/f;
y = round(pt->y*f)/f;
if (fabs(x) < OUT_MAX_DOUBLE)
sprintf(sx, "%.*f", precision, x);
else
sprintf(sx, "%g", x);
trim_trailing_zeros(sx);
if (fabs(y) < OUT_MAX_DOUBLE)
sprintf(sy, "%.*f", precision, fabs(y) ? y * -1 : y);
else
sprintf(sy, "%g", fabs(y) ? y * -1 : y);
trim_trailing_zeros(sy);
lwprint_double(x, precision, sx, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(-y, precision, sy, OUT_DOUBLE_BUFFER_SIZE);
ptr += sprintf(ptr,"%s %s l", sx, sy);
/* accum */
......@@ -614,20 +594,8 @@ pointArray_svg_rel(POINTARRAY *pa, char *output, int close_ring, int precision)
dx = x - accum_x;
dy = y - accum_y;
if (fabs(dx) < OUT_MAX_DOUBLE)
sprintf(sx, "%.*f", precision, dx);
else
sprintf(sx, "%g", dx);
trim_trailing_zeros(sx);
/* SVG Y axis is reversed, an no need to transform 0 into -0 */
if (fabs(dy) < OUT_MAX_DOUBLE)
sprintf(sy, "%.*f", precision,
fabs(dy) ? dy * -1: dy);
else
sprintf(sy, "%g",
fabs(dy) ? dy * -1: dy);
trim_trailing_zeros(sy);
lwprint_double(dx, precision, sx, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(-dy, precision, sy, OUT_DOUBLE_BUFFER_SIZE);
accum_x += dx;
accum_y += dy;
......@@ -647,8 +615,8 @@ pointArray_svg_abs(POINTARRAY *pa, char *output, int close_ring, int precision)
{
int i, end;
char *ptr;
char x[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char y[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
POINT2D pt;
ptr = output;
......@@ -660,18 +628,8 @@ pointArray_svg_abs(POINTARRAY *pa, char *output, int close_ring, int precision)
{
getPoint2d_p(pa, i, &pt);
if (fabs(pt.x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt.x);
else
sprintf(x, "%g", pt.x);
trim_trailing_zeros(x);
/* SVG Y axis is reversed, an no need to transform 0 into -0 */
if (fabs(pt.y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, fabs(pt.y) ? pt.y * -1:pt.y);
else
sprintf(y, "%g", fabs(pt.y) ? pt.y * -1:pt.y);
trim_trailing_zeros(y);
lwprint_double(pt.x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(-pt.y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
if (i == 1) ptr += sprintf(ptr, " L ");
else if (i) ptr += sprintf(ptr, " ");
......
......@@ -85,6 +85,7 @@ static void ptarray_to_wkt_sb(const POINTARRAY *ptarray, stringbuffer_t *sb, int
/* OGC only includes X/Y */
uint32_t dimensions = 2;
uint32_t i, j;
char coord[OUT_DOUBLE_BUFFER_SIZE];
/* ISO and extended formats include all dimensions */
if ( variant & ( WKT_ISO | WKT_EXTENDED ) )
......@@ -108,7 +109,11 @@ static void ptarray_to_wkt_sb(const POINTARRAY *ptarray, stringbuffer_t *sb, int
/* Spaces before every ordinate but the first */
if ( j > 0 )
stringbuffer_append(sb, " ");
stringbuffer_aprintf(sb, "%.*g", precision, dbl_ptr[j]);
lwprint_double(dbl_ptr[j],
precision,
coord,
OUT_DOUBLE_BUFFER_SIZE);
stringbuffer_append(sb, coord);
}
}
......@@ -657,15 +662,16 @@ static void lwgeom_to_wkt_sb(const LWGEOM *geom, stringbuffer_t *sb, int precisi
}
/**
* WKT emitter function. Allocates a new *char and fills it with the WKT
* representation. If size_out is not NULL, it will be set to the size of the
* allocated *char.
*
* @param variant Bitmasked value, accepts one of WKT_ISO, WKT_SFSQL, WKT_EXTENDED.
* @param precision Number of significant digits in the output doubles.
* @param size_out If supplied, will return the size of the returned string,
* including the null terminator.
*/
* WKT emitter function. Allocates a new *char and fills it with the WKT
* representation. If size_out is not NULL, it will be set to the size of the
* allocated *char.
*
* @param variant Bitmasked value, accepts one of WKT_ISO, WKT_SFSQL,
* WKT_EXTENDED.
* @param precision Maximal number of digits after comma in the output doubles.
* @param size_out If supplied, will return the size of the returned string,
* including the null terminator.
*/
char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
{
stringbuffer_t *sb;
......
......@@ -498,9 +498,9 @@ static int
ptarray_to_x3d3_sb(POINTARRAY *pa, int precision, int opts, int is_closed, stringbuffer_t *sb )
{
uint32_t i;
char x[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char y[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char z[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
char x[OUT_DOUBLE_BUFFER_SIZE];
char y[OUT_DOUBLE_BUFFER_SIZE];
char z[OUT_DOUBLE_BUFFER_SIZE];
if ( ! FLAGS_GET_Z(pa->flags) )
{
......@@ -512,17 +512,10 @@ ptarray_to_x3d3_sb(POINTARRAY *pa, int precision, int opts, int is_closed, strin
POINT2D pt;
getPoint2d_p(pa, i, &pt);
if (fabs(pt.x) < OUT_MAX_DOUBLE)
sprintf(x, "%.*f", precision, pt.x);
else
sprintf(x, "%g", pt.x);
trim_trailing_zeros(x);
if (fabs(pt.y) < OUT_MAX_DOUBLE)
sprintf(y, "%.*f", precision, pt.y);
else
sprintf(y, "%g", pt.y);
trim_trailing_zeros(y);
lwprint_double(
pt.x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
lwprint_double(
pt.y, precision, y, OUT_DOUBLE_BUFFER_SIZE);