PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_rect_tree_contains_point()

static void test_rect_tree_contains_point ( void  )
static

Definition at line 255 of file cu_measures.c.

256 {
257  LWGEOM *poly;
258  RECT_NODE* tree;
259 
260  /**********************************************************************
261  * curvepolygon
262  */
263  poly = lwgeom_from_wkt("CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0,1 5,0 10),(0 10,10 10,10 0, 0 0)),COMPOUNDCURVE(CIRCULARSTRING(3 7,5 8,7 7),(7 7,7 3,3 3, 3 7)))", LW_PARSER_CHECK_NONE);
264  tree = rect_tree_from_lwgeom(poly);
265  // char *wkt = rect_tree_to_wkt(tree);
266  // printf("%s\n", wkt);
267  // lwfree(wkt);
268  // return;
269 
270  /* in hole, within arc stroke */
271  CU_ASSERT_EQUAL(tree_pt(tree, 5, 7.5), 0);
272  /* inside */
273  CU_ASSERT_EQUAL(tree_pt(tree, 8, 9), 1);
274  /* outside */
275  CU_ASSERT_EQUAL(tree_pt(tree, -1, 5), 0);
276  /* outside */
277  CU_ASSERT_EQUAL(tree_pt(tree, -1, 7.5), 0);
278  /* outside, within arc stroke */
279  CU_ASSERT_EQUAL(tree_pt(tree, 0.2, 7.5), 0);
280  /* inside, within arc stroke */
281  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 0.5), 1);
282  /* inside, crossing arc stroke */
283  CU_ASSERT_EQUAL(tree_pt(tree, 2, 7.5), 1);
284  /* touching hole corner */
285  CU_ASSERT_EQUAL(tree_pt(tree, 7, 7), 1);
286 
287  rect_tree_free(tree);
288  lwgeom_free(poly);
289 
290 
291  /**********************************************************************
292  * polygon with hole and concavities
293  */
294  poly = lwgeom_from_wkt("POLYGON((0 0,0 10,10 10,10 0,9 0,9 9,8 6,8 0,2 0,2 9,1 6,1 0,0 0),(4 4,4 6,6 6,6 4,4 4))", LW_PARSER_CHECK_NONE);
295  tree = rect_tree_from_lwgeom(poly);
296 
297  /* inside, many grazings */
298  CU_ASSERT_EQUAL(tree_pt(tree, 3, 6), 1);
299  /* inside */
300  CU_ASSERT_EQUAL(tree_pt(tree, 3, 5.5), 1);
301  /* outside */
302  CU_ASSERT_EQUAL(tree_pt(tree, -3, 5.5), 0);
303  /* touching interior ring */
304  CU_ASSERT_EQUAL(tree_pt(tree, 4, 4), 1);
305  CU_ASSERT_EQUAL(tree_pt(tree, 6, 6), 1);
306  /* touching interior ring */
307  CU_ASSERT_EQUAL(tree_pt(tree, 4.5, 4), 1);
308  /* touching exterior ring */
309  CU_ASSERT_EQUAL(tree_pt(tree, 8, 0), 1);
310  CU_ASSERT_EQUAL(tree_pt(tree, 9, 0), 1);
311  CU_ASSERT_EQUAL(tree_pt(tree, 10, 1), 1);
312  CU_ASSERT_EQUAL(tree_pt(tree, 9.5, 1), 1);
313  CU_ASSERT_EQUAL(tree_pt(tree, 0, 10), 1);
314  /* touching grazing spike */
315  CU_ASSERT_EQUAL(tree_pt(tree, 1, 6), 1);
316  /* outide, many grazings */
317  CU_ASSERT_EQUAL(tree_pt(tree, -1, 6), 0);
318  /* within hole */
319  CU_ASSERT_EQUAL(tree_pt(tree, 5, 5), 0);
320  /* within */
321  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 4), 1);
322  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 6), 1);
323  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 9), 1);
324 
325  rect_tree_free(tree);
326  lwgeom_free(poly);
327 
328  /**********************************************************************
329  * square
330  */
331  poly = lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
332  tree = rect_tree_from_lwgeom(poly);
333 
334  /* inside square */
335  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 0.5), 1);
336  /* outside square */
337  CU_ASSERT_EQUAL(tree_pt(tree, 1.5, 0.5), 0);
338  /* outside square grazing some edges */
339  CU_ASSERT_EQUAL(tree_pt(tree, -1, 1), 0);
340  /* inside square on corner */
341  CU_ASSERT_EQUAL(tree_pt(tree, 1, 1), 1);
342  /* inside square on top edge */
343  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 1), 1);
344  /* inside square on side edge */
345  CU_ASSERT_EQUAL(tree_pt(tree, 1, 0.5), 1);
346 
347  rect_tree_free(tree);
348  lwgeom_free(poly);
349 
350  /* ziggy zaggy horizontal saw tooth polygon */
351  poly = lwgeom_from_wkt("POLYGON((0 0, 1 3, 2 0, 3 3, 4 0, 4 5, 0 5, 0 0))", LW_PARSER_CHECK_NONE);
352  tree = rect_tree_from_lwgeom(poly);
353 
354  /* not in, left side */
355  CU_ASSERT_EQUAL(tree_pt(tree, -0.5, 0.5), 0);
356  /* not in, right side */
357  CU_ASSERT_EQUAL(tree_pt(tree, 3, 1), 0);
358  /* inside */
359  CU_ASSERT_EQUAL(tree_pt(tree, 2, 1), 1);
360  /* on left border */
361  CU_ASSERT_EQUAL(tree_pt(tree, 0, 1), 1);
362  /* on left border, grazing */
363  CU_ASSERT_EQUAL(tree_pt(tree, 0, 3), 1);
364  /* on right border */
365  CU_ASSERT_EQUAL(tree_pt(tree, 4, 0), 1);
366  /* on tooth concave */
367  CU_ASSERT_EQUAL(tree_pt(tree, 3, 3), 1);
368  /* on tooth convex */
369  CU_ASSERT_EQUAL(tree_pt(tree, 2, 0), 1);
370 
371  rect_tree_free(tree);
372  lwgeom_free(poly);
373 
374  /**********************************************************************
375  * ziggy zaggy vertical saw tooth polygon
376  */
377  poly = 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);
378  tree = rect_tree_from_lwgeom(poly);
379 
380  /* not in, left side */
381  CU_ASSERT_EQUAL(tree_pt(tree, -0.5, 3.5), 0);
382  /* not in, right side */
383  CU_ASSERT_EQUAL(tree_pt(tree, 6.0, 2.2), 0);
384  /* inside */
385  CU_ASSERT_EQUAL(tree_pt(tree, 3, 2), 1);
386  /* on bottom border */
387  CU_ASSERT_EQUAL(tree_pt(tree, 1, 0), 1);
388  /* on top border */
389  CU_ASSERT_EQUAL(tree_pt(tree, 3, 6), 1);
390  /* on tooth concave */
391  CU_ASSERT_EQUAL(tree_pt(tree, 3, 1), 1);
392  /* on tooth convex */
393  CU_ASSERT_EQUAL(tree_pt(tree, 0, 2), 1);
394  /* on tooth convex */
395  CU_ASSERT_EQUAL(tree_pt(tree, 0, 6), 1);
396 
397  rect_tree_free(tree);
398  lwgeom_free(poly);
399 
400 }
static int tree_pt(RECT_NODE *tree, double x, double y)
Definition: cu_measures.c:248
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
RECT_NODE * rect_tree_from_lwgeom(const LWGEOM *lwgeom)
Create a tree index on top an LWGEOM.
Definition: lwtree.c:861
void rect_tree_free(RECT_NODE *node)
Recurse from top of node tree and free all children.
Definition: lwtree.c:69

References LW_PARSER_CHECK_NONE, lwgeom_free(), lwgeom_from_wkt(), rect_tree_free(), rect_tree_from_lwgeom(), and tree_pt().

Referenced by measures_suite_setup().

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