]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | ||
1e59de90 TL |
6 | // This file was modified by Oracle on 2014-2020. |
7 | // Modifications copyright (c) 2014-2020 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 | ||
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; | |
1e59de90 | 24 | |
7c673cae FG |
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 | ||
1e59de90 TL |
35 | // Also test with the non-default side version |
36 | bg::strategy::within::cartesian_point_box_by_side<> within_strategy; | |
37 | bg::strategy::covered_by::cartesian_point_box_by_side<> covered_by_strategy; | |
7c673cae FG |
38 | |
39 | detected_within = bg::within(point, box, within_strategy); | |
40 | detected_covered_by = bg::covered_by(point, box, covered_by_strategy); | |
41 | BOOST_CHECK_EQUAL(detected_within, expected_within); | |
42 | BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); | |
43 | ||
1e59de90 TL |
44 | // BREAKING CHANGE: |
45 | // Internally the strategies are converted to umbrella strategy | |
46 | // and then the umbrella strategy is used to get correct strategy | |
47 | // for corresponding algorithm. | |
48 | // PREVIOUSLY: | |
7c673cae FG |
49 | // We might exchange strategies between within/covered by. |
50 | // So the lines below might seem confusing, but are as intended | |
1e59de90 TL |
51 | //detected_within = bg::covered_by(point, box, within_strategy); |
52 | //detected_covered_by = bg::within(point, box, covered_by_strategy); | |
53 | //BOOST_CHECK_EQUAL(detected_within, expected_within); | |
54 | //BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); | |
7c673cae FG |
55 | |
56 | // Finally we call the strategies directly | |
57 | detected_within = within_strategy.apply(point, box); | |
58 | detected_covered_by = covered_by_strategy.apply(point, box); | |
59 | BOOST_CHECK_EQUAL(detected_within, expected_within); | |
60 | BOOST_CHECK_EQUAL(detected_covered_by, expected_covered_by); | |
61 | } | |
62 | ||
63 | template <typename Point> | |
64 | void test_box() | |
65 | { | |
66 | test_box_of<Point>("POINT(1 1)", "BOX(0 0,2 2)", true, true); | |
67 | test_box_of<Point>("POINT(0 0)", "BOX(0 0,2 2)", false, true); | |
68 | test_box_of<Point>("POINT(2 2)", "BOX(0 0,2 2)", false, true); | |
69 | test_box_of<Point>("POINT(0 1)", "BOX(0 0,2 2)", false, true); | |
70 | test_box_of<Point>("POINT(1 0)", "BOX(0 0,2 2)", false, true); | |
71 | test_box_of<Point>("POINT(3 3)", "BOX(0 0,2 2)", false, false); | |
72 | } | |
73 | ||
74 | ||
75 | int test_main(int, char* []) | |
76 | { | |
77 | test_box<bg::model::point<float, 2, bg::cs::cartesian> >(); | |
78 | test_box<bg::model::point<double, 2, bg::cs::cartesian> >(); | |
79 | ||
7c673cae FG |
80 | return 0; |
81 | } |