#### /libs/geometry/test/strategies/spherical_side.cpp

https://github.com/delalond/boost_1_54_0-bgq
C++ | 142 lines | 84 code | 31 blank | 27 comment | 4 complexity | c1a24e4be97b2862e7e233e0d5f1eb75 MD5 | raw file
```  1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6// Use, modification and distribution is subject to the Boost Software License,
7// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9
10
11#include <geometry_test_common.hpp>
12
13
14#include <boost/geometry/algorithms/assign.hpp>
15
16
17#include <boost/geometry/strategies/spherical/side_by_cross_track.hpp>
18//#include <boost/geometry/strategies/spherical/side_via_plane.hpp>
19#include <boost/geometry/strategies/spherical/ssf.hpp>
20#include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
21
22#include <boost/geometry/core/cs.hpp>
23
24#include <boost/geometry/geometries/point.hpp>
25#include <boost/geometry/geometries/segment.hpp>
26
27
28namespace boost { namespace geometry {
29
30template <typename Vector, typename Point1, typename Point2>
31static inline Vector create_vector(Point1 const& p1, Point2 const& p2)
32{
33    Vector v;
34    convert(p1, v);
35    subtract_point(v, p2);
36    return v;
37}
38
39}}
40
41inline char side_char(int side)
42{
43    return side == 1 ? 'L'
44        : side == -1 ? 'R'
45        : '-'
46        ;
47}
48
49template <typename Point>
50void test_side1(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3,
51                   int expected, int expected_cartesian)
52{
53    // std::cout << case_id << ": ";
54    //int s = bg::strategy::side::side_via_plane<>::apply(p1, p2, p3);
55    int side_ssf = bg::strategy::side::spherical_side_formula<>::apply(p1, p2, p3);
56    //int side2 = bg::strategy::side::side_via_plane<>::apply(p1, p2, p3);
57    int side_ct = bg::strategy::side::side_by_cross_track<>::apply(p1, p2, p3);
58
59    typedef bg::strategy::side::services::default_strategy<bg::cartesian_tag>::type cartesian_strategy;
60    int side_cart = cartesian_strategy::apply(p1, p2, p3);
61
62
63    BOOST_CHECK_EQUAL(side_ssf, expected);
64    BOOST_CHECK_EQUAL(side_ct, expected);
65    BOOST_CHECK_EQUAL(side_cart, expected_cartesian);
66    /*
67    std::cout
68        << "exp: " << side_char(expected)
69        << " ssf: " << side_char(side1)
70        << " pln: " << side_char(side2)
71        << " ct: " << side_char(side3)
72        //<< " def: " << side_char(side4)
73        << " cart: " << side_char(side5)
74        << std::endl;
75    */
76}
77
78template <typename Point>
79void test_side(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3,
80                   int expected, int expected_cartesian = -999)
81{
82    if (expected_cartesian == -999)
83    {
84        expected_cartesian = expected;
85    }
86    test_side1(case_id, p1, p2, p3, expected, expected_cartesian);
87    test_side1(case_id, p2, p1, p3, -expected, -expected_cartesian);
88}
89
90
91template <typename Point>
92void test_all()
93{
94    typedef std::pair<double, double> pair;
95
96    Point amsterdam(5.9, 52.4);
97    Point barcelona(2.0, 41.0);
98    Point paris(2.0, 48.0);
99    Point milan(7.0, 45.0);
100
101    //goto wrong;
102
103    test_side<Point>("bp-m", barcelona, paris, milan, -1);
104    test_side<Point>("bm-p", barcelona, milan, paris, 1);
105    test_side<Point>("mp-b", milan, paris, barcelona, 1);
106
107    test_side<Point>("am-p", amsterdam, milan, paris, -1);
108    test_side<Point>("pm-a", paris, milan, amsterdam, 1);
109
110    // http://www.gcmap.com/mapui?P=30N+10E-50N+50E,39N+30E
111    Point gcmap_p1(10.0, 30.0);
112    Point gcmap_p2(50.0, 50.0);
113    test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 41.0), -1, 1);
114    test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 42.0), -1, 1);
115    test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 43.0), -1, 1);
116    test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 44.0), 1);
117
118    // http://www.gcmap.com/mapui?P=50N+80E-60N+50W,65N+30E
119    Point gcmap_np1(80.0, 50.0);
120    Point gcmap_np2(-50.0, 60.0);
121    // http://www.gcmap.com/mapui?P=50N+140E-60N+10E,65N+30E
122    //Point gcmap_np1(140.0, 50.0);
123    //Point gcmap_np2(10.0, 60.0);
124    //test_side<Point>(gcmap_np1, gcmap_np2, gcmap_np, 1);
125    test_side<Point>("40", gcmap_np1, gcmap_np2, Point(30.0, 60.0), 1, -1);
126    test_side<Point>("45", gcmap_np1, gcmap_np2, Point(30.0, 65.0), 1, -1);
127    test_side<Point>("70", gcmap_np1, gcmap_np2, Point(30.0, 70.0), 1, -1);
128    test_side<Point>("75", gcmap_np1, gcmap_np2, Point(30.0, 75.0), -1);
129}
130
131int test_main(int, char* [])
132{
133    test_all<bg::model::point<int, 2, bg::cs::spherical<bg::degree> > >();
134    test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
135
136#if defined(HAVE_TTMATH)
137    typedef ttmath::Big<1,4> tt;
138    test_all<bg::model::point<tt, 2, bg::cs::spherical_equatorial<bg::degree> > >();
139#endif
140
141    return 0;
142}
```