PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_scroll_in_place()

int ptarray_scroll_in_place ( POINTARRAY pa,
const POINT4D pt 
)

Definition at line 2181 of file ptarray.c.

2182 {
2183  POINTARRAY *tmp;
2184  int found;
2185  uint32_t it;
2186  int ptsize;
2187 
2188  if ( ! ptarray_is_closed_2d(pa) )
2189  {
2190  lwerror("ptarray_scroll_in_place: input POINTARRAY is not closed");
2191  return LW_FAILURE;
2192  }
2193 
2194  ptsize = ptarray_point_size(pa);
2195 
2196  /* Find the point in the array */
2197  found = 0;
2198  for ( it = 0; it < pa->npoints; ++it )
2199  {
2200  if ( ! memcmp(getPoint_internal(pa, it), pt, ptsize) )
2201  {
2202  found = 1;
2203  break;
2204  }
2205  }
2206 
2207  if ( ! found )
2208  {
2209  lwerror("ptarray_scroll_in_place: input POINTARRAY does not contain the given point");
2210  return LW_FAILURE;
2211  }
2212 
2213  if ( 0 == it )
2214  {
2215  /* Point is already the start/end point, just clone the input */
2216  return LW_SUCCESS;
2217  }
2218 
2219  /* TODO: reduce allocations */
2221 
2222  bzero(getPoint_internal(tmp, 0), ptsize * pa->npoints);
2223  /* Copy the block from found point to last point into the output array */
2224  memcpy(
2225  getPoint_internal(tmp, 0),
2226  getPoint_internal(pa, it),
2227  ptsize * ( pa->npoints - it )
2228  );
2229 
2230  /* Copy the block from second point to the found point into the last portion of the
2231  * return */
2232  memcpy(
2233  getPoint_internal(tmp, pa->npoints - it),
2234  getPoint_internal(pa, 1),
2235  ptsize * ( it )
2236  );
2237 
2238  /* Copy the resulting pointarray back to source one */
2239  memcpy(
2240  getPoint_internal(pa, 0),
2241  getPoint_internal(tmp, 0),
2242  ptsize * ( pa->npoints )
2243  );
2244 
2245  ptarray_free(tmp);
2246 
2247  return LW_SUCCESS;
2248 }
#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 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:714
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:319
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: