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

Calculate the centroid->centroid distance between the boxes.

Calculate the box->box distance.

Definition at line 647 of file gserialized_gist_nd.c.

Referenced by gserialized_gist_distance(), and gserialized_gist_geog_distance().

648 {
649  int ndims, i;
650  double sum = 0;
651 
652  /* Base computation on least available dimensions */
653  ndims = Min(GIDX_NDIMS(b), GIDX_NDIMS(a));
654  for ( i = 0; i < ndims; ++i )
655  {
656  double d;
657  double amin = GIDX_GET_MIN(a,i);
658  double amax = GIDX_GET_MAX(a,i);
659  double bmin = GIDX_GET_MIN(b,i);
660  double bmax = GIDX_GET_MAX(b,i);
661  POSTGIS_DEBUGF(3, "A %g - %g", amin, amax);
662  POSTGIS_DEBUGF(3, "B %g - %g", bmin, bmax);
663 
664  if ( ( amin <= bmax && amax >= bmin ) )
665  {
666  /* overlaps */
667  d = 0;
668  }
669  else if ( i == 4 && m_is_time )
670  {
671  return FLT_MAX;
672  }
673  else if ( bmax < amin )
674  {
675  /* is "left" */
676  d = amin - bmax;
677  }
678  else
679  {
680  /* is "right" */
681  assert( bmin > amax );
682  d = bmin - amax;
683  }
684  if ( ! isfinite(d) )
685  {
686  /* Can happen if coordinates are corrupted/NaN */
687  continue;
688  }
689  sum += d * d;
690  POSTGIS_DEBUGF(3, "dist %g, squared %g, grows sum to %g", d, d*d, sum);
691  }
692  return sqrt(sum);
693 }

Here is the caller graph for this function: