PostGIS  2.5.0dev-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 701 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().

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