• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
5 
6 // This file was modified by Oracle on 2014, 2015, 2016, 2018.
7 // Modifications copyright (c) 2014-2018 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 #include "test_within.hpp"
16 
17 
18 #include <boost/geometry/geometries/geometries.hpp>
19 #include <boost/geometry/geometries/point_xy.hpp>
20 #include <boost/geometry/geometries/multi_point.hpp>
21 #include <boost/geometry/geometries/multi_linestring.hpp>
22 #include <boost/geometry/geometries/multi_polygon.hpp>
23 
24 template <typename P1, typename P2>
test_point_box()25 void test_point_box()
26 {
27     typedef bg::model::box<P1> box_type1;
28     typedef bg::model::box<P2> box_type2;
29 
30     test_geometry<P1, box_type2>("POINT(1 1)", "BOX(0 0,2 2)", true);
31     test_geometry<P1, box_type2>("POINT(0 0)", "BOX(0 0,2 2)", false);
32     test_geometry<P1, box_type2>("POINT(2 2)", "BOX(0 0,2 2)", false);
33     test_geometry<P1, box_type2>("POINT(0 1)", "BOX(0 0,2 2)", false);
34     test_geometry<P1, box_type2>("POINT(1 0)", "BOX(0 0,2 2)", false);
35 
36     test_geometry<P1, box_type2>("POINT(3 3)", "BOX(1 1,4 4)", true);
37     test_geometry<P2, box_type1>("POINT(3 3)", "BOX(0 0,5 5)", true);
38 
39     test_geometry<box_type1, box_type2>("BOX(1 1,2 2)", "BOX(0 0,3 3)", true);
40     test_geometry<box_type1, box_type2>("BOX(0 0,3 3)", "BOX(1 1,2 2)", false);
41 
42     test_geometry<box_type1, box_type2>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true);
43     test_geometry<box_type1, box_type2>("BOX(3 1,3 3)", "BOX(0 0,3 3)", false);
44 
45     test_geometry<box_type1, box_type2>("BOX(1 1,4 4)", "BOX(0 0,5 5)", true);
46     test_geometry<box_type2, box_type1>("BOX(0 0,5 5)", "BOX(1 1,4 4)", false);
47 
48     /*
49     test_within_code<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", 1);
50     test_within_code<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", 0);
51     test_within_code<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", 0);
52     test_within_code<P, box_type>("POINT(0 3)", "BOX(0 0,2 2)", -1);
53     test_within_code<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", -1);
54 
55     test_within_code<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", 1);
56     test_within_code<box_type, box_type>("BOX(0 1,2 2)", "BOX(0 0,3 3)", 0);
57     test_within_code<box_type, box_type>("BOX(1 0,2 2)", "BOX(0 0,3 3)", 0);
58     test_within_code<box_type, box_type>("BOX(1 1,2 3)", "BOX(0 0,3 3)", 0);
59     test_within_code<box_type, box_type>("BOX(1 1,3 2)", "BOX(0 0,3 3)", 0);
60     test_within_code<box_type, box_type>("BOX(1 1,3 4)", "BOX(0 0,3 3)", -1);
61     */
62 }
63 
test_point_box_3d()64 void test_point_box_3d()
65 {
66     typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type;
67     typedef boost::geometry::model::box<point_type> box_type;
68     box_type box(point_type(0, 0, 0), point_type(4, 4, 4));
69     BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 2), box), true);
70     BOOST_CHECK_EQUAL(bg::within(point_type(2, 4, 2), box), false);
71     BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 4), box), false);
72     BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 5), box), false);
73 
74     box_type box2(point_type(2, 2, 2), point_type(3, 3, 3));
75     BOOST_CHECK_EQUAL(bg::within(box2, box), true);
76 
77 }
78 
79 template <typename P1, typename P2>
test_point_poly()80 void test_point_poly()
81 {
82     typedef boost::geometry::model::polygon<P1> poly1;
83     typedef boost::geometry::model::polygon<P2> poly2;
84 
85     test_geometry<P1, poly2>("POINT(3 3)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
86     test_geometry<P2, poly1>("POINT(3 3)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
87 }
88 
89 template <typename P1, typename P2>
test_all()90 void test_all()
91 {
92     test_point_box<P1, P2>();
93     test_point_poly<P1, P2>();
94 }
95 
96 template <typename P>
test_all()97 void test_all()
98 {
99     test_all<P, P>();
100 }
101 
test_strategy()102 void test_strategy()
103 {
104     // Test by explicitly specifying a strategy
105     typedef bg::model::d2::point_xy<double> point_type;
106     typedef bg::model::box<point_type> box_type;
107     point_type p(3, 3);
108     box_type b(point_type(0, 0), point_type(5, 5));
109     box_type b0(point_type(0, 0), point_type(5, 0));
110 
111     bool r = bg::within(p, b,
112         bg::strategy::within::cartesian_point_box());
113     BOOST_CHECK_EQUAL(r, true);
114 
115     r = bg::within(b, b,
116         bg::strategy::within::box_in_box<box_type, box_type>());
117     BOOST_CHECK_EQUAL(r, true);
118 
119     r = bg::within(b0, b0,
120         bg::strategy::within::box_in_box<box_type, box_type>());
121     BOOST_CHECK_EQUAL(r, false);
122 
123     r = bg::within(p, b,
124         bg::strategy::within::point_in_box_by_side<>());
125     BOOST_CHECK_EQUAL(r, true);
126 }
127 
128 
test_main(int,char * [])129 int test_main( int , char* [] )
130 {
131     typedef boost::geometry::model::d2::point_xy<double> xyd;
132     typedef boost::geometry::model::d2::point_xy<float> xyf;
133     typedef boost::geometry::model::d2::point_xy<int> xyi;
134     typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> p2d;
135 
136     test_all<xyd, p2d>();
137     test_all<xyf, p2d>();
138     test_all<xyi, xyd>();
139 
140     test_all<xyi>();
141     test_all<xyd>();
142 
143     test_point_box_3d();
144     test_strategy();
145 
146 
147 #if defined(HAVE_TTMATH)
148     test_all<bg::model::d2::point_xy<ttmath_big> >();
149 #endif
150 
151     return 0;
152 }
153