PostGIS  2.5.7dev-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 713 of file gserialized_estimate.c.

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

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

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

Here is the caller graph for this function: