PostGIS  2.3.8dev-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 1505 of file ptarray.c.

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

Referenced by ptarray_simplify().

1506 {
1507  int k;
1508  const POINT2D *pk, *pa, *pb;
1509  double tmp, d;
1510 
1511  LWDEBUG(4, "function called");
1512 
1513  *split = p1;
1514  d = -1;
1515 
1516  if (p1 + 1 < p2)
1517  {
1518 
1519  pa = getPoint2d_cp(pts, p1);
1520  pb = getPoint2d_cp(pts, p2);
1521 
1522  LWDEBUGF(4, "P%d(%f,%f) to P%d(%f,%f)",
1523  p1, pa->x, pa->y, p2, pb->x, pb->y);
1524 
1525  for (k=p1+1; k<p2; k++)
1526  {
1527  pk = getPoint2d_cp(pts, k);
1528 
1529  LWDEBUGF(4, "P%d(%f,%f)", k, pk->x, pk->y);
1530 
1531  /* distance computation */
1532  tmp = distance2d_sqr_pt_seg(pk, pa, pb);
1533 
1534  if (tmp > d)
1535  {
1536  d = tmp; /* record the maximum */
1537  *split = k;
1538 
1539  LWDEBUGF(4, "P%d is farthest (%g)", k, d);
1540  }
1541  }
1542  *dist = d;
1543 
1544  } /* length---should be redone if can == 0 */
1545  else
1546  {
1547  LWDEBUG(3, "segment too short, no split/no dist");
1548  *dist = -1;
1549  }
1550 
1551 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:327
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:485
double y
Definition: liblwgeom.h:327
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2390
#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: