PostGIS  2.2.7dev-r@@SVN_REVISION@@
static double gidx_distance_node_centroid ( const GIDX *  node,
const GIDX *  query 
)
static

Definition at line 557 of file gserialized_gist_nd.c.

Referenced by gserialized_gist_distance().

558 {
559  int i;
560  double sum = 0;
561 
562  /* Base computation on least available dimensions */
563  int ndims = Min(GIDX_NDIMS(node), GIDX_NDIMS(query));
564 
565  for ( i = 0; i < ndims; ++i )
566  {
567  double d;
568  double amin = GIDX_GET_MIN(query,i);
569  double amax = GIDX_GET_MAX(query,i);
570  double bmin = GIDX_GET_MIN(node,i);
571  double bmax = GIDX_GET_MAX(node,i);
572  double ca = amin + ( ( amax - amin ) / 2.0 );
573 
574  if ( ( ca <= bmax && ca >= bmin ) )
575  {
576  /* overlaps */
577  d = 0;
578  }
579  else if ( bmax < ca )
580  {
581  /* is "left" */
582  d = ca - bmax;
583  }
584  else
585  {
586  /* is "right" */
587  assert( bmin > ca );
588  d = bmin - ca;
589  }
590  if ( ! isfinite(d) )
591  {
592  /* Can happen if coordinates are corrupted/NaN */
593  continue;
594  }
595  sum += d * d;
596  POSTGIS_DEBUGF(3, "dist %g, squared %g, grows sum to %g", d, d*d, sum);
597  }
598  return sqrt(sum);
599 }

Here is the caller graph for this function: