PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 441 of file lwlinearreferencing.c.

442{
443 POINT4D p1, p2;
444 POINTARRAY *opa;
445 double ovp1, ovp2;
446 POINT4D *t;
447 int8_t p1out, p2out; /* -1 - smaller than from, 0 - in range, 1 - larger than to */
448 uint32_t i;
449 uint8_t hasz = FLAGS_GET_Z(ipa->flags);
450 uint8_t hasm = FLAGS_GET_M(ipa->flags);
451
452 assert(from <= to);
453
454 t = lwalloc(sizeof(POINT4D));
455
456 /* Initial storage */
457 opa = ptarray_construct_empty(hasz, hasm, ipa->npoints);
458
459 /* Add first point */
460 getPoint4d_p(ipa, 0, &p1);
461 ovp1 = lwpoint_get_ordinate(&p1, ordinate);
462
463 p1out = (ovp1 < from) ? -1 : ((ovp1 > to) ? 1 : 0);
464
465 if (from <= ovp1 && ovp1 <= to)
467
468 /* Loop on all other input points */
469 for (i = 1; i < ipa->npoints; i++)
470 {
471 getPoint4d_p(ipa, i, &p2);
472 ovp2 = lwpoint_get_ordinate(&p2, ordinate);
473 p2out = (ovp2 < from) ? -1 : ((ovp2 > to) ? 1 : 0);
474
475 if (p1out == 0 && p2out == 0) /* both visible */
476 {
478 }
479 else if (p1out == p2out && p1out != 0) /* both invisible on the same side */
480 {
481 /* skip */
482 }
483 else if (p1out == -1 && p2out == 0)
484 {
485 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
488 }
489 else if (p1out == -1 && p2out == 1)
490 {
491 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
493 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
495 }
496 else if (p1out == 0 && p2out == -1)
497 {
498 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
500 }
501 else if (p1out == 0 && p2out == 1)
502 {
503 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
505 }
506 else if (p1out == 1 && p2out == -1)
507 {
508 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
510 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, from);
512 }
513 else if (p1out == 1 && p2out == 0)
514 {
515 point_interpolate(&p1, &p2, t, hasz, hasm, ordinate, to);
518 }
519
520 p1 = p2;
521 p1out = p2out;
522 LW_ON_INTERRUPT(ptarray_free(opa); return NULL);
523 }
524
525 if (is_closed && opa->npoints > 2)
526 {
527 getPoint4d_p(opa, 0, &p1);
529 }
530 lwfree(t);
531
532 return opa;
533}
#define LW_FALSE
Definition liblwgeom.h:108
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_Z(flags)
Definition liblwgeom.h:179
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:242
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:180
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
#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:417
uint32_t npoints
Definition liblwgeom.h:413

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: