PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ ptarray_scroll_in_place()

int ptarray_scroll_in_place ( POINTARRAY pa,
const POINT4D newbase 
)

Definition at line 2443 of file ptarray.c.

2444 {
2445  POINTARRAY *tmp;
2446  int found;
2447  uint32_t it;
2448  int ptsize;
2449 
2450  if ( ! ptarray_is_closed_2d(pa) )
2451  {
2452  lwerror("ptarray_scroll_in_place: input POINTARRAY is not closed");
2453  return LW_FAILURE;
2454  }
2455 
2456  ptsize = ptarray_point_size(pa);
2457 
2458  /* Find the point in the array */
2459  found = 0;
2460  for ( it = 0; it < pa->npoints; ++it )
2461  {
2462  if ( ! memcmp(getPoint_internal(pa, it), pt, ptsize) )
2463  {
2464  found = 1;
2465  break;
2466  }
2467  }
2468 
2469  if ( ! found )
2470  {
2471  lwerror("ptarray_scroll_in_place: input POINTARRAY does not contain the given point");
2472  return LW_FAILURE;
2473  }
2474 
2475  if ( 0 == it )
2476  {
2477  /* Point is already the start/end point, just clone the input */
2478  return LW_SUCCESS;
2479  }
2480 
2481  /* TODO: reduce allocations */
2483 
2484  bzero(getPoint_internal(tmp, 0), ptsize * pa->npoints);
2485  /* Copy the block from found point to last point into the output array */
2486  memcpy(
2487  getPoint_internal(tmp, 0),
2488  getPoint_internal(pa, it),
2489  ptsize * ( pa->npoints - it )
2490  );
2491 
2492  /* Copy the block from second point to the found point into the last portion of the
2493  * return */
2494  memcpy(
2495  getPoint_internal(tmp, pa->npoints - it),
2496  getPoint_internal(pa, 1),
2497  ptsize * ( it )
2498  );
2499 
2500  /* Copy the resulting pointarray back to source one */
2501  memcpy(
2502  getPoint_internal(pa, 0),
2503  getPoint_internal(tmp, 0),
2504  ptsize * ( pa->npoints )
2505  );
2506 
2507  ptarray_free(tmp);
2508 
2509  return LW_SUCCESS;
2510 }
#define LW_FAILURE
Definition: liblwgeom.h:110
#define LW_SUCCESS
Definition: liblwgeom.h:111
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
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:445
uint32_t npoints
Definition: liblwgeom.h:441

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: