PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ box2df_distance()

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

Calculate the box->box distance.

Definition at line 409 of file gserialized_gist_2d.c.

410 {
411  /* Check for overlap */
412  if ( box2df_overlaps(a, b) )
413  return 0.0;
414 
415  if ( box2df_left(a, b) )
416  {
417  if ( box2df_above(a, b) )
418  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
419  if ( box2df_below(a, b) )
420  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
421  else
422  return (double)b->xmin - (double)a->xmax;
423  }
424  if ( box2df_right(a, b) )
425  {
426  if ( box2df_above(a, b) )
427  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
428  if ( box2df_below(a, b) )
429  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
430  else
431  return (double)a->xmin - (double)b->xmax;
432  }
433  if ( box2df_above(a, b) )
434  {
435  if ( box2df_left(a, b) )
436  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
437  if ( box2df_right(a, b) )
438  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
439  else
440  return (double)a->ymin - (double)b->ymax;
441  }
442  if ( box2df_below(a, b) )
443  {
444  if ( box2df_left(a, b) )
445  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
446  if ( box2df_right(a, b) )
447  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
448  else
449  return (double)b->ymin - (double)a->ymax;
450  }
451 
452  return FLT_MAX;
453 }
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: