PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rect_node_leaf_new()

static RECT_NODE* rect_node_leaf_new ( const POINTARRAY pa,
int  seg_num,
int  geom_type 
)
static

Definition at line 490 of file lwtree.c.

491 {
492  const POINT2D *p1, *p2, *p3;
493  RECT_NODE *node;
494  GBOX gbox;
495  RECT_NODE_SEG_TYPE seg_type = lwgeomTypeArc[geom_type];
496 
497  switch (seg_type)
498  {
499  case RECT_NODE_SEG_POINT:
500  {
501  p1 = getPoint2d_cp(pa, seg_num);
502  gbox.xmin = gbox.xmax = p1->x;
503  gbox.ymin = gbox.ymax = p1->y;
504  break;
505  }
506 
508  {
509  p1 = getPoint2d_cp(pa, seg_num);
510  p2 = getPoint2d_cp(pa, seg_num+1);
511  /* Zero length edge, doesn't get a node */
512  if ((p1->x == p2->x) && (p1->y == p2->y))
513  return NULL;
514  gbox.xmin = FP_MIN(p1->x, p2->x);
515  gbox.xmax = FP_MAX(p1->x, p2->x);
516  gbox.ymin = FP_MIN(p1->y, p2->y);
517  gbox.ymax = FP_MAX(p1->y, p2->y);
518  break;
519  }
520 
522  {
523  p1 = getPoint2d_cp(pa, 2*seg_num);
524  p2 = getPoint2d_cp(pa, 2*seg_num+1);
525  p3 = getPoint2d_cp(pa, 2*seg_num+2);
526  /* Zero length edge, doesn't get a node */
527  if ((p1->x == p2->x) && (p2->x == p3->x) &&
528  (p1->y == p2->y) && (p2->y == p3->y))
529  return NULL;
530  lw_arc_calculate_gbox_cartesian_2d(p1, p2, p3, &gbox);
531  break;
532  }
533 
534  default:
535  {
536  lwerror("%s: unsupported seg_type - %d", __func__, seg_type);
537  return NULL;
538  }
539  }
540 
541  node = lwalloc(sizeof(RECT_NODE));
542  node->type = RECT_NODE_LEAF_TYPE;
543  node->geom_type = geom_type;
544  node->xmin = gbox.xmin;
545  node->xmax = gbox.xmax;
546  node->ymin = gbox.ymin;
547  node->ymax = gbox.ymax;
548  node->l.seg_num = seg_num;
549  node->l.seg_type = seg_type;
550  node->l.pa = pa;
551  return node;
552 }
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
Definition: g_box.c:459
void * lwalloc(size_t size)
Definition: lwutil.c:229
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwgeom_api.c:374
#define FP_MAX(A, B)
#define FP_MIN(A, B)
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
@ RECT_NODE_LEAF_TYPE
Definition: lwtree.h:30
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
double ymax
Definition: liblwgeom.h:298
double xmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
const POINTARRAY * pa
Definition: lwtree.h:50
int seg_num
Definition: lwtree.h:52
RECT_NODE_SEG_TYPE seg_type
Definition: lwtree.h:51
RECT_NODE_TYPE type
Definition: lwtree.h:67
double ymin
Definition: lwtree.h:71
double xmax
Definition: lwtree.h:70
double ymax
Definition: lwtree.h:72
RECT_NODE_LEAF l
Definition: lwtree.h:76
unsigned char geom_type
Definition: lwtree.h:68
double xmin
Definition: lwtree.h:69

References FP_MAX, FP_MIN, rect_node::geom_type, getPoint2d_cp(), rect_node::l, lw_arc_calculate_gbox_cartesian_2d(), lwalloc(), lwerror(), lwgeomTypeArc, RECT_NODE_LEAF::pa, RECT_NODE_LEAF_TYPE, RECT_NODE_SEG_CIRCULAR, RECT_NODE_SEG_LINEAR, RECT_NODE_SEG_POINT, RECT_NODE_LEAF::seg_num, RECT_NODE_LEAF::seg_type, rect_node::type, POINT2D::x, GBOX::xmax, rect_node::xmax, GBOX::xmin, rect_node::xmin, POINT2D::y, GBOX::ymax, rect_node::ymax, GBOX::ymin, and rect_node::ymin.

Referenced by rect_tree_from_ptarray().

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