PostGIS  2.2.7dev-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 630 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().

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

Here is the caller graph for this function: