• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // This file was modified by Oracle on 2014, 2015.
7 // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
8 
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 
15 
16 #include <geometry_test_common.hpp>
17 
18 
19 #include <boost/geometry/algorithms/assign.hpp>
20 
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/core/cs.hpp>
23 
24 #include <boost/geometry/geometries/point.hpp>
25 #include <boost/geometry/geometries/segment.hpp>
26 
27 #include <boost/geometry/strategies/spherical/side_by_cross_track.hpp>
28 //#include <boost/geometry/strategies/spherical/side_via_plane.hpp>
29 #include <boost/geometry/strategies/spherical/ssf.hpp>
30 #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
31 
32 #include <boost/geometry/strategies/geographic/mapping_ssf.hpp>
33 #include <boost/geometry/strategies/geographic/side_andoyer.hpp>
34 #include <boost/geometry/strategies/geographic/side_thomas.hpp>
35 #include <boost/geometry/strategies/geographic/side_vincenty.hpp>
36 
37 #include <boost/geometry/util/math.hpp>
38 
39 
40 namespace boost { namespace geometry {
41 
42 template <typename Vector, typename Point1, typename Point2>
create_vector(Point1 const & p1,Point2 const & p2)43 static inline Vector create_vector(Point1 const& p1, Point2 const& p2)
44 {
45     Vector v;
46     convert(p1, v);
47     subtract_point(v, p2);
48     return v;
49 }
50 
51 }}
52 
side_char(int side)53 inline char side_char(int side)
54 {
55     return side == 1 ? 'L'
56         : side == -1 ? 'R'
57         : '-'
58         ;
59 }
60 
61 template <typename Point>
test_side1(std::string const &,Point const & p1,Point const & p2,Point const & p3,int expected,int expected_cartesian)62 void test_side1(std::string const& /*case_id*/, Point const& p1, Point const& p2, Point const& p3,
63                    int expected, int expected_cartesian)
64 {
65     namespace bgss = bg::strategy::side;
66 
67     // std::cout << case_id << ": ";
68     //int s = bgss::side_via_plane<>::apply(p1, p2, p3);
69     int side_ssf = bgss::spherical_side_formula<>::apply(p1, p2, p3);
70     //int side2 = bgss::side_via_plane<>::apply(p1, p2, p3);
71     int side_ct = bgss::side_by_cross_track<>::apply(p1, p2, p3);
72 
73     // non-official
74     typedef bg::srs::spheroid<double> spheroid;
75     spheroid const sph(1.0, 1.0);
76     int side_mssf1 = bgss::mapping_spherical_side_formula<spheroid>(sph).apply(p1, p2, p3);
77     int side_mssf2 = bgss::mapping_spherical_side_formula<spheroid, bgss::mapping_reduced>(sph).apply(p1, p2, p3);
78     int side_mssf3 = bgss::mapping_spherical_side_formula<spheroid, bgss::mapping_geocentric>(sph).apply(p1, p2, p3);
79     int side_andoyer = bgss::andoyer<spheroid>(sph).apply(p1, p2, p3);
80     int side_thomas = bgss::thomas<spheroid>(sph).apply(p1, p2, p3);
81     int side_vincenty = bgss::vincenty<spheroid>(sph).apply(p1, p2, p3);
82 
83     // cartesian
84     typedef bg::strategy::side::services::default_strategy<bg::cartesian_tag>::type cartesian_strategy;
85     int side_cart = cartesian_strategy::apply(p1, p2, p3);
86 
87     BOOST_CHECK_EQUAL(side_ssf, expected);
88     BOOST_CHECK_EQUAL(side_ct, expected);
89     BOOST_CHECK_EQUAL(side_mssf1, expected);
90     BOOST_CHECK_EQUAL(side_mssf2, expected);
91     BOOST_CHECK_EQUAL(side_mssf3, expected);
92     BOOST_CHECK_EQUAL(side_andoyer, expected);
93     BOOST_CHECK_EQUAL(side_thomas, expected);
94     BOOST_CHECK_EQUAL(side_vincenty, expected);
95     BOOST_CHECK_EQUAL(side_cart, expected_cartesian);
96 
97     /*
98     std::cout
99         << "exp: " << side_char(expected)
100         << " ssf: " << side_char(side1)
101         << " pln: " << side_char(side2)
102         << " ct: " << side_char(side3)
103         //<< " def: " << side_char(side4)
104         << " cart: " << side_char(side5)
105         << std::endl;
106     */
107 }
108 
109 template <typename Point>
test_side(std::string const & case_id,Point const & p1,Point const & p2,Point const & p3,int expected,int expected_cartesian=-999)110 void test_side(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3,
111                    int expected, int expected_cartesian = -999)
112 {
113     if (expected_cartesian == -999)
114     {
115         expected_cartesian = expected;
116     }
117     test_side1(case_id, p1, p2, p3, expected, expected_cartesian);
118     test_side1(case_id, p2, p1, p3, -expected, -expected_cartesian);
119 }
120 
121 
122 template <typename Point>
test_all()123 void test_all()
124 {
125     typedef typename bg::coordinate_type<Point>::type CT;
126 
127     Point amsterdam(bg::math::rounding_cast<CT>(5.9), bg::math::rounding_cast<CT>(52.4));
128     Point barcelona(2.0, 41.0);
129     Point paris(2.0, 48.0);
130     Point milan(7.0, 45.0);
131 
132     //goto wrong;
133 
134     test_side<Point>("bp-m", barcelona, paris, milan, -1);
135     test_side<Point>("bm-p", barcelona, milan, paris, 1);
136     test_side<Point>("mp-b", milan, paris, barcelona, 1);
137 
138     test_side<Point>("am-p", amsterdam, milan, paris, -1);
139     test_side<Point>("pm-a", paris, milan, amsterdam, 1);
140 
141     // http://www.gcmap.com/mapui?P=30N+10E-50N+50E,39N+30E
142     Point gcmap_p1(10.0, 30.0);
143     Point gcmap_p2(50.0, 50.0);
144     test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 41.0), -1, 1);
145     test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 42.0), -1, 1);
146     test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 43.0), -1, 1);
147     test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 44.0), 1);
148 
149     // http://www.gcmap.com/mapui?P=50N+80E-60N+50W,65N+30E
150     Point gcmap_np1(80.0, 50.0);
151     Point gcmap_np2(-50.0, 60.0);
152     // http://www.gcmap.com/mapui?P=50N+140E-60N+10E,65N+30E
153     //Point gcmap_np1(140.0, 50.0);
154     //Point gcmap_np2(10.0, 60.0);
155     //test_side<Point>(gcmap_np1, gcmap_np2, gcmap_np, 1);
156     test_side<Point>("40", gcmap_np1, gcmap_np2, Point(30.0, 60.0), 1, -1);
157     test_side<Point>("45", gcmap_np1, gcmap_np2, Point(30.0, 65.0), 1, -1);
158     test_side<Point>("70", gcmap_np1, gcmap_np2, Point(30.0, 70.0), 1, -1);
159     test_side<Point>("75", gcmap_np1, gcmap_np2, Point(30.0, 75.0), -1);
160 }
161 
test_main(int,char * [])162 int test_main(int, char* [])
163 {
164     test_all<bg::model::point<int, 2, bg::cs::spherical<bg::degree> > >();
165     test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
166 
167 #if defined(HAVE_TTMATH)
168     typedef ttmath::Big<1,4> tt;
169     test_all<bg::model::point<tt, 2, bg::cs::spherical_equatorial<bg::degree> > >();
170 #endif
171 
172     return 0;
173 }
174