PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ box2df_distance_node_centroid()

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 393 of file gserialized_gist_2d.c.

References box2df_overlaps(), and LW_TRUE.

Referenced by gserialized_gist_distance_2d().

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