1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2014, 2015.
7 // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
16 #include <geometry_test_common.hpp>
19 #include <boost/geometry/algorithms/assign.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/core/cs.hpp>
24 #include <boost/geometry/geometries/point.hpp>
25 #include <boost/geometry/geometries/segment.hpp>
27 #include <boost/geometry/strategies/spherical/side_by_cross_track.hpp>
28 #include <boost/geometry/strategies/spherical/ssf.hpp>
29 #include <boost/geometry/strategy/cartesian/side_robust.hpp>
30 #include <boost/geometry/strategy/cartesian/side_by_triangle.hpp>
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>
37 #include <boost/geometry/util/math.hpp>
40 namespace boost
{ namespace geometry
{
42 template <typename Vector
, typename Point1
, typename Point2
>
43 static inline Vector
create_vector(Point1
const& p1
, Point2
const& p2
)
47 subtract_point(v
, p2
);
53 inline char side_char(int side
)
55 return side
== 1 ? 'L'
61 template <typename Point
>
62 void test_side1(std::string
const& /*case_id*/, Point
const& p1
, Point
const& p2
, Point
const& p3
,
63 int expected
, int expected_cartesian
)
65 namespace bgss
= bg::strategy::side
;
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
);
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
);
84 typedef bg::strategy::side::services::default_strategy
<bg::cartesian_tag
>::type cartesian_strategy
;
85 int side_cart
= cartesian_strategy::apply(p1
, p2
, p3
);
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
);
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)
109 template <typename Point
>
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)
113 if (expected_cartesian
== -999)
115 expected_cartesian
= expected
;
117 test_side1(case_id
, p1
, p2
, p3
, expected
, expected_cartesian
);
118 test_side1(case_id
, p2
, p1
, p3
, -expected
, -expected_cartesian
);
122 template <typename Point
>
125 typedef typename
bg::coordinate_type
<Point
>::type CT
;
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);
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);
138 test_side
<Point
>("am-p", amsterdam
, milan
, paris
, -1);
139 test_side
<Point
>("pm-a", paris
, milan
, amsterdam
, 1);
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);
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);
162 int test_main(int, char* [])
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
> > >();