PostGIS  3.4.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 732 of file gserialized_estimate.c.

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