PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_rect_tree_contains_point()

static void test_rect_tree_contains_point ( void  )
static

Definition at line 203 of file cu_measures.c.

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().

204 {
205  LWGEOM *poly;
206  RECT_NODE* tree;
207 
208  /**********************************************************************
209  * curvepolygon
210  */
211  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);
212  tree = rect_tree_from_lwgeom(poly);
213  // char *wkt = rect_tree_to_wkt(tree);
214  // printf("%s\n", wkt);
215  // lwfree(wkt);
216  // return;
217 
218  /* in hole, within arc stroke */
219  CU_ASSERT_EQUAL(tree_pt(tree, 5, 7.5), 0);
220  /* inside */
221  CU_ASSERT_EQUAL(tree_pt(tree, 8, 9), 1);
222  /* outside */
223  CU_ASSERT_EQUAL(tree_pt(tree, -1, 5), 0);
224  /* outside */
225  CU_ASSERT_EQUAL(tree_pt(tree, -1, 7.5), 0);
226  /* outside, within arc stroke */
227  CU_ASSERT_EQUAL(tree_pt(tree, 0.2, 7.5), 0);
228  /* inside, within arc stroke */
229  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 0.5), 1);
230  /* inside, crossing arc stroke */
231  CU_ASSERT_EQUAL(tree_pt(tree, 2, 7.5), 1);
232  /* touching hole corner */
233  CU_ASSERT_EQUAL(tree_pt(tree, 7, 7), 1);
234 
235  rect_tree_free(tree);
236  lwgeom_free(poly);
237 
238 
239  /**********************************************************************
240  * polygon with hole and concavities
241  */
242  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);
243  tree = rect_tree_from_lwgeom(poly);
244 
245  /* inside, many grazings */
246  CU_ASSERT_EQUAL(tree_pt(tree, 3, 6), 1);
247  /* inside */
248  CU_ASSERT_EQUAL(tree_pt(tree, 3, 5.5), 1);
249  /* outside */
250  CU_ASSERT_EQUAL(tree_pt(tree, -3, 5.5), 0);
251  /* touching interior ring */
252  CU_ASSERT_EQUAL(tree_pt(tree, 4, 4), 1);
253  CU_ASSERT_EQUAL(tree_pt(tree, 6, 6), 1);
254  /* touching interior ring */
255  CU_ASSERT_EQUAL(tree_pt(tree, 4.5, 4), 1);
256  /* touching exterior ring */
257  CU_ASSERT_EQUAL(tree_pt(tree, 8, 0), 1);
258  CU_ASSERT_EQUAL(tree_pt(tree, 9, 0), 1);
259  CU_ASSERT_EQUAL(tree_pt(tree, 10, 1), 1);
260  CU_ASSERT_EQUAL(tree_pt(tree, 9.5, 1), 1);
261  CU_ASSERT_EQUAL(tree_pt(tree, 0, 10), 1);
262  /* touching grazing spike */
263  CU_ASSERT_EQUAL(tree_pt(tree, 1, 6), 1);
264  /* outide, many grazings */
265  CU_ASSERT_EQUAL(tree_pt(tree, -1, 6), 0);
266  /* within hole */
267  CU_ASSERT_EQUAL(tree_pt(tree, 5, 5), 0);
268  /* within */
269  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 4), 1);
270  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 6), 1);
271  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 9), 1);
272 
273  rect_tree_free(tree);
274  lwgeom_free(poly);
275 
276  /**********************************************************************
277  * square
278  */
279  poly = lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
280  tree = rect_tree_from_lwgeom(poly);
281 
282  /* inside square */
283  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 0.5), 1);
284  /* outside square */
285  CU_ASSERT_EQUAL(tree_pt(tree, 1.5, 0.5), 0);
286  /* outside square grazing some edges */
287  CU_ASSERT_EQUAL(tree_pt(tree, -1, 1), 0);
288  /* inside square on corner */
289  CU_ASSERT_EQUAL(tree_pt(tree, 1, 1), 1);
290  /* inside square on top edge */
291  CU_ASSERT_EQUAL(tree_pt(tree, 0.5, 1), 1);
292  /* inside square on side edge */
293  CU_ASSERT_EQUAL(tree_pt(tree, 1, 0.5), 1);
294 
295  rect_tree_free(tree);
296  lwgeom_free(poly);
297 
298  /* ziggy zaggy horizontal saw tooth polygon */
299  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);
300  tree = rect_tree_from_lwgeom(poly);
301 
302  /* not in, left side */
303  CU_ASSERT_EQUAL(tree_pt(tree, -0.5, 0.5), 0);
304  /* not in, right side */
305  CU_ASSERT_EQUAL(tree_pt(tree, 3, 1), 0);
306  /* inside */
307  CU_ASSERT_EQUAL(tree_pt(tree, 2, 1), 1);
308  /* on left border */
309  CU_ASSERT_EQUAL(tree_pt(tree, 0, 1), 1);
310  /* on left border, grazing */
311  CU_ASSERT_EQUAL(tree_pt(tree, 0, 3), 1);
312  /* on right border */
313  CU_ASSERT_EQUAL(tree_pt(tree, 4, 0), 1);
314  /* on tooth concave */
315  CU_ASSERT_EQUAL(tree_pt(tree, 3, 3), 1);
316  /* on tooth convex */
317  CU_ASSERT_EQUAL(tree_pt(tree, 2, 0), 1);
318 
319  rect_tree_free(tree);
320  lwgeom_free(poly);
321 
322  /**********************************************************************
323  * ziggy zaggy vertical saw tooth polygon
324  */
325  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);
326  tree = rect_tree_from_lwgeom(poly);
327 
328  /* not in, left side */
329  CU_ASSERT_EQUAL(tree_pt(tree, -0.5, 3.5), 0);
330  /* not in, right side */
331  CU_ASSERT_EQUAL(tree_pt(tree, 6.0, 2.2), 0);
332  /* inside */
333  CU_ASSERT_EQUAL(tree_pt(tree, 3, 2), 1);
334  /* on bottom border */
335  CU_ASSERT_EQUAL(tree_pt(tree, 1, 0), 1);
336  /* on top border */
337  CU_ASSERT_EQUAL(tree_pt(tree, 3, 6), 1);
338  /* on tooth concave */
339  CU_ASSERT_EQUAL(tree_pt(tree, 3, 1), 1);
340  /* on tooth convex */
341  CU_ASSERT_EQUAL(tree_pt(tree, 0, 2), 1);
342  /* on tooth convex */
343  CU_ASSERT_EQUAL(tree_pt(tree, 0, 6), 1);
344 
345  rect_tree_free(tree);
346  lwgeom_free(poly);
347 
348 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2004
static int tree_pt(RECT_NODE *tree, double x, double y)
Definition: cu_measures.c:196
void rect_tree_free(RECT_NODE *node)
Recurse from top of node tree and free all children.
Definition: lwtree.c:69
RECT_NODE * rect_tree_from_lwgeom(const LWGEOM *lwgeom)
Create a tree index on top an LWGEOM.
Definition: lwtree.c:855
Here is the call graph for this function:
Here is the caller graph for this function: