PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ptarray_dp_findsplit()

static void ptarray_dp_findsplit ( POINTARRAY pts,
int  p1,
int  p2,
int *  split,
double *  dist 
)
static

Definition at line 1552 of file ptarray.c.

References distance2d_sqr_pt_seg(), getPoint2d_cp(), LWDEBUG, LWDEBUGF, POINT2D::x, and POINT2D::y.

Referenced by ptarray_simplify().

1553 {
1554  int k;
1555  const POINT2D *pk, *pa, *pb;
1556  double tmp, d;
1557 
1558  LWDEBUG(4, "function called");
1559 
1560  *split = p1;
1561  d = -1;
1562 
1563  if (p1 + 1 < p2)
1564  {
1565 
1566  pa = getPoint2d_cp(pts, p1);
1567  pb = getPoint2d_cp(pts, p2);
1568 
1569  LWDEBUGF(4, "P%d(%f,%f) to P%d(%f,%f)",
1570  p1, pa->x, pa->y, p2, pb->x, pb->y);
1571 
1572  for (k=p1+1; k<p2; k++)
1573  {
1574  pk = getPoint2d_cp(pts, k);
1575 
1576  LWDEBUGF(4, "P%d(%f,%f)", k, pk->x, pk->y);
1577 
1578  /* distance computation */
1579  tmp = distance2d_sqr_pt_seg(pk, pa, pb);
1580 
1581  if (tmp > d)
1582  {
1583  d = tmp; /* record the maximum */
1584  *split = k;
1585 
1586  LWDEBUGF(4, "P%d is farthest (%g)", k, d);
1587  }
1588  }
1589  *dist = d;
1590 
1591  } /* length---should be redone if can == 0 */
1592  else
1593  {
1594  LWDEBUG(3, "segment too short, no split/no dist");
1595  *dist = -1;
1596  }
1597 
1598 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:328
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:373
double y
Definition: liblwgeom.h:328
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2391
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
Here is the call graph for this function:
Here is the caller graph for this function: