PostGIS  2.2.7dev-r@@SVN_REVISION@@
CIRC_NODE* circ_tree_new ( const POINTARRAY pa)

Build a tree of nodes from a point array, one node per edge.

Definition at line 328 of file lwgeodetic_tree.c.

References circ_node_leaf_new(), circ_node_leaf_point_new(), circ_nodes_merge(), lwalloc(), lwfree(), and POINTARRAY::npoints.

Referenced by lwline_calculate_circ_tree(), lwpoint_calculate_circ_tree(), lwpoly_calculate_circ_tree(), test_tree_circ_create(), test_tree_circ_pip(), and test_tree_circ_pip2().

329 {
330  int num_edges;
331  int i, j;
332  CIRC_NODE **nodes;
333  CIRC_NODE *node;
334  CIRC_NODE *tree;
335 
336  /* Can't do anything with no points */
337  if ( pa->npoints < 1 )
338  return NULL;
339 
340  /* Special handling for a single point */
341  if ( pa->npoints == 1 )
342  return circ_node_leaf_point_new(pa);
343 
344  /* First create a flat list of nodes, one per edge. */
345  num_edges = pa->npoints - 1;
346  nodes = lwalloc(sizeof(CIRC_NODE*) * pa->npoints);
347  j = 0;
348  for ( i = 0; i < num_edges; i++ )
349  {
350  node = circ_node_leaf_new(pa, i);
351  if ( node ) /* Not zero length? */
352  nodes[j++] = node;
353  }
354 
355  /* Special case: only zero-length edges. Make a point node. */
356  if ( j == 0 ) {
357  lwfree(nodes);
358  return circ_node_leaf_point_new(pa);
359  }
360 
361  /* Merge the node list pairwise up into a tree */
362  tree = circ_nodes_merge(nodes, j);
363 
364  /* Free the old list structure, leaving the tree in place */
365  lwfree(nodes);
366 
367  return tree;
368 }
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void lwfree(void *mem)
Definition: lwutil.c:214
int npoints
Definition: liblwgeom.h:355
static CIRC_NODE * circ_node_leaf_new(const POINTARRAY *pa, int i)
Create a new leaf node, storing pointers back to the end points for later.
static CIRC_NODE * circ_nodes_merge(CIRC_NODE **nodes, int num_nodes)
static CIRC_NODE * circ_node_leaf_point_new(const POINTARRAY *pa)
Return a point node (zero radius, referencing one point)
void * lwalloc(size_t size)
Definition: lwutil.c:199

Here is the call graph for this function:

Here is the caller graph for this function: