PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gidx_distance_node_centroid()

static double gidx_distance_node_centroid ( const GIDX *  node,
const GIDX *  query 
)
static

Definition at line 630 of file gserialized_gist_nd.c.

Referenced by gserialized_gist_distance().

631 {
632  int i;
633  double sum = 0;
634 
635  /* Base computation on least available dimensions */
636  int ndims = Min(GIDX_NDIMS(node), GIDX_NDIMS(query));
637 
638  for ( i = 0; i < ndims; ++i )
639  {
640  double d;
641  double amin = GIDX_GET_MIN(query,i);
642  double amax = GIDX_GET_MAX(query,i);
643  double bmin = GIDX_GET_MIN(node,i);
644  double bmax = GIDX_GET_MAX(node,i);
645  double ca = amin + ( ( amax - amin ) / 2.0 );
646 
647  if ( ( ca <= bmax && ca >= bmin ) )
648  {
649  /* overlaps */
650  d = 0;
651  }
652  else if ( bmax < ca )
653  {
654  /* is "left" */
655  d = ca - bmax;
656  }
657  else
658  {
659  /* is "right" */
660  assert( bmin > ca );
661  d = bmin - ca;
662  }
663  if ( ! isfinite(d) )
664  {
665  /* Can happen if coordinates are corrupted/NaN */
666  continue;
667  }
668  sum += d * d;
669  POSTGIS_DEBUGF(3, "dist %g, squared %g, grows sum to %g", d, d*d, sum);
670  }
671  return sqrt(sum);
672 }
Here is the caller graph for this function: