PostGIS  2.5.0dev-r@@SVN_REVISION@@
static double nd_box_ratio ( const ND_BOX b1,
const ND_BOX b2,
int  ndims 
)
inlinestatic

Returns the proportion of b2 that is covered by b1.

Definition at line 700 of file gserialized_estimate.c.

References ND_BOX_T::max, and ND_BOX_T::min.

Referenced by compute_gserialized_stats_mode(), estimate_join_selectivity(), and estimate_selectivity().

701 {
702  int d;
703  bool covered = true;
704  double ivol = 1.0;
705  double vol2 = 1.0;
706  double vol1 = 1.0;
707 
708  for ( d = 0 ; d < ndims; d++ )
709  {
710  if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
711  return 0.0; /* Disjoint */
712 
713  if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
714  covered = false;
715  }
716 
717  if ( covered )
718  return 1.0;
719 
720  for ( d = 0; d < ndims; d++ )
721  {
722  double width1 = b1->max[d] - b1->min[d];
723  double width2 = b2->max[d] - b2->min[d];
724  double imin, imax, iwidth;
725 
726  vol1 *= width1;
727  vol2 *= width2;
728 
729  imin = Max(b1->min[d], b2->min[d]);
730  imax = Min(b1->max[d], b2->max[d]);
731  iwidth = imax - imin;
732  iwidth = Max(0.0, iwidth);
733 
734  ivol *= iwidth;
735  }
736 
737  if ( vol2 == 0.0 )
738  return vol2;
739 
740  return ivol / vol2;
741 }
float4 max[ND_DIMS]
float4 min[ND_DIMS]

Here is the caller graph for this function: