PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_rect_tree_contains_point ( void  )
static

Definition at line 195 of file cu_measures.c.

References boundary(), LW_PARSER_CHECK_NONE, lwgeom_from_wkt(), lwpoly_free(), rect_tree_contains_point(), rect_tree_free(), rect_tree_new(), result, LWPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

196 {
197  LWPOLY *poly;
198  POINT2D p;
199  RECT_NODE* tree;
200  int result;
201  int boundary = 0;
202 
203  /* square */
204  poly = (LWPOLY*)lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
205  tree = rect_tree_new(poly->rings[0]);
206 
207  /* inside square */
208  boundary = 0;
209  p.x = 0.5;
210  p.y = 0.5;
211  result = rect_tree_contains_point(tree, &p, &boundary);
212  CU_ASSERT_NOT_EQUAL(result, 0);
213 
214  /* outside square */
215  boundary = 0;
216  p.x = 1.5;
217  p.y = 0.5;
218  result = rect_tree_contains_point(tree, &p, &boundary);
219  CU_ASSERT_EQUAL(result, 0);
220 
221  rect_tree_free(tree);
222  lwpoly_free(poly);
223 
224  /* ziggy zaggy horizontal saw tooth polygon */
225  poly = (LWPOLY*)lwgeom_from_wkt("POLYGON((0 0, 1 3, 2 0, 3 3, 4 0, 4 5, 0 5, 0 0))", LW_PARSER_CHECK_NONE);
226  tree = rect_tree_new(poly->rings[0]);
227 
228  /* not in, left side */
229  boundary = 0;
230  p.x = -0.5;
231  p.y = 0.5;
232  result = rect_tree_contains_point(tree, &p, &boundary);
233  CU_ASSERT_EQUAL(result, 0);
234 
235  /* not in, right side */
236  boundary = 0;
237  p.x = 3.0;
238  p.y = 1.0;
239  result = rect_tree_contains_point(tree, &p, &boundary);
240  CU_ASSERT_EQUAL(result, 0);
241 
242  /* inside */
243  boundary = 0;
244  p.x = 2.0;
245  p.y = 1.0;
246  result = rect_tree_contains_point(tree, &p, &boundary);
247  CU_ASSERT_NOT_EQUAL(result, 0);
248 
249  /* on left border */
250  boundary = 0;
251  p.x = 0.0;
252  p.y = 1.0;
253  result = rect_tree_contains_point(tree, &p, &boundary);
254  CU_ASSERT_EQUAL(boundary, 1);
255 
256  /* on right border */
257  boundary = 0;
258  p.x = 4.0;
259  p.y = 0.0;
260  result = rect_tree_contains_point(tree, &p, &boundary);
261  CU_ASSERT_EQUAL(boundary, 1);
262 
263  /* on tooth concave */
264  boundary = 0;
265  p.x = 3.0;
266  p.y = 3.0;
267  result = rect_tree_contains_point(tree, &p, &boundary);
268  CU_ASSERT_EQUAL(boundary, 1);
269 
270  /* on tooth convex */
271  boundary = 0;
272  p.x = 2.0;
273  p.y = 0.0;
274  result = rect_tree_contains_point(tree, &p, &boundary);
275  CU_ASSERT_EQUAL(boundary, 1);
276 
277  rect_tree_free(tree);
278  lwpoly_free(poly);
279 
280  /* ziggy zaggy vertical saw tooth polygon */
281  poly = (LWPOLY*)lwgeom_from_wkt("POLYGON((0 0, 3 1, 0 2, 3 3, 0 4, 3 5, 0 6, 5 6, 5 0, 0 0))", LW_PARSER_CHECK_NONE);
282  tree = rect_tree_new(poly->rings[0]);
283 
284  /* not in, left side */
285  boundary = 0;
286  p.x = -0.5;
287  p.y = 3.5;
288  result = rect_tree_contains_point(tree, &p, &boundary);
289  CU_ASSERT_EQUAL(result, 0);
290 
291  /* not in, right side */
292  boundary = 0;
293  p.x = 6.0;
294  p.y = 2.2;
295  result = rect_tree_contains_point(tree, &p, &boundary);
296  CU_ASSERT_EQUAL(result, 0);
297 
298  /* inside */
299  boundary = 0;
300  p.x = 3.0;
301  p.y = 2.0;
302  result = rect_tree_contains_point(tree, &p, &boundary);
303  CU_ASSERT_NOT_EQUAL(result, 0);
304 
305  /* on bottom border */
306  boundary = 0;
307  p.x = 1.0;
308  p.y = 0.0;
309  result = rect_tree_contains_point(tree, &p, &boundary);
310  CU_ASSERT_EQUAL(boundary, 1);
311 
312  /* on top border */
313  boundary = 0;
314  p.x = 3.0;
315  p.y = 6.0;
316  result = rect_tree_contains_point(tree, &p, &boundary);
317  CU_ASSERT_EQUAL(boundary, 1);
318 
319  /* on tooth concave */
320  boundary = 0;
321  p.x = 3.0;
322  p.y = 1.0;
323  result = rect_tree_contains_point(tree, &p, &boundary);
324  CU_ASSERT_EQUAL(boundary, 1);
325 
326  /* on tooth convex */
327  boundary = 0;
328  p.x = 0.0;
329  p.y = 2.0;
330  result = rect_tree_contains_point(tree, &p, &boundary);
331  CU_ASSERT_EQUAL(boundary, 1);
332 
333  /* on tooth convex */
334  boundary = 0;
335  p.x = 0.0;
336  p.y = 6.0;
337  result = rect_tree_contains_point(tree, &p, &boundary);
338  CU_ASSERT_EQUAL(boundary, 1);
339 
340  rect_tree_free(tree);
341  lwpoly_free(poly);
342 
343 }
Datum boundary(PG_FUNCTION_ARGS)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
char ** result
Definition: liblwgeom.h:218
RECT_NODE * rect_tree_new(const POINTARRAY *pa)
Build a tree of nodes from a point array, one node per edge, and each with an associated measure rang...
Definition: lwtree.c:151
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
double x
Definition: liblwgeom.h:284
int rect_tree_contains_point(const RECT_NODE *node, const POINT2D *pt, int *on_boundary)
Definition: lwtree.c:34
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:79
POINTARRAY ** rings
Definition: liblwgeom.h:413
double y
Definition: liblwgeom.h:284
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
Definition: lwtree.h:4
void rect_tree_free(RECT_NODE *node)
Recurse from top of node tree and free all children.
Definition: lwtree.c:18

Here is the call graph for this function:

Here is the caller graph for this function: