PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ box2df_distance()

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

Calculate the box->box distance.

Definition at line 396 of file gserialized_gist_2d.c.

397 {
398  /* Check for overlap */
399  if ( box2df_overlaps(a, b) )
400  return 0.0;
401 
402  if ( box2df_left(a, b) )
403  {
404  if ( box2df_above(a, b) )
405  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
406  if ( box2df_below(a, b) )
407  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
408  else
409  return (double)b->xmin - (double)a->xmax;
410  }
411  if ( box2df_right(a, b) )
412  {
413  if ( box2df_above(a, b) )
414  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
415  if ( box2df_below(a, b) )
416  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
417  else
418  return (double)a->xmin - (double)b->xmax;
419  }
420  if ( box2df_above(a, b) )
421  {
422  if ( box2df_left(a, b) )
423  return pt_distance(a->xmax, a->ymin, b->xmin, b->ymax);
424  if ( box2df_right(a, b) )
425  return pt_distance(a->xmin, a->ymin, b->xmax, b->ymax);
426  else
427  return (double)a->ymin - (double)b->ymax;
428  }
429  if ( box2df_below(a, b) )
430  {
431  if ( box2df_left(a, b) )
432  return pt_distance(a->xmax, a->ymax, b->xmin, b->ymin);
433  if ( box2df_right(a, b) )
434  return pt_distance(a->xmin, a->ymax, b->xmax, b->ymin);
435  else
436  return (double)b->ymin - (double)a->ymax;
437  }
438 
439  return FLT_MAX;
440 }
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: