PostGIS  2.3.7dev-r@@SVN_REVISION@@
static void test_tree_circ_pip ( void  )
static

Definition at line 47 of file cu_tree.c.

References circ_tree_contains_point(), circ_tree_free(), circ_tree_new(), LW_PARSER_CHECK_NONE, lwgeom_as_lwline(), lwgeom_from_wkt(), lwline_free(), LWLINE::points, POINT2D::x, and POINT2D::y.

Referenced by tree_suite_setup().

48 {
49  LWLINE *g;
50  CIRC_NODE *c;
51  POINT2D pt, pt_outside;
52  int rv, on_boundary;
53 
54  pt.x = 0.0;
55  pt.y = 0.0;
56  pt_outside.x = -2.0;
57  pt_outside.y = 0.0;
58 
59  /* Point in square */
60  g = lwgeom_as_lwline(lwgeom_from_wkt("LINESTRING(-1 -1,1 -1,1 1,-1 1,-1 -1)", LW_PARSER_CHECK_NONE));
61  c = circ_tree_new(g->points);
62  rv = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary);
63  CU_ASSERT_EQUAL(rv, 1);
64 
65  /* Point on other side of square */
66  pt.x = 2.0;
67  pt.y = 0.0;
68  rv = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary);
69  CU_ASSERT_EQUAL(rv, 0);
70 
71  /* Clean and do new shape */
72  circ_tree_free(c);
73  lwline_free(g);
74 
75  /* Point in square, stab passing through vertex */
76  pt.x = 0.0;
77  pt.y = 0.0;
78  g = lwgeom_as_lwline(lwgeom_from_wkt("LINESTRING(-1 -1,0 -1,1 -1,1 0,1 1,0 1,-1 1,-1 0,-1 -1)", LW_PARSER_CHECK_NONE));
79  c = circ_tree_new(g->points);
80  //circ_tree_print(c, 0);
81  rv = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary);
82  CU_ASSERT_EQUAL(rv, 1);
83 
84  /* Point on other side of square, stab passing through vertex */
85  pt.x = 2.0;
86  pt.y = 0.0;
87  rv = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary);
88  CU_ASSERT_EQUAL(rv, 0);
89 
90  /* Clean and do new shape */
91  circ_tree_free(c);
92  lwline_free(g);
93 
94  /* Point outside "w" thing, stab passing through vertexes and grazing pointy thing */
95  pt.x = 2.0;
96  pt.y = 0.0;
97  g = lwgeom_as_lwline(lwgeom_from_wkt("LINESTRING(-1 -1,0 -1,1 -1,1 0,1 1,0 0,-1 1,-1 0,-1 -1)", LW_PARSER_CHECK_NONE));
98  c = circ_tree_new(g->points);
99  //circ_tree_print(c, 0);
100  rv = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary);
101  //printf("rv %d\n", rv);
102  CU_ASSERT_EQUAL(rv, 0);
103 
104  /* Point inside "w" thing, stab passing through vertexes and grazing pointy thing */
105  pt.x = 0.8;
106  pt.y = 0.0;
107  rv = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary);
108  //printf("rv %d\n", rv);
109  CU_ASSERT_EQUAL(rv, 1);
110 
111  /* Clean and do new shape */
112  circ_tree_free(c);
113  lwline_free(g);
114 
115 }
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
double x
Definition: liblwgeom.h:327
CIRC_NODE * circ_tree_new(const POINTARRAY *pa)
Build a tree of nodes from a point array, one node per edge.
int circ_tree_contains_point(const CIRC_NODE *node, const POINT2D *pt, const POINT2D *pt_outside, int *on_boundary)
Walk the tree and count intersections between the stab line and the edges.
double y
Definition: liblwgeom.h:327
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:102
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
POINTARRAY * points
Definition: liblwgeom.h:421

Here is the call graph for this function:

Here is the caller graph for this function: