PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ptarray_chaikin()

static POINTARRAY* ptarray_chaikin ( POINTARRAY inpts,
int  preserve_endpoint,
int  isclosed 
)
static

Definition at line 31 of file lwchaikins.c.

32 {
33  uint32_t p, i, n_out_points=0, p1_set=0, p2_set=0;
34  POINT4D p1, p2;
36  double *dlist;
37  double deltaval, quarter_delta, val1, val2;
38  uint32_t ndims = 2 + ptarray_has_z(inpts) + ptarray_has_m(inpts);
39  int new_npoints = inpts->npoints * 2;
40  opts = ptarray_construct_empty(FLAGS_GET_Z(inpts->flags), FLAGS_GET_M(inpts->flags), new_npoints);
41 
42  dlist = (double*)(opts->serialized_pointlist);
43 
44  p1 = getPoint4d(inpts, 0);
45  /*if first point*/
46  if(preserve_endpoint)
47  {
49  n_out_points++;
50  }
51 
52  for (p=1;p<inpts->npoints;p++)
53  {
54  memcpy(&p2, &p1, sizeof(POINT4D));
55  p1 = getPoint4d(inpts, p);
56  if(p>0)
57  {
58  p1_set = p2_set = 0;
59  for (i=0;i<ndims;i++)
60  {
61  val1 = ((double*) &(p1))[i];
62  val2 = ((double*) &(p2))[i];
63  deltaval = val1 - val2;
64  quarter_delta = deltaval * 0.25;
65  if(!preserve_endpoint || p > 1)
66  {
67  dlist[n_out_points * ndims + i] = val2 + quarter_delta;
68  p1_set = 1;
69  }
70  if(!preserve_endpoint || p < inpts->npoints - 1)
71  {
72  dlist[(n_out_points + p1_set) * ndims + i] = val1 - quarter_delta;
73  p2_set = 1;
74  }
75  }
76  n_out_points+=(p1_set + p2_set);
77  }
78  }
79 
80  /*if last point*/
81  if(preserve_endpoint)
82  {
83  opts->npoints = n_out_points;
85  n_out_points++;
86  }
87 
88  if(isclosed && !preserve_endpoint)
89  {
90  opts->npoints = n_out_points;
91  POINT4D first_point = getPoint4d(opts, 0);
92  ptarray_append_point(opts, &first_point, LW_TRUE);
93  n_out_points++;
94  }
95  opts->npoints = n_out_points;
96 
97  return opts;
98 
99 }
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:106
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:36
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:43
opts
Definition: ovdump.py:44
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint4d(), LW_TRUE, POINTARRAY::npoints, ovdump::opts, ptarray_append_point(), ptarray_construct_empty(), ptarray_has_m(), and ptarray_has_z().

Referenced by lwline_chaikin(), and lwpoly_chaikin().

Here is the call graph for this function:
Here is the caller graph for this function: