]> granicus.if.org Git - postgis/commitdiff
Fix mistake in handling crossings-at-a-vertex
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 18 Jun 2012 23:59:37 +0000 (23:59 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 18 Jun 2012 23:59:37 +0000 (23:59 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9948 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_tree.c
liblwgeom/lwgeodetic_tree.c

index 59f234a9318c98ffc93d5ffe6ec1f1f7d6f1ec09..582977705c427503b819bea63e8eb5248e76f7a5 100644 (file)
@@ -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
 };
index a2ba12c3145b99692d81807e95a170fb544ea172..6354d748c3df7d254b38224b273a97dd77f55225 100644 (file)
@@ -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;