PostGIS  2.5.7dev-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 1519 of file ptarray.c.

1520 {
1521  int k;
1522  const POINT2D *pk, *pa, *pb;
1523  double tmp, d;
1524 
1525  LWDEBUG(4, "function called");
1526 
1527  *split = p1;
1528  d = -1;
1529 
1530  if (p1 + 1 < p2)
1531  {
1532 
1533  pa = getPoint2d_cp(pts, p1);
1534  pb = getPoint2d_cp(pts, p2);
1535 
1536  LWDEBUGF(4, "P%d(%f,%f) to P%d(%f,%f)",
1537  p1, pa->x, pa->y, p2, pb->x, pb->y);
1538 
1539  for (k=p1+1; k<p2; k++)
1540  {
1541  pk = getPoint2d_cp(pts, k);
1542 
1543  LWDEBUGF(4, "P%d(%f,%f)", k, pk->x, pk->y);
1544 
1545  /* distance computation */
1546  tmp = distance2d_sqr_pt_seg(pk, pa, pb);
1547 
1548  if (tmp > d)
1549  {
1550  d = tmp; /* record the maximum */
1551  *split = k;
1552 
1553  LWDEBUGF(4, "P%d is farthest (%g)", k, d);
1554  }
1555  }
1556  *dist = d;
1557  }
1558  else
1559  {
1560  LWDEBUG(3, "segment too short, no split/no dist");
1561  *dist = -1;
1562  }
1563 }
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
Definition: measures.c:2381
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:374
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

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

Referenced by ptarray_simplify_in_place().

Here is the call graph for this function:
Here is the caller graph for this function: