]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/relational_operations/covered_by/covered_by.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / relational_operations / covered_by / covered_by.cpp
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 2015.
7 // Modifications copyright (c) 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 #include "test_covered_by.hpp"
16
17
18 #include <boost/geometry/geometries/geometries.hpp>
19 #include <boost/geometry/geometries/point_xy.hpp>
20
21
22 template <typename P>
23 void test_all()
24 {
25 /*
26 // trivial case
27 test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true, false);
28
29 // on border/corner
30 test_ring<P>("POINT(0 0)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true);
31 test_ring<P>("POINT(0 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true);
32
33 // aligned to segment/vertex
34 test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", true, false);
35 test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", true, false);
36
37 // same polygon, but point on border
38 test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", false, true);
39 test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", false, true);
40
41 // holes
42 test_geometry<P, bg::model::polygon<P> >("POINT(2 2)",
43 "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1))", false);
44
45 */
46
47 typedef bg::model::segment<P> seg;
48 test_geometry<P, seg>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true);
49 test_geometry<P, seg>("POINT(0 0)", "LINESTRING(0 0, 1 1)", true);
50 test_geometry<P, seg>("POINT(1 0)", "LINESTRING(0 0, 1 1)", false);
51
52 // linestrings
53 typedef bg::model::linestring<P> ls;
54 test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", true);
55 test_geometry<P, ls>("POINT(3 3)", "LINESTRING(0 0,1 1,2 2)", false);
56 test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,3 3)", true);
57
58 // multi_linestrings
59 typedef bg::model::multi_linestring<ls> mls;
60 test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1))", true);
61 test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1),(0 0,1 0))", true);
62
63 typedef bg::model::box<P> box_type;
64
65 test_geometry<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", true);
66 test_geometry<P, box_type>("POINT(0 0)", "BOX(0 0,2 2)", true);
67 test_geometry<P, box_type>("POINT(2 2)", "BOX(0 0,2 2)", true);
68 test_geometry<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", true);
69 test_geometry<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", true);
70 test_geometry<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", false);
71
72 test_geometry<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", true);
73 test_geometry<box_type, box_type>("BOX(0 0,3 3)", "BOX(1 1,2 2)", false);
74 test_geometry<box_type, box_type>("BOX(0 0,2 2)", "BOX(0 0,3 3)", true);
75 test_geometry<box_type, box_type>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true);
76 test_geometry<box_type, box_type>("BOX(1 2,3 3)", "BOX(0 0,3 3)", true);
77 test_geometry<box_type, box_type>("BOX(1 1,4 3)", "BOX(0 0,3 3)", false);
78 }
79
80
81 void test_3d()
82 {
83 typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type;
84 typedef boost::geometry::model::box<point_type> box_type;
85 box_type box(point_type(0, 0, 0), point_type(4, 4, 4));
86 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 2), box), true);
87 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 4, 2), box), true);
88 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 4), box), true);
89 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 5), box), false);
90 }
91
92 template <typename P1, typename P2>
93 void test_mixed_of()
94 {
95 typedef boost::geometry::model::polygon<P1> polygon_type1;
96 typedef boost::geometry::model::polygon<P2> polygon_type2;
97 typedef boost::geometry::model::box<P1> box_type1;
98 typedef boost::geometry::model::box<P2> box_type2;
99
100 polygon_type1 poly1;
101 polygon_type2 poly2;
102 boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly1);
103 boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly2);
104
105 box_type1 box1(P1(1, 1), P1(4, 4));
106 box_type2 box2(P2(0, 0), P2(5, 5));
107 P1 p1(3, 3);
108 P2 p2(3, 3);
109
110 BOOST_CHECK_EQUAL(bg::covered_by(p1, poly2), true);
111 BOOST_CHECK_EQUAL(bg::covered_by(p2, poly1), true);
112 BOOST_CHECK_EQUAL(bg::covered_by(p2, box1), true);
113 BOOST_CHECK_EQUAL(bg::covered_by(p1, box2), true);
114 BOOST_CHECK_EQUAL(bg::covered_by(box1, box2), true);
115 BOOST_CHECK_EQUAL(bg::covered_by(box2, box1), false);
116 }
117
118
119 void test_mixed()
120 {
121 // Mixing point types and coordinate types
122 test_mixed_of
123 <
124 boost::geometry::model::d2::point_xy<double>,
125 boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
126 >();
127 test_mixed_of
128 <
129 boost::geometry::model::d2::point_xy<float>,
130 boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
131 >();
132 test_mixed_of
133 <
134 boost::geometry::model::d2::point_xy<int>,
135 boost::geometry::model::d2::point_xy<double>
136 >();
137 }
138
139
140 int test_main( int , char* [] )
141 {
142 test_all<bg::model::d2::point_xy<int> >();
143 test_all<bg::model::d2::point_xy<double> >();
144
145 //test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
146
147 test_mixed();
148 test_3d();
149
150
151 #if defined(HAVE_TTMATH)
152 test_all<bg::model::d2::point_xy<ttmath_big> >();
153 test_eps<bg::model::d2::point_xy<ttmath_big> >();
154 //test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
155 #endif
156
157 return 0;
158 }