From: Paul Ramsey Date: Wed, 30 Sep 2009 23:03:29 +0000 (+0000) Subject: Add edge-edge distance tests. X-Git-Tag: 1.5.0b1~442 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5615bafed60a9f1c821a9f00058d4b180ee370b;p=postgis Add edge-edge distance tests. git-svn-id: http://svn.osgeo.org/postgis/trunk@4568 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_geodetic.c b/liblwgeom/cunit/cu_geodetic.c index f9b160815..56ed0f799 100644 --- a/liblwgeom/cunit/cu_geodetic.c +++ b/liblwgeom/cunit/cu_geodetic.c @@ -33,7 +33,8 @@ CU_pSuite register_geodetic_suite(void) (NULL == CU_add_test(pSuite, "test_gserialized_get_gbox_geocentric()", test_gserialized_get_gbox_geocentric)) || (NULL == CU_add_test(pSuite, "test_clairaut()", test_clairaut)) || (NULL == CU_add_test(pSuite, "test_edge_intersection()", test_edge_intersection)) || - (NULL == CU_add_test(pSuite, "test_edge_distance_to_point()", test_edge_distance_to_point)) + (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)) ) { CU_cleanup_registry(); @@ -386,5 +387,29 @@ void test_edge_distance_to_point(void) } +void test_edge_distance_to_edge(void) +{ + GEOGRAPHIC_EDGE e1, e2; + GEOGRAPHIC_POINT c1, c2; + double d; + + /* closest point at origin, one degree away */ + edge_set(-50.0, 0.0, 50.0, 0.0, &e1); + edge_set(-5.0, 20.0, 0.0, 1.0, &e2); + d = edge_distance_to_edge(e1, e2, &c1, &c2); +#if 0 + printf("LINESTRING(%.8g %.8g, %.8g %.8g)\n", e1.start.lon, e1.start.lat, e1.end.lon, e1.end.lat); + printf("LINESTRING(%.8g %.8g, %.8g %.8g)\n", e2.start.lon, e2.start.lat, e2.end.lon, e2.end.lat); + printf("\nDISTANCE == %.8g\n", d); +#endif + CU_ASSERT_DOUBLE_EQUAL(d, M_PI / 180.0, 0.00001); + CU_ASSERT_DOUBLE_EQUAL(c1.lat, 0.0, 0.00001); + CU_ASSERT_DOUBLE_EQUAL(c2.lat, M_PI / 180.0, 0.00001); + CU_ASSERT_DOUBLE_EQUAL(c1.lon, 0.0, 0.00001); + CU_ASSERT_DOUBLE_EQUAL(c2.lon, 0.0, 0.00001); +} + + + diff --git a/liblwgeom/cunit/cu_geodetic.h b/liblwgeom/cunit/cu_geodetic.h index 1caaf1535..b3c6738ca 100644 --- a/liblwgeom/cunit/cu_geodetic.h +++ b/liblwgeom/cunit/cu_geodetic.h @@ -30,4 +30,5 @@ void test_gserialized_get_gbox_geocentric(void); void test_clairaut(void); void test_gbox_calculation(void); void test_edge_intersection(void); -void test_edge_distance_to_point(void); \ No newline at end of file +void test_edge_distance_to_point(void); +void test_edge_distance_to_edge(void);