]> granicus.if.org Git - postgis/commitdiff
Fix for point-on-vertex case of st_covers (#271)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 7 Nov 2009 00:12:56 +0000 (00:12 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 7 Nov 2009 00:12:56 +0000 (00:12 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4761 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_geodetic.c
liblwgeom/cunit/cu_geodetic.h
liblwgeom/lwgeodetic.c

index b61e4a6baf7434bf11eed300d1dbb0e0c3ffe31f..6cecdff1c97986a1c505022fd46508c99380f764 100644 (file)
@@ -36,7 +36,8 @@ CU_pSuite register_geodetic_suite(void)
            (NULL == CU_add_test(pSuite, "test_edge_distance_to_point()", test_edge_distance_to_point)) ||
            (NULL == CU_add_test(pSuite, "test_edge_distance_to_edge()", test_edge_distance_to_edge)) || 
            (NULL == CU_add_test(pSuite, "test_lwgeom_distance_sphere()", test_lwgeom_distance_sphere)) ||
-           (NULL == CU_add_test(pSuite, "test_ptarray_point_in_ring()", test_ptarray_point_in_ring)) ||
+           (NULL == CU_add_test(pSuite, "test_ptarray_point_in_ring()", test_ptarray_point_in_ring)) || 
+           (NULL == CU_add_test(pSuite, "test_lwpoly_covers_point2d()", test_lwpoly_covers_point2d)) ||
            (NULL == CU_add_test(pSuite, "test_spheroid_distance()", test_spheroid_distance)) || 
            (NULL == CU_add_test(pSuite, "test_spheroid_area()", test_spheroid_area)) 
        )
@@ -266,6 +267,12 @@ void test_edge_intersection(void)
        GEOGRAPHIC_POINT g;
        int rv;
 
+       /* Covers case, end-to-end intersection */
+       edge_set(50, -10.999999999999998224, -10.0, 50.0, &e1);
+       edge_set(-10.0, 50.0, -10.272779983831613393, -16.937003313332997578, &e2);
+       rv = edge_intersection(e1, e2, &g);
+       CU_ASSERT_EQUAL(rv, LW_TRUE);   
+               
        /* Medford case, very short segment vs very long one */
        e1.start.lat = 0.74123572595649878103;
        e1.start.lon = -2.1496353191142714145;
@@ -488,6 +495,26 @@ void test_ptarray_point_in_ring(void)
        
 }
 
+void test_lwpoly_covers_point2d(void)
+{
+       LWPOLY *poly;
+       LWGEOM *lwg;
+       POINT2D pt_to_test;
+       GBOX gbox;
+       int result;
+
+       gbox.flags = gflags(0, 0, 1);
+               
+       lwg = lwgeom_from_ewkt("POLYGON((-9 50,51 -11,-10 50,-9 50))", PARSER_CHECK_NONE);
+       lwgeom_calculate_gbox_geodetic(lwg, &gbox);
+       poly = (LWPOLY*)lwg;
+       pt_to_test.x = -10.0;
+       pt_to_test.y = 50.0;
+       result = lwpoly_covers_point2d(poly, gbox, pt_to_test);
+       CU_ASSERT_EQUAL(result, LW_TRUE);
+       lwgeom_free(lwg);
+       
+}
 
 
 void test_lwgeom_distance_sphere(void)
index 594fda1c17edd807e5bf3c1ebf917c18eb90cf0a..25f6983f83acee239bdd61c6a188de4e944bf21e 100644 (file)
@@ -37,3 +37,4 @@ void test_lwgeom_distance_sphere(void);
 void test_ptarray_point_in_ring(void);
 void test_spheroid_distance(void);
 void test_spheroid_area(void);
+void test_lwpoly_covers_point2d(void);
index eee0d8c1dc2ec61977bc1bbf58274838a38f5ffc..cafb3a1b6028ff5777947099a62b68fee2717d35 100644 (file)
@@ -752,6 +752,27 @@ int edge_intersection(GEOGRAPHIC_EDGE e1, GEOGRAPHIC_EDGE e2, GEOGRAPHIC_POINT *
        LWDEBUGF(4, "e1 start(%.20g %.20g) end(%.20g %.20g)", rad2deg(e1.start.lon), rad2deg(e1.start.lat), rad2deg(e1.end.lon), rad2deg(e1.end.lat));
        LWDEBUGF(4, "e2 start(%.20g %.20g) end(%.20g %.20g)", rad2deg(e2.start.lon), rad2deg(e2.start.lat), rad2deg(e2.end.lon), rad2deg(e2.end.lat));
 
+       if( geographic_point_equals(e1.start, e2.start) )
+       {
+               *g = e1.start;
+               return LW_TRUE;
+       }
+       if( geographic_point_equals(e1.end, e2.end) )
+       {
+               *g = e1.end;
+               return LW_TRUE;
+       }
+       if( geographic_point_equals(e1.end, e2.start) )
+       {
+               *g = e1.end;
+               return LW_TRUE;
+       }
+       if( geographic_point_equals(e1.start, e2.end) )
+       {
+               *g = e1.start;
+               return LW_TRUE;
+       }
+       
        robust_cross_product(e1.start, e1.end, &ea);
        normalize(&ea);
        robust_cross_product(e2.start, e2.end, &eb);