PostGIS  2.2.7dev-r@@SVN_REVISION@@
static CIRC_NODE * circ_nodes_merge ( CIRC_NODE **  nodes,
int  num_nodes 
)
static

Definition at line 383 of file lwgeodetic_tree.c.

References circ_node_internal_new(), CIRC_NODE_SIZE, lwalloc(), and lwfree().

Referenced by circ_tree_new(), lwcollection_calculate_circ_tree(), and lwpoly_calculate_circ_tree().

384 {
385  CIRC_NODE **inodes = NULL;
386  int num_children = num_nodes;
387  int inode_num = 0;
388  int num_parents = 0;
389  int j;
390 
391  /* TODO, roll geom_type *up* as tree is built, changing to collection types as simple types are merged
392  * TODO, change the distance algorithm to drive down to simple types first, test pip on poly/other cases, then test edges
393  */
394 
395  while( num_children > 1 )
396  {
397  for ( j = 0; j < num_children; j++ )
398  {
399  inode_num = (j % CIRC_NODE_SIZE);
400  if ( inode_num == 0 )
401  inodes = lwalloc(sizeof(CIRC_NODE*)*CIRC_NODE_SIZE);
402 
403  inodes[inode_num] = nodes[j];
404 
405  if ( inode_num == CIRC_NODE_SIZE-1 )
406  nodes[num_parents++] = circ_node_internal_new(inodes, CIRC_NODE_SIZE);
407  }
408 
409  /* Clean up any remaining nodes... */
410  if ( inode_num == 0 )
411  {
412  /* Promote solo nodes without merging */
413  nodes[num_parents++] = inodes[0];
414  lwfree(inodes);
415  }
416  else if ( inode_num < CIRC_NODE_SIZE-1 )
417  {
418  /* Merge spare nodes */
419  nodes[num_parents++] = circ_node_internal_new(inodes, inode_num+1);
420  }
421 
422  num_children = num_parents;
423  num_parents = 0;
424  }
425 
426  /* Return a reference to the head of the tree */
427  return nodes[0];
428 }
#define CIRC_NODE_SIZE
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void lwfree(void *mem)
Definition: lwutil.c:214
void * lwalloc(size_t size)
Definition: lwutil.c:199
static CIRC_NODE * circ_node_internal_new(CIRC_NODE **c, int num_nodes)
Create a new internal node, calculating the new measure range for the node, and storing pointers to t...

Here is the call graph for this function:

Here is the caller graph for this function: