PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ ptarray_dp_findsplit_in_place()

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

Definition at line 1512 of file ptarray.c.

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

Referenced by ptarray_simplify_in_place().

1513 {
1514  int k;
1515  const POINT2D *pk, *pa, *pb;
1516  double tmp, d;
1517 
1518  LWDEBUG(4, "function called");
1519 
1520  *split = p1;
1521  d = -1;
1522 
1523  if (p1 + 1 < p2)
1524  {
1525 
1526  pa = getPoint2d_cp(pts, p1);
1527  pb = getPoint2d_cp(pts, p2);
1528 
1529  LWDEBUGF(4, "P%d(%f,%f) to P%d(%f,%f)",
1530  p1, pa->x, pa->y, p2, pb->x, pb->y);
1531 
1532  for (k=p1+1; k<p2; k++)
1533  {
1534  pk = getPoint2d_cp(pts, k);
1535 
1536  LWDEBUGF(4, "P%d(%f,%f)", k, pk->x, pk->y);
1537 
1538  /* distance computation */
1539  tmp = distance2d_sqr_pt_seg(pk, pa, pb);
1540 
1541  if (tmp > d)
1542  {
1543  d = tmp; /* record the maximum */
1544  *split = k;
1545 
1546  LWDEBUGF(4, "P%d is farthest (%g)", k, d);
1547  }
1548  }
1549  *dist = d;
1550  }
1551  else
1552  {
1553  LWDEBUG(3, "segment too short, no split/no dist");
1554  *dist = -1;
1555  }
1556 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:330
double y
Definition: liblwgeom.h:330
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2379
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
Here is the call graph for this function:
Here is the caller graph for this function: