PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ box2df_distance()

static double box2df_distance ( const BOX2DF *  a,
const BOX2DF *  b 
)
static

Calculate the box->box distance.

Definition at line 589 of file gserialized_gist_2d.c.

590 {
591  /* Check for overlap */
592  if ( box2df_overlaps(a, b) )
593  return 0.0;
594 
595  if ( box2df_left(a, b) )
596  {
597  if ( box2df_above(a, b) )
598  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
599  if ( box2df_below(a, b) )
600  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
601  else
602  return (double)b->xmin - (double)a->xmax;
603  }
604  if ( box2df_right(a, b) )
605  {
606  if ( box2df_above(a, b) )
607  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
608  if ( box2df_below(a, b) )
609  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
610  else
611  return (double)a->xmin - (double)b->xmax;
612  }
613  if ( box2df_above(a, b) )
614  {
615  if ( box2df_left(a, b) )
616  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
617  if ( box2df_right(a, b) )
618  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
619  else
620  return (double)a->ymin - (double)b->ymax;
621  }
622  if ( box2df_below(a, b) )
623  {
624  if ( box2df_left(a, b) )
625  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
626  if ( box2df_right(a, b) )
627  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
628  else
629  return (double)b->ymin - (double)a->ymax;
630  }
631 
632  return FLT_MAX;
633 }
bool box2df_left(const BOX2DF *a, const BOX2DF *b)
bool box2df_right(const BOX2DF *a, const BOX2DF *b)
bool box2df_overlaps(const BOX2DF *a, const BOX2DF *b)
bool box2df_above(const BOX2DF *a, const BOX2DF *b)
static double pt_distance(double ax, double ay, double bx, double by)
bool box2df_below(const BOX2DF *a, const BOX2DF *b)

References box2df_above(), box2df_below(), box2df_left(), box2df_overlaps(), box2df_right(), and pt_distance().

Referenced by gserialized_distance_box_2d(), and gserialized_gist_distance_2d().

Here is the call graph for this function:
Here is the caller graph for this function: