PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 705 of file gserialized_estimate.c.

706{
707 int d;
708 bool covered = true;
709 double ivol = 1.0;
710 double vol2 = 1.0;
711 double vol1 = 1.0;
712
713 for ( d = 0 ; d < ndims; d++ )
714 {
715 if ( b1->max[d] <= b2->min[d] || b1->min[d] >= b2->max[d] )
716 return 0.0; /* Disjoint */
717
718 if ( b1->min[d] > b2->min[d] || b1->max[d] < b2->max[d] )
719 covered = false;
720 }
721
722 if ( covered )
723 return 1.0;
724
725 for ( d = 0; d < ndims; d++ )
726 {
727 double width1 = b1->max[d] - b1->min[d];
728 double width2 = b2->max[d] - b2->min[d];
729 double imin, imax, iwidth;
730
731 vol1 *= width1;
732 vol2 *= width2;
733
734 imin = Max(b1->min[d], b2->min[d]);
735 imax = Min(b1->max[d], b2->max[d]);
736 iwidth = imax - imin;
737 iwidth = Max(0.0, iwidth);
738
739 ivol *= iwidth;
740 }
741
742 if ( vol2 == 0.0 )
743 return vol2;
744
745 return ivol / vol2;
746}
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: