PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ pointArray_svg_rel()

static size_t pointArray_svg_rel ( POINTARRAY pa,
char *  output,
int  close_ring,
int  precision 
)
static

Definition at line 546 of file lwout_svg.c.

References getPoint2d_cp(), POINTARRAY::npoints, OUT_MAX_DIGS_DOUBLE, OUT_MAX_DOUBLE, OUT_MAX_DOUBLE_PRECISION, trim_trailing_zeros(), pixval::x, POINT2D::x, pixval::y, and POINT2D::y.

Referenced by assvg_line_buf(), and assvg_polygon_buf().

547 {
548  int i, end;
549  char *ptr;
552  const POINT2D *pt;
553 
554  double f = 1.0;
555  double dx, dy, x, y, accum_x, accum_y;
556 
557  ptr = output;
558 
559  if (precision >= 0)
560  {
561  f = pow(10, precision);
562  }
563 
564  if (close_ring) end = pa->npoints;
565  else end = pa->npoints - 1;
566 
567  /* Starting point */
568  pt = getPoint2d_cp(pa, 0);
569 
570  x = round(pt->x*f)/f;
571  y = round(pt->y*f)/f;
572 
573  if (fabs(x) < OUT_MAX_DOUBLE)
574  sprintf(sx, "%.*f", precision, x);
575  else
576  sprintf(sx, "%g", x);
578 
579  if (fabs(y) < OUT_MAX_DOUBLE)
580  sprintf(sy, "%.*f", precision, fabs(y) ? y * -1 : y);
581  else
582  sprintf(sy, "%g", fabs(y) ? y * -1 : y);
584 
585  ptr += sprintf(ptr,"%s %s l", sx, sy);
586 
587  /* accum */
588  accum_x = x;
589  accum_y = y;
590 
591  /* All the following ones */
592  for (i=1 ; i < end ; i++)
593  {
594  // lpt = pt;
595 
596  pt = getPoint2d_cp(pa, i);
597 
598  x = round(pt->x*f)/f;
599  y = round(pt->y*f)/f;
600  dx = x - accum_x;
601  dy = y - accum_y;
602 
603  if (fabs(dx) < OUT_MAX_DOUBLE)
604  sprintf(sx, "%.*f", precision, dx);
605  else
606  sprintf(sx, "%g", dx);
608 
609  /* SVG Y axis is reversed, an no need to transform 0 into -0 */
610  if (fabs(dy) < OUT_MAX_DOUBLE)
611  sprintf(sy, "%.*f", precision,
612  fabs(dy) ? dy * -1: dy);
613  else
614  sprintf(sy, "%g",
615  fabs(dy) ? dy * -1: dy);
617 
618  accum_x += dx;
619  accum_y += dy;
620 
621  ptr += sprintf(ptr," %s %s", sx, sy);
622  }
623 
624  return (ptr-output);
625 }
int npoints
Definition: liblwgeom.h:355
#define OUT_MAX_DOUBLE_PRECISION
void trim_trailing_zeros(char *num)
Definition: lwutil.c:224
double x
Definition: liblwgeom.h:312
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:472
uint8_t precision
Definition: cu_in_twkb.c:25
double y
Definition: liblwgeom.h:312
#define OUT_MAX_DOUBLE
#define OUT_MAX_DIGS_DOUBLE
Here is the call graph for this function:
Here is the caller graph for this function: