]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/within/within.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
6 // This file was modified by Oracle on 2014, 2015, 2016, 2018.
7 // Modifications copyright (c) 2014-2018 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
15 #include "test_within.hpp"
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>
24 template <typename P1
, typename P2
>
27 typedef bg::model::box
<P1
> box_type1
;
28 typedef bg::model::box
<P2
> box_type2
;
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);
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);
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);
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);
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);
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);
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);
64 void test_point_box_3d()
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);
74 box_type
box2(point_type(2, 2, 2), point_type(3, 3, 3));
75 BOOST_CHECK_EQUAL(bg::within(box2
, box
), true);
79 template <typename P1
, typename P2
>
80 void test_point_poly()
82 typedef boost::geometry::model::polygon
<P1
> poly1
;
83 typedef boost::geometry::model::polygon
<P2
> poly2
;
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);
89 template <typename P1
, typename P2
>
92 test_point_box
<P1
, P2
>();
93 test_point_poly
<P1
, P2
>();
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
;
108 box_type
b(point_type(0, 0), point_type(5, 5));
109 box_type
b0(point_type(0, 0), point_type(5, 0));
111 bool r
= bg::within(p
, b
,
112 bg::strategy::within::cartesian_point_box());
113 BOOST_CHECK_EQUAL(r
, true);
116 bg::strategy::within::box_in_box
<box_type
, box_type
>());
117 BOOST_CHECK_EQUAL(r
, true);
119 r
= bg::within(b0
, b0
,
120 bg::strategy::within::box_in_box
<box_type
, box_type
>());
121 BOOST_CHECK_EQUAL(r
, false);
124 bg::strategy::within::point_in_box_by_side
<>());
125 BOOST_CHECK_EQUAL(r
, true);
129 int test_main( int , char* [] )
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
;
136 test_all
<xyd
, p2d
>();
137 test_all
<xyf
, p2d
>();
138 test_all
<xyi
, xyd
>();
147 #if defined(HAVE_TTMATH)
148 test_all
<bg::model::d2::point_xy
<ttmath_big
> >();