]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/relational_operations/covered_by/covered_by.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / relational_operations / covered_by / covered_by.cpp
CommitLineData
7c673cae
FG
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
b32b8144
FG
6// This file was modified by Oracle on 2015, 2017.
7// Modifications copyright (c) 2017 Oracle and/or its affiliates.
7c673cae
FG
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
22template <typename P>
23void 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
b32b8144
FG
47 test_geometry<P, P>("POINT(0 0)", "POINT(0 0)", true);
48 test_geometry<P, P>("POINT(0 0)", "POINT(1 1)", false);
49
50 typedef bg::model::multi_point<P> mpt;
51 test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(0 0, 1 1)", true);
52 test_geometry<mpt, P>("MULTIPOINT(0 0, 1 1)", "POINT(1 1)", false);
53 test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 1)", "MULTIPOINT(1 1, 2 2)", false);
54
7c673cae
FG
55 typedef bg::model::segment<P> seg;
56 test_geometry<P, seg>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true);
57 test_geometry<P, seg>("POINT(0 0)", "LINESTRING(0 0, 1 1)", true);
58 test_geometry<P, seg>("POINT(1 0)", "LINESTRING(0 0, 1 1)", false);
59
60 // linestrings
61 typedef bg::model::linestring<P> ls;
62 test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", true);
63 test_geometry<P, ls>("POINT(3 3)", "LINESTRING(0 0,1 1,2 2)", false);
64 test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,3 3)", true);
65
66 // multi_linestrings
67 typedef bg::model::multi_linestring<ls> mls;
68 test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1))", true);
69 test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1),(0 0,1 0))", true);
70
b32b8144
FG
71 // multi_point/segment
72 typedef bg::model::multi_point<P> mpt;
73 test_geometry<mpt, seg>("MULTIPOINT(0 0, 1 1)", "LINESTRING(0 0, 2 2)", true);
74
75 // multi_point/linestring
76 test_geometry<mpt, ls>("MULTIPOINT(0 0, 2 2)", "LINESTRING(0 0, 2 2)", true);
77 test_geometry<mpt, ls>("MULTIPOINT(1 1, 3 3)", "LINESTRING(0 0, 2 2)", false);
78
79 // multi_point/multi_linestring
80 test_geometry<mpt, mls>("MULTIPOINT(0 0, 1 1)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", true);
81 test_geometry<mpt, mls>("MULTIPOINT(0 0, 2 2)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", true);
82 test_geometry<mpt, mls>("MULTIPOINT(0 0, 3 3)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", true);
83 test_geometry<mpt, mls>("MULTIPOINT(1 1, 4 4)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", false);
84
85 // point/A
86 typedef bg::model::ring<P> ring;
87 typedef bg::model::polygon<P> poly;
88 typedef bg::model::multi_polygon<poly> mpoly;
89 test_geometry<P, ring>("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true);
90 test_geometry<P, poly>("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true);
91 test_geometry<P, mpoly>("POINT(1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", true);
92
93 // multi_point/A
94 test_geometry<mpt, ring>("MULTIPOINT(0 0, 1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true);
95 test_geometry<mpt, poly>("MULTIPOINT(0 0, 2 2)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true);
96 test_geometry<mpt, poly>("MULTIPOINT(1 1, 3 3)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false);
97 test_geometry<mpt, mpoly>("MULTIPOINT(0 0, 1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", true);
98 test_geometry<mpt, mpoly>("MULTIPOINT(0 0, 2 2)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", true);
99 test_geometry<mpt, mpoly>("MULTIPOINT(0 0, 3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", true);
100 test_geometry<mpt, mpoly>("MULTIPOINT(1 1, 4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", false);
101
7c673cae
FG
102 typedef bg::model::box<P> box_type;
103
104 test_geometry<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", true);
105 test_geometry<P, box_type>("POINT(0 0)", "BOX(0 0,2 2)", true);
106 test_geometry<P, box_type>("POINT(2 2)", "BOX(0 0,2 2)", true);
107 test_geometry<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", true);
108 test_geometry<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", true);
109 test_geometry<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", false);
110
111 test_geometry<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", true);
112 test_geometry<box_type, box_type>("BOX(0 0,3 3)", "BOX(1 1,2 2)", false);
113 test_geometry<box_type, box_type>("BOX(0 0,2 2)", "BOX(0 0,3 3)", true);
114 test_geometry<box_type, box_type>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true);
115 test_geometry<box_type, box_type>("BOX(1 2,3 3)", "BOX(0 0,3 3)", true);
116 test_geometry<box_type, box_type>("BOX(1 1,4 3)", "BOX(0 0,3 3)", false);
117}
118
119
120void test_3d()
121{
122 typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type;
123 typedef boost::geometry::model::box<point_type> box_type;
124 box_type box(point_type(0, 0, 0), point_type(4, 4, 4));
125 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 2), box), true);
126 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 4, 2), box), true);
127 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 4), box), true);
128 BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 5), box), false);
129}
130
131template <typename P1, typename P2>
132void test_mixed_of()
133{
134 typedef boost::geometry::model::polygon<P1> polygon_type1;
135 typedef boost::geometry::model::polygon<P2> polygon_type2;
136 typedef boost::geometry::model::box<P1> box_type1;
137 typedef boost::geometry::model::box<P2> box_type2;
138
139 polygon_type1 poly1;
140 polygon_type2 poly2;
141 boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly1);
142 boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly2);
143
144 box_type1 box1(P1(1, 1), P1(4, 4));
145 box_type2 box2(P2(0, 0), P2(5, 5));
146 P1 p1(3, 3);
147 P2 p2(3, 3);
148
149 BOOST_CHECK_EQUAL(bg::covered_by(p1, poly2), true);
150 BOOST_CHECK_EQUAL(bg::covered_by(p2, poly1), true);
151 BOOST_CHECK_EQUAL(bg::covered_by(p2, box1), true);
152 BOOST_CHECK_EQUAL(bg::covered_by(p1, box2), true);
153 BOOST_CHECK_EQUAL(bg::covered_by(box1, box2), true);
154 BOOST_CHECK_EQUAL(bg::covered_by(box2, box1), false);
155}
156
157
158void test_mixed()
159{
160 // Mixing point types and coordinate types
161 test_mixed_of
162 <
163 boost::geometry::model::d2::point_xy<double>,
164 boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
165 >();
166 test_mixed_of
167 <
168 boost::geometry::model::d2::point_xy<float>,
169 boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
170 >();
171 test_mixed_of
172 <
173 boost::geometry::model::d2::point_xy<int>,
174 boost::geometry::model::d2::point_xy<double>
175 >();
176}
177
178
179int test_main( int , char* [] )
180{
181 test_all<bg::model::d2::point_xy<int> >();
182 test_all<bg::model::d2::point_xy<double> >();
183
184 //test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
185
186 test_mixed();
187 test_3d();
188
189
190#if defined(HAVE_TTMATH)
191 test_all<bg::model::d2::point_xy<ttmath_big> >();
192 test_eps<bg::model::d2::point_xy<ttmath_big> >();
193 //test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
194#endif
195
196 return 0;
197}