PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rect_tree_distance_tree_recursive()

static double rect_tree_distance_tree_recursive ( RECT_NODE n1,
RECT_NODE n2,
RECT_TREE_DISTANCE_STATE state 
)
static

Definition at line 1290 of file lwtree.c.

1291 {
1292  double min, max;
1293 
1294  /* Short circuit if we've already hit the minimum */
1295  if (state->min_dist < state->threshold || state->min_dist == 0.0)
1296  return state->min_dist;
1297 
1298  /* If your minimum is greater than anyone's maximum, you can't hold the winner */
1299  min = rect_node_min_distance(n1, n2);
1300  if (min > state->max_dist)
1301  {
1302  //lwnotice("pruning pair %p, %p", n1, n2);
1303  LWDEBUGF(4, "pruning pair %p, %p", n1, n2);
1304  return FLT_MAX;
1305  }
1306 
1307  /* If your maximum is a new low, we'll use that as our new global tolerance */
1308  max = rect_node_max_distance(n1, n2);
1309  if (max < state->max_dist)
1310  state->max_dist = max;
1311 
1312  /* Both leaf nodes, do a real distance calculation */
1313  if (rect_node_is_leaf(n1) && rect_node_is_leaf(n2))
1314  {
1315  return rect_leaf_node_distance(&n1->l, &n2->l, state);
1316  }
1317  /* Recurse into nodes */
1318  else
1319  {
1320  int i, j;
1321  double d_min = FLT_MAX;
1322  rect_tree_node_sort(n1, n2);
1323  if (rect_node_is_leaf(n1) && !rect_node_is_leaf(n2))
1324  {
1325  for (i = 0; i < n2->i.num_nodes; i++)
1326  {
1327  min = rect_tree_distance_tree_recursive(n1, n2->i.nodes[i], state);
1328  d_min = FP_MIN(d_min, min);
1329  }
1330  }
1331  else if (rect_node_is_leaf(n2) && !rect_node_is_leaf(n1))
1332  {
1333  for (i = 0; i < n1->i.num_nodes; i++)
1334  {
1335  min = rect_tree_distance_tree_recursive(n1->i.nodes[i], n2, state);
1336  d_min = FP_MIN(d_min, min);
1337  }
1338  }
1339  else
1340  {
1341  for (i = 0; i < n1->i.num_nodes; i++)
1342  {
1343  for (j = 0; j < n2->i.num_nodes; j++)
1344  {
1345  min = rect_tree_distance_tree_recursive(n1->i.nodes[i], n2->i.nodes[j], state);
1346  d_min = FP_MIN(d_min, min);
1347  }
1348  }
1349  }
1350  return d_min;
1351  }
1352 }
#define FP_MIN(A, B)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
static double rect_node_max_distance(const RECT_NODE *n1, const RECT_NODE *n2)
Definition: lwtree.c:1078
static double rect_tree_distance_tree_recursive(RECT_NODE *n1, RECT_NODE *n2, RECT_TREE_DISTANCE_STATE *state)
Definition: lwtree.c:1290
static double rect_node_min_distance(const RECT_NODE *n1, const RECT_NODE *n2)
Definition: lwtree.c:1042
static double rect_leaf_node_distance(const RECT_NODE_LEAF *n1, const RECT_NODE_LEAF *n2, RECT_TREE_DISTANCE_STATE *state)
Definition: lwtree.c:1100
static int rect_node_is_leaf(const RECT_NODE *node)
Definition: lwtree.c:31
static void rect_tree_node_sort(RECT_NODE *n1, RECT_NODE *n2)
Definition: lwtree.c:1248
struct rect_node * nodes[RECT_NODE_SIZE]
Definition: lwtree.h:61
RECT_NODE_INTERNAL i
Definition: lwtree.h:75
RECT_NODE_LEAF l
Definition: lwtree.h:76

References FP_MIN, rect_node::i, rect_node::l, LWDEBUGF, rect_tree_distance_state::max_dist, rect_tree_distance_state::min_dist, RECT_NODE_INTERNAL::nodes, RECT_NODE_INTERNAL::num_nodes, rect_leaf_node_distance(), rect_node_is_leaf(), rect_node_max_distance(), rect_node_min_distance(), rect_tree_node_sort(), and rect_tree_distance_state::threshold.

Referenced by rect_tree_distance_tree().

Here is the call graph for this function:
Here is the caller graph for this function: