PostGIS  2.3.7dev-r@@SVN_REVISION@@
static double gidx_distance ( const GIDX *  a,
const GIDX *  b,
int  m_is_time 
)
static

Calculate the box->box distance.

Definition at line 581 of file gserialized_gist_nd.c.

Referenced by gserialized_gist_distance(), and gserialized_gist_geog_distance().

582 {
583  int ndims, i;
584  double sum = 0;
585 
586  /* Base computation on least available dimensions */
587  ndims = Min(GIDX_NDIMS(b), GIDX_NDIMS(a));
588  for ( i = 0; i < ndims; ++i )
589  {
590  double d;
591  double amin = GIDX_GET_MIN(a,i);
592  double amax = GIDX_GET_MAX(a,i);
593  double bmin = GIDX_GET_MIN(b,i);
594  double bmax = GIDX_GET_MAX(b,i);
595  POSTGIS_DEBUGF(3, "A %g - %g", amin, amax);
596  POSTGIS_DEBUGF(3, "B %g - %g", bmin, bmax);
597 
598  if ( ( amin <= bmax && amax >= bmin ) )
599  {
600  /* overlaps */
601  d = 0;
602  }
603  else if ( i == 4 && m_is_time )
604  {
605  return FLT_MAX;
606  }
607  else if ( bmax < amin )
608  {
609  /* is "left" */
610  d = amin - bmax;
611  }
612  else
613  {
614  /* is "right" */
615  assert( bmin > amax );
616  d = bmin - amax;
617  }
618  if ( ! isfinite(d) )
619  {
620  /* Can happen if coordinates are corrupted/NaN */
621  continue;
622  }
623  sum += d * d;
624  POSTGIS_DEBUGF(3, "dist %g, squared %g, grows sum to %g", d, d*d, sum);
625  }
626  return sqrt(sum);
627 }

Here is the caller graph for this function: