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