PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 629 of file gserialized_estimate.c.

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

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

630 {
631  int d;
632  bool covered = TRUE;
633  double ivol = 1.0;
634  double vol2 = 1.0;
635  double vol1 = 1.0;
636 
637  for ( d = 0 ; d < ndims; d++ )
638  {
639  if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
640  return 0.0; /* Disjoint */
641 
642  if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
643  covered = FALSE;
644  }
645 
646  if ( covered )
647  return 1.0;
648 
649  for ( d = 0; d < ndims; d++ )
650  {
651  double width1 = b1->max[d] - b1->min[d];
652  double width2 = b2->max[d] - b2->min[d];
653  double imin, imax, iwidth;
654 
655  vol1 *= width1;
656  vol2 *= width2;
657 
658  imin = Max(b1->min[d], b2->min[d]);
659  imax = Min(b1->max[d], b2->max[d]);
660  iwidth = imax - imin;
661  iwidth = Max(0.0, iwidth);
662 
663  ivol *= iwidth;
664  }
665 
666  if ( vol2 == 0.0 )
667  return vol2;
668 
669  return ivol / vol2;
670 }
float4 max[ND_DIMS]
float4 min[ND_DIMS]
#define FALSE
Definition: dbfopen.c:169
#define TRUE
Definition: dbfopen.c:170

Here is the caller graph for this function: