PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ ptarray_closest_vertex_2d()

int ptarray_closest_vertex_2d ( const POINTARRAY pa,
const POINT2D qp,
double *  dist 
)
Parameters
pathe subject pointarray
qpthe query point
distoptional output for actual distance from vertex

Definition at line 1480 of file ptarray.c.

1481 {
1482  uint32_t t, pn=0;
1483  const POINT2D *p;
1484  double mindist = DBL_MAX;
1485 
1486  /* Loop through pointarray looking for nearest segment */
1487  for (t=0; t<pa->npoints; t++)
1488  {
1489  double dist_sqr;
1490  p = getPoint2d_cp(pa, t);
1491  dist_sqr = distance2d_sqr_pt_pt(p, qp);
1492 
1493  if (dist_sqr < mindist)
1494  {
1495  mindist = dist_sqr;
1496  pn = t;
1497  if ( mindist == 0 )
1498  {
1499  LWDEBUG(3, "Breaking on mindist=0");
1500  break;
1501  }
1502  }
1503  }
1504  if ( dist ) *dist = sqrt(mindist);
1505  return pn;
1506 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:97
static double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: lwinline.h:33
uint32_t npoints
Definition: liblwgeom.h:427

References distance2d_sqr_pt_pt(), getPoint2d_cp(), LWDEBUG, and POINTARRAY::npoints.

Referenced by test_ptarray_closest_vertex_2d().

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