PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ ptarray_scroll_in_place()

int ptarray_scroll_in_place ( POINTARRAY pa,
const POINT4D newbase 
)

Definition at line 2325 of file ptarray.c.

2326 {
2327  POINTARRAY *tmp;
2328  int found;
2329  uint32_t it;
2330  int ptsize;
2331 
2332  if ( ! ptarray_is_closed_2d(pa) )
2333  {
2334  lwerror("ptarray_scroll_in_place: input POINTARRAY is not closed");
2335  return LW_FAILURE;
2336  }
2337 
2338  ptsize = ptarray_point_size(pa);
2339 
2340  /* Find the point in the array */
2341  found = 0;
2342  for ( it = 0; it < pa->npoints; ++it )
2343  {
2344  if ( ! memcmp(getPoint_internal(pa, it), pt, ptsize) )
2345  {
2346  found = 1;
2347  break;
2348  }
2349  }
2350 
2351  if ( ! found )
2352  {
2353  lwerror("ptarray_scroll_in_place: input POINTARRAY does not contain the given point");
2354  return LW_FAILURE;
2355  }
2356 
2357  if ( 0 == it )
2358  {
2359  /* Point is already the start/end point, just clone the input */
2360  return LW_SUCCESS;
2361  }
2362 
2363  /* TODO: reduce allocations */
2365 
2366  memset(getPoint_internal(tmp, 0), 0, (size_t)ptsize * pa->npoints);
2367  /* Copy the block from found point to last point into the output array */
2368  memcpy(
2369  getPoint_internal(tmp, 0),
2370  getPoint_internal(pa, it),
2371  (size_t)ptsize * ( pa->npoints - it )
2372  );
2373 
2374  /* Copy the block from second point to the found point into the last portion of the
2375  * return */
2376  memcpy(
2377  getPoint_internal(tmp, pa->npoints - it),
2378  getPoint_internal(pa, 1),
2379  (size_t)ptsize * ( it )
2380  );
2381 
2382  /* Copy the resulting pointarray back to source one */
2383  memcpy(
2384  getPoint_internal(pa, 0),
2385  getPoint_internal(tmp, 0),
2386  (size_t)ptsize * ( pa->npoints )
2387  );
2388 
2389  ptarray_free(tmp);
2390 
2391  return LW_SUCCESS;
2392 }
#define LW_FAILURE
Definition: liblwgeom.h:96
#define LW_SUCCESS
Definition: liblwgeom.h:97
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:166
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:56
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:75
int ptarray_is_closed_2d(const POINTARRAY *in)
Definition: ptarray.c:710
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:431
uint32_t npoints
Definition: liblwgeom.h:427

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: