• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 
3 // Copyright (c) 2016 Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 #include "test_covered_by.hpp"
11 
12 
13 #include <boost/geometry/geometries/geometries.hpp>
14 
15 
16 template <typename P>
test_point_box()17 void test_point_box()
18 {
19     typedef bg::model::box<P> box_t;
20 
21     test_geometry<P, box_t>("POINT(0 0)",    "BOX(0 0, 1 1)", true);
22     test_geometry<P, box_t>("POINT(1 1)",    "BOX(0 0, 2 2)", true);
23 
24     test_geometry<P, box_t>("POINT(180 1)",  "BOX(170 0, 190 2)", true);
25     test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 190 2)", true);
26     test_geometry<P, box_t>("POINT(180 1)",  "BOX(170 0, 180 2)", true);
27     test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 180 2)", true);
28     test_geometry<P, box_t>("POINT(179 1)",  "BOX(170 0, 190 2)", true);
29     test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 190 2)", true);
30     test_geometry<P, box_t>("POINT(179 1)",  "BOX(170 0, 180 2)", true);
31     test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 180 2)", false);
32     test_geometry<P, box_t>("POINT(169 1)", "BOX(170 0, 180 2)", false);
33 
34     // https://svn.boost.org/trac/boost/ticket/12412
35     test_geometry<P, box_t>("POINT(-0.127592 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
36     // and related
37     test_geometry<P, box_t>("POINT(-2.08882 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
38     test_geometry<P, box_t>("POINT(0.127592 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
39     test_geometry<P, box_t>("POINT(2.08882 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
40 
41     test_geometry<P, box_t>("POINT(179.08882 1)", "BOX(179.08882 0, 538.127592 2)", true);
42     test_geometry<P, box_t>("POINT(178.127592 1)", "BOX(179.08882 0, 538.127592 2)", true);
43     test_geometry<P, box_t>("POINT(179.08882 1)", "BOX(179.08882 0, 182.127592 2)", true);
44     test_geometry<P, box_t>("POINT(-177.872408 1)", "BOX(179.08882 0, 182.127592 2)", true);
45 }
46 
47 template <typename P>
test_box_box()48 void test_box_box()
49 {
50     typedef bg::model::box<P> box_t;
51 
52     test_geometry<box_t, box_t>("BOX(0 0, 1 1)", "BOX(0 0, 1 1)", true);
53 
54     test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(-180 0, 180 1)", true);
55     test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(170 0, 200 1)",  true);
56     test_geometry<box_t, box_t>("BOX(-170 0,-150 1)", "BOX(170 0, 200 1)",  false);
57     test_geometry<box_t, box_t>("BOX(0 0,1 1)",       "BOX(170 0, 370 1)",  true);
58     test_geometry<box_t, box_t>("BOX(0 0,10 1)",      "BOX(170 0, 370 1)",  true);
59     test_geometry<box_t, box_t>("BOX(-180 0,10 1)",   "BOX(170 0, 370 1)",  true);
60     test_geometry<box_t, box_t>("BOX(-180 0,20 1)",   "BOX(170 0, 370 1)",  false);
61     test_geometry<box_t, box_t>("BOX(10 0,20 1)",     "BOX(170 0, 370 1)",  false);
62     test_geometry<box_t, box_t>("BOX(160 0,180 1)",   "BOX(170 0, 370 1)",  false);
63 
64     test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 190 1)",  true); // invalid?
65     test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 191 1)",  true); // invalid?
66     test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(179 0, 190 1)",  true);
67     test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(181 0, 190 1)",  false); // invalid?
68     test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 189 1)",  false); // invalid?
69 
70     // Related to https://svn.boost.org/trac/boost/ticket/12412
71     test_geometry<box_t, box_t>("BOX(-1.346346 51.6, -0.127592 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
72     test_geometry<box_t, box_t>("BOX(-2.08882 51.6, -1.346346 51.7)", "BOX(-2.08882 51.5034, -0.127592 51.9074)", true);
73     test_geometry<box_t, box_t>("BOX(0.127592 51.6, 1.346346 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
74     test_geometry<box_t, box_t>("BOX(1.346346 51.6, 2.08882 51.7)", "BOX(0.127592 51.5034, 2.08882 51.9074)", true);
75 
76     test_geometry<box_t, box_t>("BOX(179.08882 1, 180.0 1)", "BOX(179.08882 0, 538.127592 2)", true);
77     test_geometry<box_t, box_t>("BOX(177.0 1, 178.127592 1)", "BOX(179.08882 0, 538.127592 2)", true);
78     test_geometry<box_t, box_t>("BOX(179.08882 1, 179.9 1)", "BOX(179.08882 0, 182.127592 2)", true);
79     test_geometry<box_t, box_t>("BOX(-179.9 1, -177.872408 1)", "BOX(179.08882 0, 182.127592 2)", true);
80 }
81 
82 template <typename P>
test_point_polygon()83 void test_point_polygon()
84 {
85     typename boost::mpl::if_
86         <
87             boost::is_same<typename bg::cs_tag<P>::type, bg::geographic_tag>,
88             bg::strategy::within::geographic_winding<P>,
89             bg::strategy::within::spherical_winding<P>
90         >::type s;
91 
92     typedef bg::model::polygon<P> poly;
93 
94     // MySQL report 08.2017
95     test_geometry<P, poly>("POINT(-179 0)",
96                            "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
97                            false);
98     test_geometry<P, poly>("POINT(-179 0)",
99                            "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
100                            false,
101                            s);
102 
103     test_geometry<P, poly>("POINT(1 0)",
104                            "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
105                            true);
106     test_geometry<P, poly>("POINT(1 0)",
107                            "POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
108                            true,
109                            s);
110 }
111 
112 template <typename P>
test_cs()113 void test_cs()
114 {
115     test_point_box<P>();
116     test_box_box<P>();
117     test_point_polygon<P>();
118 }
119 
120 
test_main(int,char * [])121 int test_main( int , char* [] )
122 {
123     test_cs<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
124     test_cs<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
125 
126 #if defined(HAVE_TTMATH)
127     test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
128     test_cs<bg::model::point<ttmath_big, 2, bg::cs::geographic<bg::degree> > >();;
129 #endif
130 
131     return 0;
132 }
133