PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rect_tree_intersects_tree()

int rect_tree_intersects_tree ( const RECT_NODE tree1,
const RECT_NODE tree2 
)

Definition at line 79 of file lwtree.c.

References FP_GT, rect_node::left_node, LW_FALSE, lw_segment_intersects(), LW_TRUE, LWDEBUG, LWDEBUGF, rect_node::p1, rect_node::p2, rect_node_is_leaf(), rect_tree_intersects_tree(), rect_node::right_node, rect_node::xmax, rect_node::xmin, rect_node::ymax, and rect_node::ymin.

Referenced by rect_tree_intersects_tree(), and test_rect_tree_intersects_tree().

80 {
81  LWDEBUGF(4,"n1 (%.9g %.9g,%.9g %.9g) vs n2 (%.9g %.9g,%.9g %.9g)",n1->xmin,n1->ymin,n1->xmax,n1->ymax,n2->xmin,n2->ymin,n2->xmax,n2->ymax);
82  /* There can only be an edge intersection if the rectangles overlap */
83  if ( ! ( FP_GT(n1->xmin, n2->xmax) || FP_GT(n2->xmin, n1->xmax) || FP_GT(n1->ymin, n2->ymax) || FP_GT(n2->ymin, n1->ymax) ) )
84  {
85  LWDEBUG(4," interaction found");
86  /* We can only test for a true intersection if the nodes are both leaf nodes */
87  if ( rect_node_is_leaf(n1) && rect_node_is_leaf(n2) )
88  {
89  LWDEBUG(4," leaf node test");
90  /* Check for true intersection */
91  if ( lw_segment_intersects(n1->p1, n1->p2, n2->p1, n2->p2) )
92  return LW_TRUE;
93  else
94  return LW_FALSE;
95  }
96  else
97  {
98  LWDEBUG(4," internal node found, recursing");
99  /* Recurse to children */
100  if ( rect_node_is_leaf(n1) )
101  {
102  if ( rect_tree_intersects_tree(n2->left_node, n1) || rect_tree_intersects_tree(n2->right_node, n1) )
103  return LW_TRUE;
104  else
105  return LW_FALSE;
106  }
107  else
108  {
109  if ( rect_tree_intersects_tree(n1->left_node, n2) || rect_tree_intersects_tree(n1->right_node, n2) )
110  return LW_TRUE;
111  else
112  return LW_FALSE;
113  }
114  }
115  }
116  else
117  {
118  LWDEBUG(4," no interaction found");
119  return LW_FALSE;
120  }
121 }
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
static int rect_node_is_leaf(const RECT_NODE *node)
Internal nodes have their point references set to NULL.
Definition: lwtree.c:33
#define LW_FALSE
Definition: liblwgeom.h:77
#define FP_GT(A, B)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
int rect_tree_intersects_tree(const RECT_NODE *n1, const RECT_NODE *n2)
Definition: lwtree.c:79
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
returns the kind of CG_SEGMENT_INTERSECTION_TYPE behavior of lineseg 1 (constructed from p1 and p2) a...
Definition: lwalgorithm.c:371
Here is the call graph for this function:
Here is the caller graph for this function: