PostGIS  3.2.2dev-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 722 of file gserialized_estimate.c.

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