PostGIS  2.3.6-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 654 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().

655 {
656  int d;
657  bool covered = TRUE;
658  double ivol = 1.0;
659  double vol2 = 1.0;
660  double vol1 = 1.0;
661 
662  for ( d = 0 ; d < ndims; d++ )
663  {
664  if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
665  return 0.0; /* Disjoint */
666 
667  if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
668  covered = FALSE;
669  }
670 
671  if ( covered )
672  return 1.0;
673 
674  for ( d = 0; d < ndims; d++ )
675  {
676  double width1 = b1->max[d] - b1->min[d];
677  double width2 = b2->max[d] - b2->min[d];
678  double imin, imax, iwidth;
679 
680  vol1 *= width1;
681  vol2 *= width2;
682 
683  imin = Max(b1->min[d], b2->min[d]);
684  imax = Min(b1->max[d], b2->max[d]);
685  iwidth = imax - imin;
686  iwidth = Max(0.0, iwidth);
687 
688  ivol *= iwidth;
689  }
690 
691  if ( vol2 == 0.0 )
692  return vol2;
693 
694  return ivol / vol2;
695 }
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: