1 | // Boost.Geometry |
2 | |
3 | // Copyright (c) 2021-2023, Oracle and/or its affiliates. |
4 | |
5 | // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle |
6 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7 | |
8 | // Licensed under the Boost Software License version 1.0. |
9 | // http://www.boost.org/users/license.html |
10 | |
11 | |
12 | #include <geometry_test_common.hpp> |
13 | |
14 | #include <boost/geometry/algorithms/assign.hpp> |
15 | |
16 | #include <boost/geometry/arithmetic/arithmetic.hpp> |
17 | |
18 | #include <boost/geometry/core/cs.hpp> |
19 | |
20 | #include <boost/geometry/geometries/point.hpp> |
21 | |
22 | #include <boost/geometry/util/algorithm.hpp> |
23 | |
24 | |
25 | void test_dimension(bg::util::index_constant<0>) |
26 | { |
27 | bool called = false; |
28 | bg::detail::for_each_index<0>(function: [&](auto) { called = true; }); |
29 | BOOST_CHECK(!called); |
30 | BOOST_CHECK(bg::detail::all_indexes_of<0>([&](auto) { return true; }) == true); |
31 | BOOST_CHECK(bg::detail::all_indexes_of<0>([&](auto) { return false; }) == true); |
32 | BOOST_CHECK(bg::detail::any_index_of<0>([&](auto) { return true; }) == false); |
33 | BOOST_CHECK(bg::detail::any_index_of<0>([&](auto) { return false; }) == false); |
34 | BOOST_CHECK(bg::detail::none_index_of<0>([&](auto) { return true; }) == true); |
35 | BOOST_CHECK(bg::detail::none_index_of<0>([&](auto) { return false; }) == true); |
36 | } |
37 | |
38 | template <std::size_t I> |
39 | void test_dimension(bg::util::index_constant<I>) |
40 | { |
41 | using point = bg::model::point<double, I, bg::cs::cartesian>; |
42 | point p; |
43 | bg::assign_value(p, 10.0); |
44 | |
45 | bg::detail::for_each_index<I>([&](auto index) |
46 | { |
47 | BOOST_CHECK(bg::get<index>(p) == 10.0); |
48 | bg::set<index>(p, double(index)); |
49 | }); |
50 | bg::detail::for_each_dimension<point>([&](auto index) |
51 | { |
52 | BOOST_CHECK(bg::get<index>(p) == double(index)); |
53 | }); |
54 | |
55 | BOOST_CHECK( |
56 | bg::detail::all_indexes_of<0>([&](auto index) |
57 | { |
58 | return bg::get<index>(p) == double(index); |
59 | }) == true); |
60 | BOOST_CHECK( |
61 | bg::detail::all_dimensions_of<point>([&](auto index) |
62 | { |
63 | return bg::get<index>(p) == 10; |
64 | }) == false); |
65 | BOOST_CHECK( |
66 | bg::detail::any_index_of<0>([&](auto) |
67 | { |
68 | return false; |
69 | }) == false); |
70 | BOOST_CHECK( |
71 | bg::detail::any_dimension_of<point>([&](auto index) |
72 | { |
73 | return bg::get<index>(p) == double(I - 1); |
74 | }) == true); |
75 | BOOST_CHECK( |
76 | bg::detail::none_index_of<0>([&](auto) |
77 | { |
78 | return false; |
79 | }) == true); |
80 | BOOST_CHECK( |
81 | bg::detail::none_dimension_of<point>([&](auto index) |
82 | { |
83 | return bg::get<index>(p) == double(0); |
84 | }) == false); |
85 | } |
86 | |
87 | template <std::size_t I, std::size_t N> |
88 | struct test_dimensions |
89 | { |
90 | static void apply() |
91 | { |
92 | test_dimension(bg::util::index_constant<I>()); |
93 | test_dimensions<I + 1, N>::apply(); |
94 | } |
95 | }; |
96 | |
97 | template <std::size_t N> |
98 | struct test_dimensions<N, N> |
99 | { |
100 | static void apply() {} |
101 | }; |
102 | |
103 | int test_main(int, char* []) |
104 | { |
105 | test_dimensions<0, 5>::apply(); |
106 | |
107 | return 0; |
108 | } |
109 | |