PostGIS  2.3.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 560 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().

561 {
562  int i, end;
563  char *ptr;
566  const POINT2D *pt;
567 
568  double f = 1.0;
569  double dx, dy, x, y, accum_x, accum_y;
570 
571  ptr = output;
572 
573  if (precision >= 0)
574  {
575  f = pow(10, precision);
576  }
577 
578  if (close_ring) end = pa->npoints;
579  else end = pa->npoints - 1;
580 
581  /* Starting point */
582  pt = getPoint2d_cp(pa, 0);
583 
584  x = round(pt->x*f)/f;
585  y = round(pt->y*f)/f;
586 
587  if (fabs(x) < OUT_MAX_DOUBLE)
588  sprintf(sx, "%.*f", precision, x);
589  else
590  sprintf(sx, "%g", x);
592 
593  if (fabs(y) < OUT_MAX_DOUBLE)
594  sprintf(sy, "%.*f", precision, fabs(y) ? y * -1 : y);
595  else
596  sprintf(sy, "%g", fabs(y) ? y * -1 : y);
598 
599  ptr += sprintf(ptr,"%s %s l", sx, sy);
600 
601  /* accum */
602  accum_x = x;
603  accum_y = y;
604 
605  /* All the following ones */
606  for (i=1 ; i < end ; i++)
607  {
608  // lpt = pt;
609 
610  pt = getPoint2d_cp(pa, i);
611 
612  x = round(pt->x*f)/f;
613  y = round(pt->y*f)/f;
614  dx = x - accum_x;
615  dy = y - accum_y;
616 
617  if (fabs(dx) < OUT_MAX_DOUBLE)
618  sprintf(sx, "%.*f", precision, dx);
619  else
620  sprintf(sx, "%g", dx);
622 
623  /* SVG Y axis is reversed, an no need to transform 0 into -0 */
624  if (fabs(dy) < OUT_MAX_DOUBLE)
625  sprintf(sy, "%.*f", precision,
626  fabs(dy) ? dy * -1: dy);
627  else
628  sprintf(sy, "%g",
629  fabs(dy) ? dy * -1: dy);
631 
632  accum_x += dx;
633  accum_y += dy;
634 
635  ptr += sprintf(ptr," %s %s", sx, sy);
636  }
637 
638  return (ptr-output);
639 }
int npoints
Definition: liblwgeom.h:370
#define OUT_MAX_DOUBLE_PRECISION
void trim_trailing_zeros(char *num)
Definition: lwutil.c:252
double x
Definition: liblwgeom.h:327
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:485
uint8_t precision
Definition: cu_in_twkb.c:25
double y
Definition: liblwgeom.h:327
#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: