PostGIS  2.2.7dev-r@@SVN_REVISION@@
static double box2df_distance ( const BOX2DF *  a,
const BOX2DF *  b 
)
static

Calculate the box->box distance.

Definition at line 474 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().

475 {
476  /* Check for overlap */
477  if ( box2df_overlaps(a, b) )
478  return 0.0;
479 
480  if ( box2df_left(a, b) )
481  {
482  if ( box2df_above(a, b) )
483  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
484  if ( box2df_below(a, b) )
485  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
486  else
487  return (double)b->xmin - (double)a->xmax;
488  }
489  if ( box2df_right(a, b) )
490  {
491  if ( box2df_above(a, b) )
492  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
493  if ( box2df_below(a, b) )
494  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
495  else
496  return (double)a->xmin - (double)b->xmax;
497  }
498  if ( box2df_above(a, b) )
499  {
500  if ( box2df_left(a, b) )
501  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
502  if ( box2df_right(a, b) )
503  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
504  else
505  return (double)a->ymin - (double)b->ymax;
506  }
507  if ( box2df_below(a, b) )
508  {
509  if ( box2df_left(a, b) )
510  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
511  if ( box2df_right(a, b) )
512  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
513  else
514  return (double)b->ymin - (double)a->ymax;
515  }
516 
517  return FLT_MAX;
518 }
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: