PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ box2df_distance()

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

Calculate the box->box distance.

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

499 {
500  /* Check for overlap */
501  if ( box2df_overlaps(a, b) )
502  return 0.0;
503 
504  if ( box2df_left(a, b) )
505  {
506  if ( box2df_above(a, b) )
507  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
508  if ( box2df_below(a, b) )
509  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
510  else
511  return (double)b->xmin - (double)a->xmax;
512  }
513  if ( box2df_right(a, b) )
514  {
515  if ( box2df_above(a, b) )
516  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
517  if ( box2df_below(a, b) )
518  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
519  else
520  return (double)a->xmin - (double)b->xmax;
521  }
522  if ( box2df_above(a, b) )
523  {
524  if ( box2df_left(a, b) )
525  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
526  if ( box2df_right(a, b) )
527  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
528  else
529  return (double)a->ymin - (double)b->ymax;
530  }
531  if ( box2df_below(a, b) )
532  {
533  if ( box2df_left(a, b) )
534  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
535  if ( box2df_right(a, b) )
536  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
537  else
538  return (double)b->ymin - (double)a->ymax;
539  }
540 
541  return FLT_MAX;
542 }
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: