PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rect_tree_from_ptarray()

RECT_NODE* rect_tree_from_ptarray ( const POINTARRAY pa,
int  geom_type 
)

Definition at line 632 of file lwtree.c.

633 {
634  int num_edges = 0, i = 0, j = 0;
635  RECT_NODE_SEG_TYPE seg_type = lwgeomTypeArc[geom_type];
636  RECT_NODE **nodes = NULL;
637  RECT_NODE *tree = NULL;
638 
639  /* No-op on empty ring/line/pt */
640  if ( pa->npoints < 1 )
641  return NULL;
642 
643  /* For arcs, 3 points per edge, for lines, 2 per edge */
644  switch(seg_type)
645  {
646  case RECT_NODE_SEG_POINT:
647  return rect_node_leaf_new(pa, 0, geom_type);
648  break;
650  num_edges = pa->npoints - 1;
651  break;
653  num_edges = (pa->npoints - 1)/2;
654  break;
655  default:
656  lwerror("%s: unsupported seg_type - %d", __func__, seg_type);
657  }
658 
659  /* First create a flat list of nodes, one per edge. */
660  nodes = lwalloc(sizeof(RECT_NODE*) * num_edges);
661  for (i = 0; i < num_edges; i++)
662  {
663  RECT_NODE *node = rect_node_leaf_new(pa, i, geom_type);
664  if (node) /* Not zero length? */
665  nodes[j++] = node;
666  }
667 
668  /* Merge the list into a tree */
669  tree = rect_nodes_merge(nodes, j);
670 
671  /* Free the old list structure, leaving the tree in place */
672  lwfree(nodes);
673 
674  /* Return top of tree */
675  return tree;
676 }
void lwfree(void *mem)
Definition: lwutil.c:244
void * lwalloc(size_t size)
Definition: lwutil.c:229
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static RECT_NODE_SEG_TYPE lwgeomTypeArc[]
Definition: lwtree.c:466
static RECT_NODE * rect_nodes_merge(RECT_NODE **nodes, uint32_t num_nodes)
Definition: lwtree.c:596
static RECT_NODE * rect_node_leaf_new(const POINTARRAY *pa, int seg_num, int geom_type)
Definition: lwtree.c:490
RECT_NODE_SEG_TYPE
Definition: lwtree.h:41
@ RECT_NODE_SEG_POINT
Definition: lwtree.h:43
@ RECT_NODE_SEG_LINEAR
Definition: lwtree.h:44
@ RECT_NODE_SEG_CIRCULAR
Definition: lwtree.h:45
uint32_t npoints
Definition: liblwgeom.h:374

References lwalloc(), lwerror(), lwfree(), lwgeomTypeArc, POINTARRAY::npoints, rect_node_leaf_new(), RECT_NODE_SEG_CIRCULAR, RECT_NODE_SEG_LINEAR, RECT_NODE_SEG_POINT, and rect_nodes_merge().

Referenced by rect_tree_from_lwline(), rect_tree_from_lwpoint(), and rect_tree_from_lwpoly().

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