PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gidx_distance()

static double gidx_distance ( const GIDX *  a,
const GIDX *  b,
int  m_is_time 
)
static

Calculate the box->box distance.

Definition at line 508 of file gserialized_gist_nd.c.

Referenced by gserialized_gist_distance(), and gserialized_gist_geog_distance().

509 {
510  int ndims, i;
511  double sum = 0;
512 
513  /* Base computation on least available dimensions */
514  ndims = Min(GIDX_NDIMS(b), GIDX_NDIMS(a));
515  for ( i = 0; i < ndims; ++i )
516  {
517  double d;
518  double amin = GIDX_GET_MIN(a,i);
519  double amax = GIDX_GET_MAX(a,i);
520  double bmin = GIDX_GET_MIN(b,i);
521  double bmax = GIDX_GET_MAX(b,i);
522  POSTGIS_DEBUGF(3, "A %g - %g", amin, amax);
523  POSTGIS_DEBUGF(3, "B %g - %g", bmin, bmax);
524 
525  if ( ( amin <= bmax && amax >= bmin ) )
526  {
527  /* overlaps */
528  d = 0;
529  }
530  else if ( i == 4 && m_is_time )
531  {
532  return FLT_MAX;
533  }
534  else if ( bmax < amin )
535  {
536  /* is "left" */
537  d = amin - bmax;
538  }
539  else
540  {
541  /* is "right" */
542  assert( bmin > amax );
543  d = bmin - amax;
544  }
545  if ( ! isfinite(d) )
546  {
547  /* Can happen if coordinates are corrupted/NaN */
548  continue;
549  }
550  sum += d * d;
551  POSTGIS_DEBUGF(3, "dist %g, squared %g, grows sum to %g", d, d*d, sum);
552  }
553  return sqrt(sum);
554 }
Here is the caller graph for this function: