PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ nd_box_ratio()

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 707 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().

708 {
709  int d;
710  bool covered = true;
711  double ivol = 1.0;
712  double vol2 = 1.0;
713  double vol1 = 1.0;
714 
715  for ( d = 0 ; d < ndims; d++ )
716  {
717  if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
718  return 0.0; /* Disjoint */
719 
720  if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
721  covered = false;
722  }
723 
724  if ( covered )
725  return 1.0;
726 
727  for ( d = 0; d < ndims; d++ )
728  {
729  double width1 = b1->max[d] - b1->min[d];
730  double width2 = b2->max[d] - b2->min[d];
731  double imin, imax, iwidth;
732 
733  vol1 *= width1;
734  vol2 *= width2;
735 
736  imin = Max(b1->min[d], b2->min[d]);
737  imax = Min(b1->max[d], b2->max[d]);
738  iwidth = imax - imin;
739  iwidth = Max(0.0, iwidth);
740 
741  ivol *= iwidth;
742  }
743 
744  if ( vol2 == 0.0 )
745  return vol2;
746 
747  return ivol / vol2;
748 }
float4 max[ND_DIMS]
float4 min[ND_DIMS]
Here is the caller graph for this function: