PostGIS  3.4.0dev-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 1353 of file ptarray.c.

1354 {
1355  uint32_t t, pn=0;
1356  const POINT2D *p;
1357  double mindist = DBL_MAX;
1358 
1359  /* Loop through pointarray looking for nearest segment */
1360  for (t=0; t<pa->npoints; t++)
1361  {
1362  double dist_sqr;
1363  p = getPoint2d_cp(pa, t);
1364  dist_sqr = distance2d_sqr_pt_pt(p, qp);
1365 
1366  if (dist_sqr < mindist)
1367  {
1368  mindist = dist_sqr;
1369  pn = t;
1370  if ( mindist == 0 )
1371  {
1372  LWDEBUG(3, "Breaking on mindist=0");
1373  break;
1374  }
1375  }
1376  }
1377  if ( dist ) *dist = sqrt(mindist);
1378  return pn;
1379 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
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:101
static double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: lwinline.h:35
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: