]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/point_in_box.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / strategies / point_in_box.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // This file was modified by Oracle on 2014.
7 // Modifications copyright (c) 2014 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
16 #include <strategies/test_within.hpp>
17
18
19 template <typename Point>
20 void test_box_of(std::string const& wkt_point, std::string const& wkt_box,
21 bool expected_within, bool expected_covered_by)
22 {
23 typedef bg::model::box<Point> box_type;
24
25 Point point;
26 box_type box;
27 bg::read_wkt(wkt_point, point);
28 bg::read_wkt(wkt_box, box);
29
30 bool detected_within = bg::within(point, box);
31 bool detected_covered_by = bg::covered_by(point, box);
32 BOOST_CHECK_EQUAL(detected_within, expected_within);
33 BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
34
35 // Also test with the non-default agnostic side version
36 namespace wi = bg::strategy::within;
37 wi::point_in_box_by_side<> within_strategy;
38 wi::point_in_box_by_side<wi::decide_covered_by> covered_by_strategy;
39
40 detected_within = bg::within(point, box, within_strategy);
41 detected_covered_by = bg::covered_by(point, box, covered_by_strategy);
42 BOOST_CHECK_EQUAL(detected_within, expected_within);
43 BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
44
45 // We might exchange strategies between within/covered by.
46 // So the lines below might seem confusing, but are as intended
47 detected_within = bg::covered_by(point, box, within_strategy);
48 detected_covered_by = bg::within(point, box, covered_by_strategy);
49 BOOST_CHECK_EQUAL(detected_within, expected_within);
50 BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
51
52 // Finally we call the strategies directly
53 detected_within = within_strategy.apply(point, box);
54 detected_covered_by = covered_by_strategy.apply(point, box);
55 BOOST_CHECK_EQUAL(detected_within, expected_within);
56 BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by);
57 }
58
59 template <typename Point>
60 void test_box()
61 {
62 test_box_of<Point>("POINT(1 1)", "BOX(0 0,2 2)", true, true);
63 test_box_of<Point>("POINT(0 0)", "BOX(0 0,2 2)", false, true);
64 test_box_of<Point>("POINT(2 2)", "BOX(0 0,2 2)", false, true);
65 test_box_of<Point>("POINT(0 1)", "BOX(0 0,2 2)", false, true);
66 test_box_of<Point>("POINT(1 0)", "BOX(0 0,2 2)", false, true);
67 test_box_of<Point>("POINT(3 3)", "BOX(0 0,2 2)", false, false);
68 }
69
70
71 int test_main(int, char* [])
72 {
73 test_box<bg::model::point<float, 2, bg::cs::cartesian> >();
74 test_box<bg::model::point<double, 2, bg::cs::cartesian> >();
75
76 return 0;
77 }