PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void ptarray_dp_findsplit ( POINTARRAY pts,
int  p1,
int  p2,
int *  split,
double *  dist 
)
static

Definition at line 1446 of file ptarray.c.

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

Referenced by ptarray_simplify().

1447 {
1448  int k;
1449  const POINT2D *pk, *pa, *pb;
1450  double tmp, d;
1451 
1452  LWDEBUG(4, "function called");
1453 
1454  *split = p1;
1455  d = -1;
1456 
1457  if (p1 + 1 < p2)
1458  {
1459 
1460  pa = getPoint2d_cp(pts, p1);
1461  pb = getPoint2d_cp(pts, p2);
1462 
1463  LWDEBUGF(4, "P%d(%f,%f) to P%d(%f,%f)",
1464  p1, pa->x, pa->y, p2, pb->x, pb->y);
1465 
1466  for (k=p1+1; k<p2; k++)
1467  {
1468  pk = getPoint2d_cp(pts, k);
1469 
1470  LWDEBUGF(4, "P%d(%f,%f)", k, pk->x, pk->y);
1471 
1472  /* distance computation */
1473  tmp = distance2d_sqr_pt_seg(pk, pa, pb);
1474 
1475  if (tmp > d)
1476  {
1477  d = tmp; /* record the maximum */
1478  *split = k;
1479 
1480  LWDEBUGF(4, "P%d is farthest (%g)", k, d);
1481  }
1482  }
1483  *dist = d;
1484 
1485  } /* length---should be redone if can == 0 */
1486  else
1487  {
1488  LWDEBUG(3, "segment too short, no split/no dist");
1489  *dist = -1;
1490  }
1491 
1492 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double x
Definition: liblwgeom.h:284
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:458
double y
Definition: liblwgeom.h:284
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2197
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the call graph for this function:

Here is the caller graph for this function: