PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ box2df_distance()

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

Calculate the box->box distance.

Definition at line 533 of file gserialized_gist_2d.c.

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().

534 {
535  /* Check for overlap */
536  if ( box2df_overlaps(a, b) )
537  return 0.0;
538 
539  if ( box2df_left(a, b) )
540  {
541  if ( box2df_above(a, b) )
542  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
543  if ( box2df_below(a, b) )
544  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
545  else
546  return (double)b->xmin - (double)a->xmax;
547  }
548  if ( box2df_right(a, b) )
549  {
550  if ( box2df_above(a, b) )
551  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
552  if ( box2df_below(a, b) )
553  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
554  else
555  return (double)a->xmin - (double)b->xmax;
556  }
557  if ( box2df_above(a, b) )
558  {
559  if ( box2df_left(a, b) )
560  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
561  if ( box2df_right(a, b) )
562  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
563  else
564  return (double)a->ymin - (double)b->ymax;
565  }
566  if ( box2df_below(a, b) )
567  {
568  if ( box2df_left(a, b) )
569  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
570  if ( box2df_right(a, b) )
571  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
572  else
573  return (double)b->ymin - (double)a->ymax;
574  }
575 
576  return FLT_MAX;
577 }
static bool box2df_overlaps(const BOX2DF *a, const BOX2DF *b)
static bool box2df_left(const BOX2DF *a, const BOX2DF *b)
static bool box2df_below(const BOX2DF *a, const BOX2DF *b)
static bool box2df_right(const BOX2DF *a, const BOX2DF *b)
static bool box2df_above(const BOX2DF *a, const BOX2DF *b)
static double pt_distance(double ax, double ay, double bx, double by)
Here is the call graph for this function:
Here is the caller graph for this function: