// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // This file was modified by Oracle on 2014, 2015. // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // 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 #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, int expected_cartesian) { namespace bgss = bg::strategy::side; // std::cout << case_id << ": "; //int s = bgss::side_via_plane<>::apply(p1, p2, p3); int side_ssf = bgss::spherical_side_formula<>::apply(p1, p2, p3); //int side2 = bgss::side_via_plane<>::apply(p1, p2, p3); int side_ct = bgss::side_by_cross_track<>::apply(p1, p2, p3); // non-official typedef bg::srs::spheroid spheroid; spheroid const sph(1.0, 1.0); int side_mssf1 = bgss::mapping_spherical_side_formula(sph).apply(p1, p2, p3); int side_mssf2 = bgss::mapping_spherical_side_formula(sph).apply(p1, p2, p3); int side_mssf3 = bgss::mapping_spherical_side_formula(sph).apply(p1, p2, p3); int side_andoyer = bgss::andoyer(sph).apply(p1, p2, p3); int side_thomas = bgss::thomas(sph).apply(p1, p2, p3); int side_vincenty = bgss::vincenty(sph).apply(p1, p2, p3); // cartesian typedef bg::strategy::side::services::default_strategy::type cartesian_strategy; int side_cart = cartesian_strategy::apply(p1, p2, p3); BOOST_CHECK_EQUAL(side_ssf, expected); BOOST_CHECK_EQUAL(side_ct, expected); BOOST_CHECK_EQUAL(side_mssf1, expected); BOOST_CHECK_EQUAL(side_mssf2, expected); BOOST_CHECK_EQUAL(side_mssf3, expected); BOOST_CHECK_EQUAL(side_andoyer, expected); BOOST_CHECK_EQUAL(side_thomas, expected); BOOST_CHECK_EQUAL(side_vincenty, expected); BOOST_CHECK_EQUAL(side_cart, expected_cartesian); /* 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, int expected_cartesian = -999) { if (expected_cartesian == -999) { expected_cartesian = expected; } test_side1(case_id, p1, p2, p3, expected, expected_cartesian); test_side1(case_id, p2, p1, p3, -expected, -expected_cartesian); } template void test_all() { typedef typename bg::coordinate_type::type CT; Point amsterdam(bg::math::rounding_cast(5.9), bg::math::rounding_cast(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); // http://www.gcmap.com/mapui?P=30N+10E-50N+50E,39N+30E Point gcmap_p1(10.0, 30.0); Point gcmap_p2(50.0, 50.0); test_side("blog1", gcmap_p1, gcmap_p2, Point(30.0, 41.0), -1, 1); test_side("blog1", gcmap_p1, gcmap_p2, Point(30.0, 42.0), -1, 1); test_side("blog1", gcmap_p1, gcmap_p2, Point(30.0, 43.0), -1, 1); test_side("blog1", gcmap_p1, gcmap_p2, Point(30.0, 44.0), 1); // http://www.gcmap.com/mapui?P=50N+80E-60N+50W,65N+30E Point gcmap_np1(80.0, 50.0); Point gcmap_np2(-50.0, 60.0); // http://www.gcmap.com/mapui?P=50N+140E-60N+10E,65N+30E //Point gcmap_np1(140.0, 50.0); //Point gcmap_np2(10.0, 60.0); //test_side(gcmap_np1, gcmap_np2, gcmap_np, 1); test_side("40", gcmap_np1, gcmap_np2, Point(30.0, 60.0), 1, -1); test_side("45", gcmap_np1, gcmap_np2, Point(30.0, 65.0), 1, -1); test_side("70", gcmap_np1, gcmap_np2, Point(30.0, 70.0), 1, -1); test_side("75", gcmap_np1, gcmap_np2, Point(30.0, 75.0), -1); } int test_main(int, char* []) { test_all > >(); test_all > >(); #if defined(HAVE_TTMATH) typedef ttmath::Big<1,4> tt; test_all > >(); #endif return 0; }