PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_rect_tree_contains_point()

static void test_rect_tree_contains_point ( void  )
static

Definition at line 242 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(), LWPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

243 {
244  LWPOLY *poly;
245  POINT2D p;
246  RECT_NODE* tree;
247  int result;
248  int boundary = 0;
249 
250  /* square */
251  poly = (LWPOLY*)lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
252  tree = rect_tree_new(poly->rings[0]);
253 
254  /* inside square */
255  boundary = 0;
256  p.x = 0.5;
257  p.y = 0.5;
258  result = rect_tree_contains_point(tree, &p, &boundary);
259  CU_ASSERT_NOT_EQUAL(result, 0);
260 
261  /* outside square */
262  boundary = 0;
263  p.x = 1.5;
264  p.y = 0.5;
265  result = rect_tree_contains_point(tree, &p, &boundary);
266  CU_ASSERT_EQUAL(result, 0);
267 
268  rect_tree_free(tree);
269  lwpoly_free(poly);
270 
271  /* ziggy zaggy horizontal saw tooth polygon */
272  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);
273  tree = rect_tree_new(poly->rings[0]);
274 
275  /* not in, left side */
276  boundary = 0;
277  p.x = -0.5;
278  p.y = 0.5;
279  result = rect_tree_contains_point(tree, &p, &boundary);
280  CU_ASSERT_EQUAL(result, 0);
281 
282  /* not in, right side */
283  boundary = 0;
284  p.x = 3.0;
285  p.y = 1.0;
286  result = rect_tree_contains_point(tree, &p, &boundary);
287  CU_ASSERT_EQUAL(result, 0);
288 
289  /* inside */
290  boundary = 0;
291  p.x = 2.0;
292  p.y = 1.0;
293  result = rect_tree_contains_point(tree, &p, &boundary);
294  CU_ASSERT_NOT_EQUAL(result, 0);
295 
296  /* on left border */
297  boundary = 0;
298  p.x = 0.0;
299  p.y = 1.0;
300  result = rect_tree_contains_point(tree, &p, &boundary);
301  CU_ASSERT_EQUAL(boundary, 1);
302 
303  /* on right border */
304  boundary = 0;
305  p.x = 4.0;
306  p.y = 0.0;
307  result = rect_tree_contains_point(tree, &p, &boundary);
308  CU_ASSERT_EQUAL(boundary, 1);
309 
310  /* on tooth concave */
311  boundary = 0;
312  p.x = 3.0;
313  p.y = 3.0;
314  result = rect_tree_contains_point(tree, &p, &boundary);
315  CU_ASSERT_EQUAL(boundary, 1);
316 
317  /* on tooth convex */
318  boundary = 0;
319  p.x = 2.0;
320  p.y = 0.0;
321  result = rect_tree_contains_point(tree, &p, &boundary);
322  CU_ASSERT_EQUAL(boundary, 1);
323 
324  rect_tree_free(tree);
325  lwpoly_free(poly);
326 
327  /* ziggy zaggy vertical saw tooth polygon */
328  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);
329  tree = rect_tree_new(poly->rings[0]);
330 
331  /* not in, left side */
332  boundary = 0;
333  p.x = -0.5;
334  p.y = 3.5;
335  result = rect_tree_contains_point(tree, &p, &boundary);
336  CU_ASSERT_EQUAL(result, 0);
337 
338  /* not in, right side */
339  boundary = 0;
340  p.x = 6.0;
341  p.y = 2.2;
342  result = rect_tree_contains_point(tree, &p, &boundary);
343  CU_ASSERT_EQUAL(result, 0);
344 
345  /* inside */
346  boundary = 0;
347  p.x = 3.0;
348  p.y = 2.0;
349  result = rect_tree_contains_point(tree, &p, &boundary);
350  CU_ASSERT_NOT_EQUAL(result, 0);
351 
352  /* on bottom border */
353  boundary = 0;
354  p.x = 1.0;
355  p.y = 0.0;
356  result = rect_tree_contains_point(tree, &p, &boundary);
357  CU_ASSERT_EQUAL(boundary, 1);
358 
359  /* on top border */
360  boundary = 0;
361  p.x = 3.0;
362  p.y = 6.0;
363  result = rect_tree_contains_point(tree, &p, &boundary);
364  CU_ASSERT_EQUAL(boundary, 1);
365 
366  /* on tooth concave */
367  boundary = 0;
368  p.x = 3.0;
369  p.y = 1.0;
370  result = rect_tree_contains_point(tree, &p, &boundary);
371  CU_ASSERT_EQUAL(boundary, 1);
372 
373  /* on tooth convex */
374  boundary = 0;
375  p.x = 0.0;
376  p.y = 2.0;
377  result = rect_tree_contains_point(tree, &p, &boundary);
378  CU_ASSERT_EQUAL(boundary, 1);
379 
380  /* on tooth convex */
381  boundary = 0;
382  p.x = 0.0;
383  p.y = 6.0;
384  result = rect_tree_contains_point(tree, &p, &boundary);
385  CU_ASSERT_EQUAL(boundary, 1);
386 
387  rect_tree_free(tree);
388  lwpoly_free(poly);
389 
390 }
Datum boundary(PG_FUNCTION_ARGS)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
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:175
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
double x
Definition: liblwgeom.h:328
int rect_tree_contains_point(const RECT_NODE *node, const POINT2D *pt, int *on_boundary)
Definition: lwtree.c:58
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:174
POINTARRAY ** rings
Definition: liblwgeom.h:457
double y
Definition: liblwgeom.h:328
void rect_tree_free(RECT_NODE *node)
Recurse from top of node tree and free all children.
Definition: lwtree.c:42
Here is the call graph for this function:
Here is the caller graph for this function: