PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gidx_distance()

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 648 of file gserialized_gist_nd.c.

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

Referenced by gserialized_gist_distance(), and gserialized_gist_geog_distance().

Here is the caller graph for this function: