diff --git a/doc/src/examples/algorithms/area.cpp b/doc/src/examples/algorithms/area.cpp index 5b5ef9179..e9dfbbf33 100644 --- a/doc/src/examples/algorithms/area.cpp +++ b/doc/src/examples/algorithms/area.cpp @@ -27,8 +27,8 @@ int main() double area = bg::area(poly); std::cout << "Area: " << area << std::endl; - // Calculate the area of a spherical polygon - bg::model::polygon > > sph_poly; + // Calculate the area of a spherical equatorial polygon + bg::model::polygon > > sph_poly; bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly); area = bg::area(sph_poly); std::cout << "Area: " << area << std::endl; diff --git a/doc/src/examples/algorithms/area_with_strategy.cpp b/doc/src/examples/algorithms/area_with_strategy.cpp index d47120889..027889a15 100644 --- a/doc/src/examples/algorithms/area_with_strategy.cpp +++ b/doc/src/examples/algorithms/area_with_strategy.cpp @@ -27,8 +27,8 @@ int main() double area = bg::area(poly); std::cout << "Area: " << area << std::endl; - // Calculate the area of a spherical polygon - bg::model::polygon > > sph_poly; + // Calculate the area of a spherical polygon (for latitude: 0 at equator) + bg::model::polygon > > sph_poly; bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly); area = bg::area(sph_poly); std::cout << "Area: " << area << std::endl; diff --git a/doc/src/examples/algorithms/length_with_strategy.cpp b/doc/src/examples/algorithms/length_with_strategy.cpp index 2c68f3ae8..564d6a846 100644 --- a/doc/src/examples/algorithms/length_with_strategy.cpp +++ b/doc/src/examples/algorithms/length_with_strategy.cpp @@ -17,7 +17,7 @@ int main() { using namespace boost::geometry; - typedef model::point > P; + typedef model::point > P; model::linestring

line; line.push_back(P(2, 41)); line.push_back(P(2, 48)); diff --git a/doc/src/examples/algorithms/transform.cpp b/doc/src/examples/algorithms/transform.cpp index feee4ab13..b2fccaad0 100644 --- a/doc/src/examples/algorithms/transform.cpp +++ b/doc/src/examples/algorithms/transform.cpp @@ -18,7 +18,8 @@ int main() { namespace bg = boost::geometry; - bg::model::point > p1(5.0, 52.0); + // Select a point near the pole (theta=5.0, phi=15.0) + bg::model::point > p1(15.0, 5.0); // Transform from degree to radian. Default strategy is automatically selected, // it will convert from degree to radian @@ -45,9 +46,9 @@ int main() /*` Output: [pre -p1: (5, 52) -p2: (0.0872665, 0.907571) -p3: (0.785012, 0.0686797, 0.615661) +p1: (15, 5) +p2: (0.261799, 0.0872665) +p3: (0.084186, 0.0225576, 0.996195) ] */ //] diff --git a/doc/src/examples/core/degree_radian.cpp b/doc/src/examples/core/degree_radian.cpp index 3cd2d3dba..af27a8652 100644 --- a/doc/src/examples/core/degree_radian.cpp +++ b/doc/src/examples/core/degree_radian.cpp @@ -17,8 +17,8 @@ using namespace boost::geometry; int main() { - typedef model::point > degree_point; - typedef model::point > radian_point; + typedef model::point > degree_point; + typedef model::point > radian_point; degree_point d(4.893, 52.373); radian_point r(0.041, 0.8527); diff --git a/doc/src/examples/quick_start.cpp b/doc/src/examples/quick_start.cpp index ff96b19c7..7f16a7653 100644 --- a/doc/src/examples/quick_start.cpp +++ b/doc/src/examples/quick_start.cpp @@ -135,7 +135,7 @@ int main(void) //[quick_start_spherical typedef boost::geometry::model::point < - double, 2, boost::geometry::cs::spherical + double, 2, boost::geometry::cs::spherical_equatorial > spherical_point; spherical_point amsterdam(4.90, 52.37); diff --git a/example/06_a_transformation_example.cpp b/example/06_a_transformation_example.cpp index 75440f42e..a0f0d2d71 100644 --- a/example/06_a_transformation_example.cpp +++ b/example/06_a_transformation_example.cpp @@ -50,7 +50,7 @@ int main() // - from Cartesian to Spherical coordinate systems and back // - from Cartesian to Cartesian (mapping, affine transformations) and back (inverse) // - Map Projections - // - from Degree to Radian and back in spherical or geographic coordinate systems + // - from Degree to Radian and back in spherical_equatorial or geographic coordinate systems return 0; } diff --git a/example/07_a_graph_route_example.cpp b/example/07_a_graph_route_example.cpp index 929af00a1..8ad672431 100644 --- a/example/07_a_graph_route_example.cpp +++ b/example/07_a_graph_route_example.cpp @@ -267,7 +267,7 @@ int main() // (geographic calculations are in an extension; for sample it makes no difference) typedef boost::geometry::model::point < - double, 2, boost::geometry::cs::spherical + double, 2, boost::geometry::cs::spherical_equatorial > point_type; typedef boost::geometry::model::linestring line_type; diff --git a/example/07_b_graph_route_example.cpp b/example/07_b_graph_route_example.cpp index 17dbea3a6..c28b3c06e 100644 --- a/example/07_b_graph_route_example.cpp +++ b/example/07_b_graph_route_example.cpp @@ -249,11 +249,11 @@ inline void build_route(Graph const& graph, int main() { - // Define a point in the Geographic coordinate system (currently Spherical) + // Define a point in the Geographic coordinate system (currently spherical-equatorial) // (geographic calculations are in an extension; for sample it makes no difference) typedef boost::geometry::model::point < - double, 2, boost::geometry::cs::spherical + double, 2, boost::geometry::cs::spherical_equatorial > point_type; typedef boost::geometry::model::linestring line_type; diff --git a/include/boost/geometry/core/cs.hpp b/include/boost/geometry/core/cs.hpp index 93e0eec77..a53d6e278 100644 --- a/include/boost/geometry/core/cs.hpp +++ b/include/boost/geometry/core/cs.hpp @@ -79,7 +79,7 @@ struct geographic /*! -\brief Spherical coordinate system, in degree or in radian +\brief Spherical (polar) coordinate system, in degree or in radian \details Defines the spherical coordinate system where points are defined in two angles and an optional radius usually known as r, theta, phi @@ -102,6 +102,25 @@ struct spherical typedef DegreeOrRadian units; }; + +/*! +\brief Spherical equatorial coordinate system, in degree or in radian +\details This one resembles the geographic coordinate system, and has latitude + up from zero at the equator, to 90 at the pole + (opposite to the spherical(polar) coordinate system). + Used in astronomy and in GIS (but there is also the geographic) + +\see http://en.wikipedia.org/wiki/Spherical_coordinates +\ingroup cs +*/ +template +struct spherical_equatorial +{ + typedef DegreeOrRadian units; +}; + + + /*! \brief Polar coordinate system \details Defines the polar coordinate system "in which each point @@ -144,9 +163,16 @@ struct cs_tag > template struct cs_tag > { - typedef spherical_tag type; + typedef spherical_polar_tag type; }; +template +struct cs_tag > +{ + typedef spherical_equatorial_tag type; +}; + + template<> struct cs_tag { diff --git a/include/boost/geometry/core/tags.hpp b/include/boost/geometry/core/tags.hpp index 6469b6c11..f110a079a 100644 --- a/include/boost/geometry/core/tags.hpp +++ b/include/boost/geometry/core/tags.hpp @@ -24,11 +24,15 @@ namespace boost { namespace geometry /// Tag indicating Cartesian coordinate system family (cartesian,epsg) struct cartesian_tag {}; +/// Tag indicating Spherical polar coordinate system family +struct spherical_polar_tag {}; + +/// Tag indicating Spherical equatorial coordinate system family +struct spherical_equatorial_tag {}; + /// Tag indicating Geographic coordinate system family (geographic) struct geographic_tag {}; -/// Tag indicating Spherical coordinate system family (spherical,celestial,...) -struct spherical_tag {}; // Tags defining tag hierarchy diff --git a/include/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp b/include/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp index 373014f15..af0251ec6 100644 --- a/include/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp +++ b/include/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp @@ -188,7 +188,13 @@ struct default_strategy -struct default_strategy +struct default_strategy +{ + typedef winding type; +}; + +template +struct default_strategy { typedef winding type; }; diff --git a/include/boost/geometry/strategies/cartesian/side_by_triangle.hpp b/include/boost/geometry/strategies/cartesian/side_by_triangle.hpp index 123689975..bec41cf5c 100644 --- a/include/boost/geometry/strategies/cartesian/side_by_triangle.hpp +++ b/include/boost/geometry/strategies/cartesian/side_by_triangle.hpp @@ -21,6 +21,7 @@ #include +#include namespace boost { namespace geometry diff --git a/include/boost/geometry/strategies/spherical/area_huiller.hpp b/include/boost/geometry/strategies/spherical/area_huiller.hpp index 23fd0cd64..edd861957 100644 --- a/include/boost/geometry/strategies/spherical/area_huiller.hpp +++ b/include/boost/geometry/strategies/spherical/area_huiller.hpp @@ -45,6 +45,8 @@ http://trs-new.jpl.nasa.gov/dspace/bitstream/2014/40409/1/07-03.pdf, is simple and works well in most cases but not in 180 meridian crossing cases. This probably could be solved. +\note This version is made for spherical equatorial coordinate systems + \qbk{ [heading Example] @@ -161,11 +163,20 @@ private : namespace services { - template - struct default_strategy - { - typedef strategy::area::huiller type; - }; + + +template +struct default_strategy +{ + typedef strategy::area::huiller type; +}; + +// Note: spherical polar coordinate system requires "get_as_radian_equatorial" +/***template +struct default_strategy +{ + typedef strategy::area::huiller type; +};***/ } // namespace services diff --git a/include/boost/geometry/strategies/spherical/compare_circular.hpp b/include/boost/geometry/strategies/spherical/compare_circular.hpp index e33147c22..fee1e2b7e 100644 --- a/include/boost/geometry/strategies/spherical/compare_circular.hpp +++ b/include/boost/geometry/strategies/spherical/compare_circular.hpp @@ -117,7 +117,7 @@ template template class CoordinateSystem, typename Units > -struct strategy_compare, 0> +struct strategy_compare, 0> { typedef typename coordinate_type::type coordinate_type; typedef strategy::compare::circular_comparator @@ -134,7 +134,7 @@ template template class CoordinateSystem, typename Units > -struct strategy_compare, 0> +struct strategy_compare, 0> { typedef typename coordinate_type::type coordinate_type; typedef strategy::compare::circular_comparator diff --git a/include/boost/geometry/strategies/spherical/distance_cross_track.hpp b/include/boost/geometry/strategies/spherical/distance_cross_track.hpp index 5c5f3e9a2..f902591bf 100644 --- a/include/boost/geometry/strategies/spherical/distance_cross_track.hpp +++ b/include/boost/geometry/strategies/spherical/distance_cross_track.hpp @@ -219,7 +219,12 @@ struct comparable_type +template +< + typename Point, typename PointOfSegment, + typename CalculationType, + typename Strategy +> struct get_comparable > { typedef typename comparable_type @@ -234,7 +239,12 @@ public : }; -template +template +< + typename Point, typename PointOfSegment, + typename CalculationType, + typename Strategy +> struct result_from_distance > { private : @@ -248,7 +258,12 @@ public : }; -template +template +< + typename Point, typename PointOfSegment, + typename CalculationType, + typename Strategy +> struct strategy_point_point > { typedef Strategy type; @@ -256,9 +271,17 @@ struct strategy_point_point" template -struct default_strategy +struct default_strategy + < + segment_tag, Point, PointOfSegment, + spherical_polar_tag, spherical_polar_tag, + Strategy + > { typedef cross_track < @@ -271,12 +294,40 @@ struct default_strategy::type, Strategy >::type > type; }; +*/ + +template +struct default_strategy + < + segment_tag, Point, PointOfSegment, + spherical_equatorial_tag, spherical_equatorial_tag, + Strategy + > +{ + typedef cross_track + < + Point, + PointOfSegment, + void, + typename boost::mpl::if_ + < + boost::is_void, + typename default_strategy + < + point_tag, Point, PointOfSegment, + spherical_equatorial_tag, spherical_equatorial_tag + >::type, + Strategy + >::type + > type; +}; + } // namespace services diff --git a/include/boost/geometry/strategies/spherical/distance_haversine.hpp b/include/boost/geometry/strategies/spherical/distance_haversine.hpp index 3722de23c..eb9bf553b 100644 --- a/include/boost/geometry/strategies/spherical/distance_haversine.hpp +++ b/include/boost/geometry/strategies/spherical/distance_haversine.hpp @@ -306,13 +306,16 @@ public : }; -// Register it as the default for point-types in a spherical coordinate system +// Register it as the default for point-types +// in a spherical equatorial coordinate system template -struct default_strategy +struct default_strategy { typedef strategy::distance::haversine type; }; +// Note: spherical polar coordinate system requires "get_as_radian_equatorial" + } // namespace services #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS diff --git a/include/boost/geometry/strategies/strategy_transform.hpp b/include/boost/geometry/strategies/strategy_transform.hpp index 35c6a4526..dd6ead146 100644 --- a/include/boost/geometry/strategies/strategy_transform.hpp +++ b/include/boost/geometry/strategies/strategy_transform.hpp @@ -160,6 +160,9 @@ namespace detail assert_dimension(); // http://en.wikipedia.org/wiki/List_of_canonical_coordinate_transformations#From_spherical_coordinates + // http://www.vias.org/comp_geometry/math_coord_convert_3d.htm + // https://moodle.polymtl.ca/file.php/1183/Autres_Documents/Derivation_for_Spherical_Co-ordinates.pdf + // Phi = first, theta is second, r is third, see documentation on cs::spherical // (calculations are splitted to implement ttmath) @@ -230,7 +233,7 @@ namespace detail \tparam P2 second point type */ template -struct from_spherical_2_to_cartesian_3 +struct from_spherical_polar_2_to_cartesian_3 { inline bool apply(P1 const& p1, P2& p2) const { @@ -247,7 +250,7 @@ struct from_spherical_2_to_cartesian_3 \tparam P2 second point type */ template -struct from_spherical_3_to_cartesian_3 +struct from_spherical_polar_3_to_cartesian_3 { inline bool apply(P1 const& p1, P2& p2) const { @@ -267,7 +270,7 @@ struct from_spherical_3_to_cartesian_3 \note If x,y,z point is not lying on unit sphere, transformation will return false */ template -struct from_cartesian_3_to_spherical_2 +struct from_cartesian_3_to_spherical_polar_2 { inline bool apply(P1 const& p1, P2& p2) const { @@ -284,7 +287,7 @@ struct from_cartesian_3_to_spherical_2 \tparam P2 second point type */ template -struct from_cartesian_3_to_spherical_3 +struct from_cartesian_3_to_spherical_polar_3 { inline bool apply(P1 const& p1, P2& p2) const { @@ -343,30 +346,30 @@ struct default_strategy, CoordSys -struct default_strategy +struct default_strategy { - typedef from_spherical_2_to_cartesian_3 type; + typedef from_spherical_polar_2_to_cartesian_3 type; }; /// Specialization to transform from sphere(phi,theta,r) to XYZ template -struct default_strategy +struct default_strategy { - typedef from_spherical_3_to_cartesian_3 type; + typedef from_spherical_polar_3_to_cartesian_3 type; }; /// Specialization to transform from XYZ to unit sphere(phi,theta) template -struct default_strategy +struct default_strategy { - typedef from_cartesian_3_to_spherical_2 type; + typedef from_cartesian_3_to_spherical_polar_2 type; }; /// Specialization to transform from XYZ to sphere(phi,theta,r) template -struct default_strategy +struct default_strategy { - typedef from_cartesian_3_to_spherical_3 type; + typedef from_cartesian_3_to_spherical_polar_3 type; }; diff --git a/test/algorithms/area.cpp b/test/algorithms/area.cpp index 4ed4e7009..b9eaa9d4c 100644 --- a/test/algorithms/area.cpp +++ b/test/algorithms/area.cpp @@ -60,7 +60,7 @@ void test_all() } template -void test_spherical() +void test_spherical(bool polar = false) { bg::model::polygon geometry; @@ -79,6 +79,29 @@ void test_spherical() area = bg::area(geometry, strategy); BOOST_CHECK_CLOSE(area, 2.0 * 2.0 * expected, 0.0001); + + { + bg::model::ring aurha; // a'dam-utr-rott.-den haag-a'dam + bg::read_wkt("POLYGON((4.892 52.373,5.119 52.093,4.479 51.930,4.23 52.08,4.892 52.373))", aurha); + if (polar) + { + // Create colatitudes (measured from pole) + BOOST_FOREACH(Point& p, aurha) + { + bg::set<1>(p, 90.0 - bg::get<1>(p)); + } + bg::correct(aurha); + } + bg::strategy::area::huiller + < + typename bg::point_type::type + > huiller(6372.795); + area = bg::area(aurha, huiller); + BOOST_CHECK_CLOSE(area, 1476.645675, 0.0001); + + // SQL Server gives: 1481.55595960659 + // for select geography::STGeomFromText('POLYGON((4.892 52.373,4.23 52.08,4.479 51.930,5.119 52.093,4.892 52.373))',4326).STArea()/1000000.0 + } } template @@ -116,7 +139,8 @@ int test_main(int, char* []) test_all >(); test_all >(); - test_spherical > >(); + test_spherical > >(); + test_spherical > >(true); test_ccw >(); test_open >(); diff --git a/test/algorithms/simplify.cpp b/test/algorithms/simplify.cpp index 2555a638e..09ca32135 100644 --- a/test/algorithms/simplify.cpp +++ b/test/algorithms/simplify.cpp @@ -96,11 +96,11 @@ int test_main(int, char* []) test_all >(); test_all >(); - test_spherical > >(); + test_spherical > >(); #if defined(HAVE_TTMATH) test_all >(); - test_spherical > >(); + test_spherical > >(); #endif return 0; diff --git a/test/algorithms/test_area.hpp b/test/algorithms/test_area.hpp index 5441bcffc..bf7d7a021 100644 --- a/test/algorithms/test_area.hpp +++ b/test/algorithms/test_area.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include diff --git a/test/geometry_test_common.hpp b/test/geometry_test_common.hpp index 9fbe8b26d..0af0a8340 100644 --- a/test/geometry_test_common.hpp +++ b/test/geometry_test_common.hpp @@ -94,6 +94,29 @@ template <> struct string_from_type #endif + +struct geographic_policy +{ + template + static inline CoordinateType apply(CoordinateType const& value) + { + return value; + } +}; + +struct mathematical_policy +{ + template + static inline CoordinateType apply(CoordinateType const& value) + { + return 90 - value; + } + +}; + + + + // For all tests: // - do NOT use "using namespace boost::geometry" to make clear what is Boost.Geometry // - use bg:: as short alias diff --git a/test/strategies/cross_track.cpp b/test/strategies/cross_track.cpp index f53f6255b..debc5aba8 100644 --- a/test/strategies/cross_track.cpp +++ b/test/strategies/cross_track.cpp @@ -28,9 +28,10 @@ #include +// This test is GIS oriented. -template +template void test_distance( typename bg::coordinate_type::type const& lon1, typename bg::coordinate_type::type const& lat1, @@ -60,9 +61,9 @@ void test_distance( Point p1, p2, p3; - bg::assign_values(p1, lon1, lat1); - bg::assign_values(p2, lon2, lat2); - bg::assign_values(p3, lon3, lat3); + bg::assign_values(p1, lon1, LatitudePolicy::apply(lat1)); + bg::assign_values(p2, lon2, LatitudePolicy::apply(lat2)); + bg::assign_values(p3, lon3, LatitudePolicy::apply(lat3)); strategy_type strategy; @@ -83,29 +84,30 @@ void test_distance( } - -template +template void test_all() { typename bg::coordinate_type::type const average_earth_radius = 6372795.0; // distance (Paris <-> Amsterdam/Barcelona), // with coordinates rounded as below ~87 km - // should be is equal - // to distance (Paris <-> Barcelona/Amsterdam) + // is equal to distance (Paris <-> Barcelona/Amsterdam) typename bg::coordinate_type::type const p_to_ab = 86.798321 * 1000.0; - test_distance(2, 48, 4, 52, 2, 41, average_earth_radius, p_to_ab, 0.1); - test_distance(2, 48, 2, 41, 4, 52, average_earth_radius, p_to_ab, 0.1); + test_distance(2, 48, 4, 52, 2, 41, average_earth_radius, p_to_ab, 0.1); + test_distance(2, 48, 2, 41, 4, 52, average_earth_radius, p_to_ab, 0.1); } int test_main(int, char* []) { - test_all > >(); + test_all >, geographic_policy >(); + + // NYI: haversine for mathematical spherical coordinate systems + // test_all >, mathematical_policya >(); #if defined(HAVE_TTMATH) typedef ttmath::Big<1,4> tt; - //test_all > >(); + //test_all >, geographic_policy>(); #endif return 0; diff --git a/test/strategies/haversine.cpp b/test/strategies/haversine.cpp index 3ad545878..8ac8ca3a4 100644 --- a/test/strategies/haversine.cpp +++ b/test/strategies/haversine.cpp @@ -34,7 +34,7 @@ double const average_earth_radius = 6372795.0; -template +template struct test_distance { typedef bg::strategy::distance::haversine @@ -60,15 +60,15 @@ struct test_distance haversine_type strategy(radius); Point p1, p2; - bg::assign_values(p1, lon1, lat1); - bg::assign_values(p2, lon2, lat2); + bg::assign_values(p1, lon1, LatitudePolicy::apply(lat1)); + bg::assign_values(p2, lon2, LatitudePolicy::apply(lat2)); return_type d = strategy.apply(p1, p2); BOOST_CHECK_CLOSE(d, expected, tolerance); } }; -template +template void test_all() { // earth to unit-sphere -> divide by earth circumference, then it is from 0-1, @@ -77,19 +77,19 @@ void test_all() // ~ Amsterdam/Paris, 467 kilometers double const a_p = 467.2704 * 1000.0; - test_distance::test(4, 52, 2, 48, average_earth_radius, a_p, 1.0); - test_distance::test(2, 48, 4, 52, average_earth_radius, a_p, 1.0); - test_distance::test(4, 52, 2, 48, 1.0, a_p * e2u, 0.001); + test_distance::test(4, 52, 2, 48, average_earth_radius, a_p, 1.0); + test_distance::test(2, 48, 4, 52, average_earth_radius, a_p, 1.0); + test_distance::test(4, 52, 2, 48, 1.0, a_p * e2u, 0.001); // ~ Amsterdam/Barcelona double const a_b = 1232.9065 * 1000.0; - test_distance::test(4, 52, 2, 41, average_earth_radius, a_b, 1.0); - test_distance::test(2, 41, 4, 52, average_earth_radius, a_b, 1.0); - test_distance::test(4, 52, 2, 41, 1.0, a_b * e2u, 0.001); + test_distance::test(4, 52, 2, 41, average_earth_radius, a_b, 1.0); + test_distance::test(2, 41, 4, 52, average_earth_radius, a_b, 1.0); + test_distance::test(4, 52, 2, 41, 1.0, a_b * e2u, 0.001); } -template +template void test_services() { namespace bgsd = bg::strategy::distance; @@ -244,9 +244,12 @@ double time_normal(int n) int test_main(int, char* []) { - test_all > >(); - test_all > >(); - test_all > >(); + test_all >, geographic_policy>(); + test_all >, geographic_policy>(); + test_all >, geographic_policy>(); + + // NYI: haversine for mathematical spherical coordinate systems + // test_all >, mathematical_policy>(); //double t1 = time_sqrt(20000); //double t2 = time_normal(20000); @@ -255,15 +258,16 @@ int test_main(int, char* []) #if defined(HAVE_TTMATH) typedef ttmath::Big<1,4> tt; - test_all > >(); + test_all >, geographic_policy>(); #endif test_services < - bg::model::point >, bg::model::point >, - double + bg::model::point >, + double, + geographic_policy >(); return 0; diff --git a/test/strategies/segment_intersection.cpp b/test/strategies/segment_intersection.cpp index d68b6ee5c..5dfe3ed0f 100644 --- a/test/strategies/segment_intersection.cpp +++ b/test/strategies/segment_intersection.cpp @@ -91,7 +91,7 @@ static void test_segment_intersection(int caseno, #endif typedef typename bg::coordinate_type

::type coordinate_type; - typedef segment segment_type; + typedef bg::model::referring_segment segment_type; P p1, p2, p3, p4; bg::assign_values(p1, x1, y1); diff --git a/test/strategies/segment_intersection_collinear.cpp b/test/strategies/segment_intersection_collinear.cpp index 3c02f39ad..ea28f9cc5 100644 --- a/test/strategies/segment_intersection_collinear.cpp +++ b/test/strategies/segment_intersection_collinear.cpp @@ -64,7 +64,7 @@ static void test_segment_intersection(std::string const& case_id, //#endif typedef typename bg::coordinate_type

::type coordinate_type; - typedef bg::segment segment_type; + typedef bg::model::referring_segment segment_type; P p1, p2, p3, p4; bg::assign_values(p1, x1, y1); diff --git a/test/strategies/side_by_cross_track.cpp b/test/strategies/side_by_cross_track.cpp deleted file mode 100644 index e02f3267d..000000000 --- a/test/strategies/side_by_cross_track.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) -// Unit Test - -// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. - -// Use, modification and distribution is subject to the Boost Software License, -// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - - -#include - -#include - -#include - -#include - -#include -#include - - -template -void test_side(double lon1, double lat1, - double lon2, double lat2, - double lon3, double lat3, - int expected) -{ - typedef bg::strategy::side::side_by_cross_track strategy; - - Point p1, p2, p3; - bg::assign_values(p1, lon1, lat1); - bg::assign_values(p2, lon2, lat2); - bg::assign_values(p3, lon3, lat3); - int s = strategy::apply(p1, p2, p3); - -} - -template -void test_all() -{ - test_side(2.0, 48.0, 4.0, 52.0, 2.0, 41.0, 1); - test_side(2.0, 48.0, 2.0, 41.0, 4.0, 52.0, -1); -} - -int test_main(int, char* []) -{ - test_all > >(); - - double a = 0; - double b = sin(a); - - return 0; -} diff --git a/test/strategies/spherical_side.cpp b/test/strategies/spherical_side.cpp new file mode 100644 index 000000000..296953571 --- /dev/null +++ b/test/strategies/spherical_side.cpp @@ -0,0 +1,137 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + + +#include + + +#include + + +#include +#include +#include +#include + +#include + +#include +#include + + +namespace boost { namespace geometry { + +template +static inline Vector create_vector(Point1 const& p1, Point2 const& p2) +{ + Vector v; + convert(p1, v); + subtract_point(v, p2); + return v; +} + +}} + +inline char side_char(int side) +{ + return side == 1 ? 'L' + : side == -1 ? 'R' + : '-' + ; +} + +template +void test_side1(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3, + int expected) +{ + std::cout << case_id << ": "; + //int s = bg::strategy::side::side_via_plane<>::apply(p1, p2, p3); + int side1 = bg::strategy::side::spherical_side_formula<>::apply(p1, p2, p3); + int side2 = bg::strategy::side::side_via_plane<>::apply(p1, p2, p3); + int side3 = bg::strategy::side::side_by_cross_track<>::apply(p1, p2, p3); + + typedef bg::strategy_side::type spherical_strategy; + //int side4 = spherical_strategy::apply(p1, p2, p3); + + typedef bg::strategy_side::type cartesian_strategy; + int side5 = cartesian_strategy::apply(p1, p2, p3); + + + //BOOST_CHECK_EQUAL(side1, expected); + //BOOST_CHECK_EQUAL(side2, expected); + std::cout + << "exp: " << side_char(expected) + << " ssf: " << side_char(side1) + << " pln: " << side_char(side2) + << " ct: " << side_char(side3) + //<< " def: " << side_char(side4) + << " cart: " << side_char(side5) + << std::endl; +} + +template +void test_side(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3, + int expected) +{ + test_side1(case_id, p1, p2, p3, expected); + //test_side1(case_id, p2, p1, p3, -expected); +} + + +template +void test_all() +{ + typedef std::pair pair; + + Point amsterdam(5.9, 52.4); + Point barcelona(2.0, 41.0); + Point paris(2.0, 48.0); + Point milan(7.0, 45.0); + + goto wrong; + + test_side("bp-m", barcelona, paris, milan, -1); + test_side("bm-p", barcelona, milan, paris, 1); + test_side("mp-b", milan, paris, barcelona, 1); + + test_side("am-p", amsterdam, milan, paris, -1); + test_side("pm-a", paris, milan, amsterdam, 1); + +wrong: + Point blog_p1(10.0, 30.0); + Point blog_p2(50.0, 50.0); + Point blog_p(30.0, 39.0); + test_side("blog1", blog_p1, blog_p2, blog_p, 1); +return; + + // http://www.gcmap.com/mapui?P=50N+80E-60N+50W,65N+30E + //Point blog_np1(80.0, 50.0); + //Point blog_np2(-50.0, 60.0); + // http://www.gcmap.com/mapui?P=50N+140E-60N+10E,65N+30E + Point blog_np1(140.0, 50.0); + Point blog_np2(10.0, 60.0); + Point blog_np(30.0, 65.0); + //test_side(blog_np1, blog_np2, blog_np, 1); + test_side("40", blog_np1, blog_np2, Point(30.0, 40.0), 1); + test_side("45", blog_np1, blog_np2, Point(30.0, 45.0), 1); + test_side("50", blog_np1, blog_np2, Point(30.0, 50.0), 1); + test_side("55", blog_np1, blog_np2, Point(30.0, 55.0), 1); + test_side("60", blog_np1, blog_np2, Point(30.0, 60.0), 1); + test_side("65", blog_np1, blog_np2, Point(30.0, 65.0), 1); + test_side("70", blog_np1, blog_np2, Point(30.0, 70.0), 1); + test_side("75", blog_np1, blog_np2, Point(30.0, 75.0), 1); +} + +int test_main(int, char* []) +{ + //test_all > >(); + test_all > >(); + + return 0; +} diff --git a/test/strategies/side_by_cross_track.vcproj b/test/strategies/spherical_side.vcproj similarity index 92% rename from test/strategies/side_by_cross_track.vcproj rename to test/strategies/spherical_side.vcproj index e5f1a9359..70dd8689c 100644 --- a/test/strategies/side_by_cross_track.vcproj +++ b/test/strategies/spherical_side.vcproj @@ -2,9 +2,9 @@ @@ -18,7 +18,7 @@ diff --git a/test/strategies/strategies_tests.sln b/test/strategies/strategies_tests.sln index 6120639f4..226baff48 100644 --- a/test/strategies/strategies_tests.sln +++ b/test/strategies/strategies_tests.sln @@ -14,7 +14,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "projected_point", "projecte EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "segment_intersection_collinear", "segment_intersection_collinear.vcproj", "{2D0CB6D3-6ABC-4119-A235-66E6065A279E}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "side_by_cross_track", "side_by_cross_track.vcproj", "{ADBE38D8-1828-48A2-BBA1-81F50B53C67C}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spherical_side", "spherical_side.vcproj", "{ADBE38D8-1828-48A2-BBA1-81F50B53C67C}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "within", "within.vcproj", "{AB13D2AC-FD34-4DE4-BD8E-4D463050E5DD}" EndProject diff --git a/test_extensions/gis/latlong/andoyer.vcproj b/test_extensions/gis/latlong/andoyer.vcproj index a0051abb3..40fd85ca6 100644 --- a/test_extensions/gis/latlong/andoyer.vcproj +++ b/test_extensions/gis/latlong/andoyer.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\andoyer" ConfigurationType="1" - InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops" + InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops" CharacterSet="1" > @@ -114,7 +114,7 @@ /> #include -#include +//#include template @@ -177,6 +177,7 @@ void test_latlong(double perc) // with holes test_area_polygon_ll, bg::model::ll::point >(false, true, perc); + } int test_main(int, char* []) diff --git a/test_extensions/gis/latlong/area_ll.vcproj b/test_extensions/gis/latlong/area_ll.vcproj index 415819d7f..a12a44a1e 100644 --- a/test_extensions/gis/latlong/area_ll.vcproj +++ b/test_extensions/gis/latlong/area_ll.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\area_ll" ConfigurationType="1" - InheritedPropertySheets="..\..\..\boost.vsprops" + InheritedPropertySheets="..\..\boost.vsprops" CharacterSet="1" > @@ -114,7 +114,7 @@ /> @@ -114,7 +114,7 @@ /> diff --git a/test_extensions/gis/latlong/parse.vcproj b/test_extensions/gis/latlong/parse.vcproj index ac70a68d5..f923abd70 100644 --- a/test_extensions/gis/latlong/parse.vcproj +++ b/test_extensions/gis/latlong/parse.vcproj @@ -21,7 +21,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\parse" ConfigurationType="1" - InheritedPropertySheets="../../../boost.vsprops" + InheritedPropertySheets="../../boost.vsprops" CharacterSet="1" > diff --git a/test_extensions/gis/latlong/parse_dms.vcproj b/test_extensions/gis/latlong/parse_dms.vcproj index 4d7f71f8b..63a2443fd 100644 --- a/test_extensions/gis/latlong/parse_dms.vcproj +++ b/test_extensions/gis/latlong/parse_dms.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\parse_dms" ConfigurationType="1" - InheritedPropertySheets="..\..\..\boost.vsprops" + InheritedPropertySheets="..\..\boost.vsprops" CharacterSet="1" > diff --git a/test_extensions/gis/latlong/point_ll.vcproj b/test_extensions/gis/latlong/point_ll.vcproj index 31412e6bc..a3e0a0fe5 100644 --- a/test_extensions/gis/latlong/point_ll.vcproj +++ b/test_extensions/gis/latlong/point_ll.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\point_ll" ConfigurationType="1" - InheritedPropertySheets="..\..\..\boost.vsprops" + InheritedPropertySheets="..\..\boost.vsprops" CharacterSet="1" > diff --git a/test_extensions/gis/latlong/vincenty.vcproj b/test_extensions/gis/latlong/vincenty.vcproj index d2cf480f6..4e6908074 100644 --- a/test_extensions/gis/latlong/vincenty.vcproj +++ b/test_extensions/gis/latlong/vincenty.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)\vincenty" ConfigurationType="1" - InheritedPropertySheets="..\..\..\boost.vsprops;..\..\..\ttmath.vsprops" + InheritedPropertySheets="..\..\boost.vsprops;..\..\ttmath.vsprops" CharacterSet="1" > @@ -114,7 +114,7 @@ />