PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ptarray_scroll_in_place()

int ptarray_scroll_in_place ( POINTARRAY pa,
const POINT4D pt 
)

Definition at line 2163 of file ptarray.c.

2164 {
2165  POINTARRAY *tmp;
2166  int found;
2167  uint32_t it;
2168  int ptsize;
2169 
2170  if ( ! ptarray_is_closed_2d(pa) )
2171  {
2172  lwerror("ptarray_scroll_in_place: input POINTARRAY is not closed");
2173  return LW_FAILURE;
2174  }
2175 
2176  ptsize = ptarray_point_size(pa);
2177 
2178  /* Find the point in the array */
2179  found = 0;
2180  for ( it = 0; it < pa->npoints; ++it )
2181  {
2182  if ( ! memcmp(getPoint_internal(pa, it), pt, ptsize) )
2183  {
2184  found = 1;
2185  break;
2186  }
2187  }
2188 
2189  if ( ! found )
2190  {
2191  lwerror("ptarray_scroll_in_place: input POINTARRAY does not contain the given point");
2192  return LW_FAILURE;
2193  }
2194 
2195  if ( 0 == it )
2196  {
2197  /* Point is already the start/end point, just clone the input */
2198  return LW_SUCCESS;
2199  }
2200 
2201  /* TODO: reduce allocations */
2203 
2204  bzero(getPoint_internal(tmp, 0), ptsize * pa->npoints);
2205  /* Copy the block from found point to last point into the output array */
2206  memcpy(
2207  getPoint_internal(tmp, 0),
2208  getPoint_internal(pa, it),
2209  ptsize * ( pa->npoints - it )
2210  );
2211 
2212  /* Copy the block from second point to the found point into the last portion of the
2213  * return */
2214  memcpy(
2215  getPoint_internal(tmp, pa->npoints - it),
2216  getPoint_internal(pa, 1),
2217  ptsize * ( it )
2218  );
2219 
2220  /* Copy the resulting pointarray back to source one */
2221  memcpy(
2222  getPoint_internal(pa, 0),
2223  getPoint_internal(tmp, 0),
2224  ptsize * ( pa->npoints )
2225  );
2226 
2227  ptarray_free(tmp);
2228 
2229  return LW_SUCCESS;
2230 }
#define LW_FAILURE
Definition: liblwgeom.h:111
#define LW_SUCCESS
Definition: liblwgeom.h:112
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:180
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:181
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:58
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:77
int ptarray_is_closed_2d(const POINTARRAY *in)
Definition: ptarray.c:701
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:51
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:327
lwflags_t flags
Definition: liblwgeom.h:446
uint32_t npoints
Definition: liblwgeom.h:442

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint_internal(), LW_FAILURE, LW_SUCCESS, lwerror(), POINTARRAY::npoints, ptarray_construct(), ptarray_free(), ptarray_is_closed_2d(), and ptarray_point_size().

Referenced by _lwt_AddLine(), ST_Scroll(), and test_ptarray_scroll().

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