PostGIS  3.6.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 729 of file gserialized_estimate.c.

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