PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ circ_tree_new()

CIRC_NODE* circ_tree_new ( const POINTARRAY pa)

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

Definition at line 353 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().

354 {
355  int num_edges;
356  int i, j;
357  CIRC_NODE **nodes;
358  CIRC_NODE *node;
359  CIRC_NODE *tree;
360 
361  /* Can't do anything with no points */
362  if ( pa->npoints < 1 )
363  return NULL;
364 
365  /* Special handling for a single point */
366  if ( pa->npoints == 1 )
367  return circ_node_leaf_point_new(pa);
368 
369  /* First create a flat list of nodes, one per edge. */
370  num_edges = pa->npoints - 1;
371  nodes = lwalloc(sizeof(CIRC_NODE*) * pa->npoints);
372  j = 0;
373  for ( i = 0; i < num_edges; i++ )
374  {
375  node = circ_node_leaf_new(pa, i);
376  if ( node ) /* Not zero length? */
377  nodes[j++] = node;
378  }
379 
380  /* Special case: only zero-length edges. Make a point node. */
381  if ( j == 0 ) {
382  lwfree(nodes);
383  return circ_node_leaf_point_new(pa);
384  }
385 
386  /* Merge the node list pairwise up into a tree */
387  tree = circ_nodes_merge(nodes, j);
388 
389  /* Free the old list structure, leaving the tree in place */
390  lwfree(nodes);
391 
392  return tree;
393 }
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void lwfree(void *mem)
Definition: lwutil.c:244
int npoints
Definition: liblwgeom.h:371
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:229
Here is the call graph for this function:
Here is the caller graph for this function: