PostGIS  3.7.0dev-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 354 of file lwgeodetic_tree.c.

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

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().

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