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

◆ gidx_distance()

static double gidx_distance ( const GIDX *  a,
const GIDX *  b,
int  m_is_time 
)
static

Calculate the box->box distance.

Definition at line 569 of file gserialized_gist_nd.c.

570{
571 int ndims, i;
572 double sum = 0;
573
574 /* Base computation on least available dimensions */
575 ndims = Min(GIDX_NDIMS(b), GIDX_NDIMS(a));
576 for (i = 0; i < ndims; ++i)
577 {
578 double d;
579 double amin = GIDX_GET_MIN(a, i);
580 double amax = GIDX_GET_MAX(a, i);
581 double bmin = GIDX_GET_MIN(b, i);
582 double bmax = GIDX_GET_MAX(b, i);
583 POSTGIS_DEBUGF(3, "A %g - %g", amin, amax);
584 POSTGIS_DEBUGF(3, "B %g - %g", bmin, bmax);
585
586 if ((amin <= bmax && amax >= bmin))
587 {
588 /* overlaps */
589 d = 0;
590 }
591 else if (i == 4 && m_is_time)
592 {
593 return FLT_MAX;
594 }
595 else if (bmax < amin)
596 {
597 /* is "left" */
598 d = amin - bmax;
599 }
600 else
601 {
602 /* is "right" */
603 assert(bmin > amax);
604 d = bmin - amax;
605 }
606 if (!isfinite(d))
607 {
608 /* Can happen if coordinates are corrupted/NaN */
609 continue;
610 }
611 sum += d * d;
612 POSTGIS_DEBUGF(3, "dist %g, squared %g, grows sum to %g", d, d * d, sum);
613 }
614 return sqrt(sum);
615}

Referenced by gserialized_gist_distance(), and gserialized_gist_geog_distance().

Here is the caller graph for this function: