PostGIS  3.3.9dev-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 722 of file gserialized_estimate.c.

723 {
724  int d;
725  bool covered = true;
726  double ivol = 1.0;
727  double vol2 = 1.0;
728 
729  for ( d = 0 ; d < ndims; d++ )
730  {
731  if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
732  return 0.0; /* Disjoint */
733 
734  if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
735  covered = false;
736  }
737 
738  if ( covered )
739  return 1.0;
740 
741  for ( d = 0; d < ndims; d++ )
742  {
743  double width2 = b2->max[d] - b2->min[d];
744  double imin, imax, iwidth;
745 
746  vol2 *= width2;
747 
748  imin = Max(b1->min[d], b2->min[d]);
749  imax = Min(b1->max[d], b2->max[d]);
750  iwidth = imax - imin;
751  iwidth = Max(0.0, iwidth);
752 
753  ivol *= iwidth;
754  }
755 
756  if ( vol2 == 0.0 )
757  return vol2;
758 
759  return ivol / vol2;
760 }
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: