PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ test_rect_tree_contains_point()

static void test_rect_tree_contains_point ( void  )
static

Definition at line 196 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().

197 {
198  LWPOLY *poly;
199  POINT2D p;
200  RECT_NODE* tree;
201  int result;
202  int boundary = 0;
203 
204  /* square */
205  poly = (LWPOLY*)lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
206  tree = rect_tree_new(poly->rings[0]);
207 
208  /* inside square */
209  boundary = 0;
210  p.x = 0.5;
211  p.y = 0.5;
212  result = rect_tree_contains_point(tree, &p, &boundary);
213  CU_ASSERT_NOT_EQUAL(result, 0);
214 
215  /* outside square */
216  boundary = 0;
217  p.x = 1.5;
218  p.y = 0.5;
219  result = rect_tree_contains_point(tree, &p, &boundary);
220  CU_ASSERT_EQUAL(result, 0);
221 
222  rect_tree_free(tree);
223  lwpoly_free(poly);
224 
225  /* ziggy zaggy horizontal saw tooth polygon */
226  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);
227  tree = rect_tree_new(poly->rings[0]);
228 
229  /* not in, left side */
230  boundary = 0;
231  p.x = -0.5;
232  p.y = 0.5;
233  result = rect_tree_contains_point(tree, &p, &boundary);
234  CU_ASSERT_EQUAL(result, 0);
235 
236  /* not in, right side */
237  boundary = 0;
238  p.x = 3.0;
239  p.y = 1.0;
240  result = rect_tree_contains_point(tree, &p, &boundary);
241  CU_ASSERT_EQUAL(result, 0);
242 
243  /* inside */
244  boundary = 0;
245  p.x = 2.0;
246  p.y = 1.0;
247  result = rect_tree_contains_point(tree, &p, &boundary);
248  CU_ASSERT_NOT_EQUAL(result, 0);
249 
250  /* on left border */
251  boundary = 0;
252  p.x = 0.0;
253  p.y = 1.0;
254  result = rect_tree_contains_point(tree, &p, &boundary);
255  CU_ASSERT_EQUAL(boundary, 1);
256 
257  /* on right border */
258  boundary = 0;
259  p.x = 4.0;
260  p.y = 0.0;
261  result = rect_tree_contains_point(tree, &p, &boundary);
262  CU_ASSERT_EQUAL(boundary, 1);
263 
264  /* on tooth concave */
265  boundary = 0;
266  p.x = 3.0;
267  p.y = 3.0;
268  result = rect_tree_contains_point(tree, &p, &boundary);
269  CU_ASSERT_EQUAL(boundary, 1);
270 
271  /* on tooth convex */
272  boundary = 0;
273  p.x = 2.0;
274  p.y = 0.0;
275  result = rect_tree_contains_point(tree, &p, &boundary);
276  CU_ASSERT_EQUAL(boundary, 1);
277 
278  rect_tree_free(tree);
279  lwpoly_free(poly);
280 
281  /* ziggy zaggy vertical saw tooth polygon */
282  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);
283  tree = rect_tree_new(poly->rings[0]);
284 
285  /* not in, left side */
286  boundary = 0;
287  p.x = -0.5;
288  p.y = 3.5;
289  result = rect_tree_contains_point(tree, &p, &boundary);
290  CU_ASSERT_EQUAL(result, 0);
291 
292  /* not in, right side */
293  boundary = 0;
294  p.x = 6.0;
295  p.y = 2.2;
296  result = rect_tree_contains_point(tree, &p, &boundary);
297  CU_ASSERT_EQUAL(result, 0);
298 
299  /* inside */
300  boundary = 0;
301  p.x = 3.0;
302  p.y = 2.0;
303  result = rect_tree_contains_point(tree, &p, &boundary);
304  CU_ASSERT_NOT_EQUAL(result, 0);
305 
306  /* on bottom border */
307  boundary = 0;
308  p.x = 1.0;
309  p.y = 0.0;
310  result = rect_tree_contains_point(tree, &p, &boundary);
311  CU_ASSERT_EQUAL(boundary, 1);
312 
313  /* on top border */
314  boundary = 0;
315  p.x = 3.0;
316  p.y = 6.0;
317  result = rect_tree_contains_point(tree, &p, &boundary);
318  CU_ASSERT_EQUAL(boundary, 1);
319 
320  /* on tooth concave */
321  boundary = 0;
322  p.x = 3.0;
323  p.y = 1.0;
324  result = rect_tree_contains_point(tree, &p, &boundary);
325  CU_ASSERT_EQUAL(boundary, 1);
326 
327  /* on tooth convex */
328  boundary = 0;
329  p.x = 0.0;
330  p.y = 2.0;
331  result = rect_tree_contains_point(tree, &p, &boundary);
332  CU_ASSERT_EQUAL(boundary, 1);
333 
334  /* on tooth convex */
335  boundary = 0;
336  p.x = 0.0;
337  p.y = 6.0;
338  result = rect_tree_contains_point(tree, &p, &boundary);
339  CU_ASSERT_EQUAL(boundary, 1);
340 
341  rect_tree_free(tree);
342  lwpoly_free(poly);
343 
344 }
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:1985
double x
Definition: liblwgeom.h:327
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:152
POINTARRAY ** rings
Definition: liblwgeom.h:456
double y
Definition: liblwgeom.h:327
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: