From: Paul Ramsey Date: Mon, 18 Jun 2012 23:59:37 +0000 (+0000) Subject: Fix mistake in handling crossings-at-a-vertex X-Git-Tag: 2.1.0beta2~880 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5e299620f544f45106d602faffe8954611a90bb;p=postgis Fix mistake in handling crossings-at-a-vertex git-svn-id: http://svn.osgeo.org/postgis/trunk@9948 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_tree.c b/liblwgeom/cunit/cu_tree.c index 59f234a93..582977705 100644 --- a/liblwgeom/cunit/cu_tree.c +++ b/liblwgeom/cunit/cu_tree.c @@ -101,8 +101,33 @@ static void test_tree_circ_pip(void) /* Clean and do new shape */ circ_tree_free(c); lwline_free(g); + +} + +static void test_tree_circ_pip2(void) +{ + LWGEOM* g; + LWPOLY* p; + int rv_classic, rv_tree, on_boundary; + POINT2D pt, pt_outside; + GBOX gbox; + CIRC_NODE *c; + + g = lwgeom_from_wkt("POLYGON((0 0,0 1,1 1,1 0,0 0))", LW_PARSER_CHECK_NONE); + p = lwgeom_as_lwpoly(g); + + pt.x = 0.2; + pt.y = 0.1; + lwgeom_calculate_gbox_geodetic(g, &gbox); + gbox_pt_outside(&gbox, &pt_outside); + c = circ_tree_new(p->rings[0]); + circ_tree_print(c, 0); + rv_classic = lwpoly_covers_point2d(p, &pt); + rv_tree = circ_tree_contains_point(c, &pt, &pt_outside, &on_boundary); + CU_ASSERT_EQUAL(rv_tree, rv_classic); } + static void test_tree_circ_distance(void) { LWLINE *line; @@ -174,6 +199,7 @@ CU_TestInfo tree_tests[] = { PG_TEST(test_tree_circ_create), PG_TEST(test_tree_circ_pip), + PG_TEST(test_tree_circ_pip2), PG_TEST(test_tree_circ_distance), CU_TEST_INFO_NULL }; diff --git a/liblwgeom/lwgeodetic_tree.c b/liblwgeom/lwgeodetic_tree.c index a2ba12c31..6354d748c 100644 --- a/liblwgeom/lwgeodetic_tree.c +++ b/liblwgeom/lwgeodetic_tree.c @@ -313,26 +313,26 @@ int circ_tree_contains_point(const CIRC_NODE* node, const POINT2D* pt, const POI */ // circ_tree_print(node, 0); d = edge_distance_to_point(&stab_edge, &(node->center), &closest); - LWDEBUGF(4, "edge_distance_to_point %g", d); + LWDEBUGF(4, "edge_distance_to_point=%g, node_radius=%g", d, node->radius); if ( FP_LTEQ(d, node->radius) ) { - LWDEBUG(3,"entering this branch"); + LWDEBUGF(3,"entering this branch (%p)", node); /* Return the crossing number of this leaf */ if ( circ_node_is_leaf(node) ) { - LWDEBUG(4, "leaf node calculation"); + LWDEBUGF(4, "leaf node calculation (edge %d)", node->edge_num); geographic_point_init(node->p1->x, node->p1->y, &(edge.start)); geographic_point_init(node->p2->x, node->p2->y, &(edge.end)); if ( edge_intersection(&stab_edge, &edge, &crossing) ) { - LWDEBUG(4,"got stab line edge_intersection!"); + LWDEBUG(4," got stab line edge_intersection with this edge!"); /* To avoid double counting crossings-at-a-vertex, */ /* always ignore crossings at "lower" ends of edges*/ - if ( (FP_EQUALS(crossing.lat, edge.start.lat) && (edge.start.lat <= edge.end.lat)) || - (FP_EQUALS(crossing.lat, edge.end.lat) && (edge.end.lat <= edge.start.lat)) ) + if ( (FP_EQUALS(crossing.lon, edge.start.lon) && FP_EQUALS(crossing.lat, edge.start.lat) && (edge.start.lat <= edge.end.lat)) || + (FP_EQUALS(crossing.lon, edge.end.lon) && FP_EQUALS(crossing.lat, edge.end.lat) && (edge.end.lat <= edge.start.lat)) ) { - LWDEBUG(4," rejecting stab line on 'lower' vertex"); + LWDEBUG(4," rejecting stab line intersection on 'lower' end point vertex"); return 0; } else @@ -348,7 +348,8 @@ int circ_tree_contains_point(const CIRC_NODE* node, const POINT2D* pt, const POI c = 0; for ( i = 0; i < node->num_nodes; i++ ) { - LWDEBUGF(3,"calling circ_tree_contains_point on child %d!", i); + LWDEBUG(3,"internal node calculation"); + LWDEBUGF(3," calling circ_tree_contains_point on child %d!", i); c += circ_tree_contains_point(node->nodes[i], pt, pt_outside, on_boundary); } return c; @@ -356,7 +357,7 @@ int circ_tree_contains_point(const CIRC_NODE* node, const POINT2D* pt, const POI } else { - LWDEBUG(3,"skipping this branch"); + LWDEBUGF(3,"skipping this branch (%p)", node); } return 0;