PostGIS  2.4.9dev-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 674 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().

675 {
676  int d;
677  bool covered = TRUE;
678  double ivol = 1.0;
679  double vol2 = 1.0;
680  double vol1 = 1.0;
681 
682  for ( d = 0 ; d < ndims; d++ )
683  {
684  if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
685  return 0.0; /* Disjoint */
686 
687  if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
688  covered = FALSE;
689  }
690 
691  if ( covered )
692  return 1.0;
693 
694  for ( d = 0; d < ndims; d++ )
695  {
696  double width1 = b1->max[d] - b1->min[d];
697  double width2 = b2->max[d] - b2->min[d];
698  double imin, imax, iwidth;
699 
700  vol1 *= width1;
701  vol2 *= width2;
702 
703  imin = Max(b1->min[d], b2->min[d]);
704  imax = Min(b1->max[d], b2->max[d]);
705  iwidth = imax - imin;
706  iwidth = Max(0.0, iwidth);
707 
708  ivol *= iwidth;
709  }
710 
711  if ( vol2 == 0.0 )
712  return vol2;
713 
714  return ivol / vol2;
715 }
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: