PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ptarray_clamp_to_ordinate_range()

static POINTARRAY* ptarray_clamp_to_ordinate_range ( const POINTARRAY ipa,
char  ordinate,
double  from,
double  to,
uint8_t  is_closed 
)
inlinestatic

Definition at line 429 of file lwlinearreferencing.c.

430 {
431  POINT4D p1, p2;
432  POINTARRAY *opa;
433  double ovp1, ovp2;
434  POINT4D *t;
435  int8_t p1out, p2out; /* -1 - smaller than from, 0 - in range, 1 - larger than to */
436  uint32_t i;
437  uint8_t hasz = FLAGS_GET_Z(ipa->flags);
438  uint8_t hasm = FLAGS_GET_M(ipa->flags);
439 
440  assert(from <= to);
441 
442  t = lwalloc(sizeof(POINT4D));
443 
444  /* Initial storage */
445  opa = ptarray_construct_empty(hasz, hasm, ipa->npoints);
446 
447  /* Add first point */
448  getPoint4d_p(ipa, 0, &p1);
449  ovp1 = lwpoint_get_ordinate(&p1, ordinate);
450 
451  p1out = (ovp1 < from) ? -1 : ((ovp1 > to) ? 1 : 0);
452 
453  if (from <= ovp1 && ovp1 <= to)
454  ptarray_append_point(opa, &p1, LW_FALSE);
455 
456  /* Loop on all other input points */
457  for (i = 1; i < ipa->npoints; i++)
458  {
459  getPoint4d_p(ipa, i, &p2);
460  ovp2 = lwpoint_get_ordinate(&p2, ordinate);
461  p2out = (ovp2 < from) ? -1 : ((ovp2 > to) ? 1 : 0);
462 
463  if (p1out == 0 && p2out == 0) /* both visible */
464  {
465  ptarray_append_point(opa, &p2, LW_FALSE);
466  }
467  else if (p1out == p2out && p1out != 0) /* both invisible on the same side */
468  {
469  /* skip */
470  }
471  else if (p1out == -1 && p2out == 0)
472  {
473  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
475  ptarray_append_point(opa, &p2, LW_FALSE);
476  }
477  else if (p1out == -1 && p2out == 1)
478  {
479  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
481  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
483  }
484  else if (p1out == 0 && p2out == -1)
485  {
486  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
488  }
489  else if (p1out == 0 && p2out == 1)
490  {
491  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
493  }
494  else if (p1out == 1 && p2out == -1)
495  {
496  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
498  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
500  }
501  else if (p1out == 1 && p2out == 0)
502  {
503  point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
505  ptarray_append_point(opa, &p2, LW_FALSE);
506  }
507 
508  p1 = p2;
509  p1out = p2out;
510  LW_ON_INTERRUPT(ptarray_free(opa); return NULL);
511  }
512 
513  if (is_closed && opa->npoints > 2)
514  {
515  getPoint4d_p(opa, 0, &p1);
516  ptarray_append_point(opa, &p1, LW_FALSE);
517  }
518  lwfree(t);
519 
520  return opa;
521 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:165
void lwfree(void *mem)
Definition: lwutil.c:248
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:166
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:327
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:147
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define LW_ON_INTERRUPT(x)
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value)
Given two points, a dimensionality, an ordinate, and an interpolation value generate a new point that...
lwflags_t flags
Definition: liblwgeom.h:431
uint32_t npoints
Definition: liblwgeom.h:427

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint4d_p(), LW_FALSE, LW_ON_INTERRUPT, lwalloc(), lwfree(), lwpoint_get_ordinate(), POINTARRAY::npoints, point_interpolate(), ptarray_append_point(), ptarray_construct_empty(), and ptarray_free().

Referenced by lwpoly_clip_to_ordinate_range(), and lwtriangle_clip_to_ordinate_range().

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