PostGIS  2.1.10dev-r@@SVN_REVISION@@
static double box2df_distance_node_centroid ( const BOX2DF *  node,
const BOX2DF *  query 
)
static

Calculate the The node_box_edge->query_centroid distance between the boxes.

Definition at line 397 of file gserialized_gist_2d.c.

References box2df_overlaps(), and LW_TRUE.

Referenced by gserialized_gist_distance_2d().

398 {
399  BOX2DF q;
400  double qx, qy;
401  double d = 0.0;
402 
403  /* Turn query into point */
404  q.xmin = q.xmax = (query->xmin + query->xmax) / 2.0;
405  q.ymin = q.ymax = (query->ymin + query->ymax) / 2.0;
406  qx = q.xmin;
407  qy = q.ymin;
408 
409  /* Check for overlap */
410  if ( box2df_overlaps(node, &q) == LW_TRUE )
411  return 0.0;
412 
413  /* Above or below */
414  if ( qx >= node->xmin && qx <= node->xmax )
415  {
416  if( qy > node->ymax )
417  d = qy - node->ymax;
418  else if ( qy < node->ymin )
419  d = node->ymin - qy;
420  return d;
421  }
422  /* Left or right */
423  else if ( qy >= node->ymin && qy <= node->ymax )
424  {
425  if ( qx > node->xmax )
426  d = qx - node->xmax;
427  else if ( qx < node->xmin )
428  d = node->xmin - qx;
429  return d;
430  }
431  /* Corner quadrants */
432  else
433  {
434  /* below/left of xmin/ymin */
435  if ( qx < node->xmin && qy < node->ymin )
436  {
437  d = (node->xmin - qx) * (node->xmin - qx) +
438  (node->ymin - qy) * (node->ymin - qy);
439  }
440  /* above/left of xmin/ymax */
441  else if ( qx < node->xmin && qy > node->ymax )
442  {
443  d = (node->xmin - qx) * (node->xmin - qx) +
444  (node->ymax - qy) * (node->ymax - qy);
445  }
446  /* above/right of xmax/ymax */
447  else if ( qx > node->xmax && qy > node->ymax )
448  {
449  d = (node->xmax - qx) * (node->xmax - qx) +
450  (node->ymax - qy) * (node->ymax - qy);
451  }
452  /* below/right of xmax/ymin */
453  else if ( qx > node->xmin && qy < node->ymin )
454  {
455  d = (node->xmax - qx) * (node->xmax - qx) +
456  (node->ymin - qy) * (node->ymin - qy);
457  }
458  else
459  {
460  /*ERROR*/
461  }
462  }
463 
464  return sqrt(d);
465 }
static bool box2df_overlaps(const BOX2DF *a, const BOX2DF *b)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51

Here is the call graph for this function:

Here is the caller graph for this function: