]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
20effc67 | 3 | // Copyright (c) 2015-2020, Oracle and/or its affiliates. |
7c673cae FG |
4 | |
5 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
20effc67 | 6 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7c673cae FG |
7 | |
8 | // Licensed under the Boost Software License version 1.0. | |
9 | // http://www.boost.org/users/license.html | |
10 | ||
11 | #ifndef BOOST_GEOMETRY_VIEWS_DETAIL_TWO_DIMENSIONAL_VIEW_HPP | |
12 | #define BOOST_GEOMETRY_VIEWS_DETAIL_TWO_DIMENSIONAL_VIEW_HPP | |
13 | ||
14 | #include <cstddef> | |
15 | ||
7c673cae FG |
16 | #include <boost/geometry/core/access.hpp> |
17 | #include <boost/geometry/core/coordinate_type.hpp> | |
18 | #include <boost/geometry/core/coordinate_system.hpp> | |
19 | #include <boost/geometry/core/coordinate_dimension.hpp> | |
20 | #include <boost/geometry/core/point_type.hpp> | |
20effc67 | 21 | #include <boost/geometry/core/static_assert.hpp> |
7c673cae FG |
22 | #include <boost/geometry/core/tag.hpp> |
23 | #include <boost/geometry/core/tags.hpp> | |
24 | ||
25 | #include <boost/geometry/algorithms/not_implemented.hpp> | |
26 | ||
27 | ||
28 | namespace boost { namespace geometry | |
29 | { | |
30 | ||
31 | #ifndef DOXYGEN_NO_DETAIL | |
32 | namespace detail | |
33 | { | |
34 | ||
35 | template | |
36 | < | |
37 | typename Geometry, | |
38 | std::size_t Dimension1 = 0, | |
39 | std::size_t Dimension2 = 1, | |
40 | typename Tag = typename tag<Geometry>::type | |
41 | > | |
42 | struct two_dimensional_view | |
43 | : not_implemented<Tag> | |
44 | {}; | |
45 | ||
46 | ||
47 | // View that enables to choose two dimensions of a point and see it as | |
48 | // a two-dimensional point | |
49 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
50 | struct two_dimensional_view<Point, Dimension1, Dimension2, point_tag> | |
51 | { | |
20effc67 TL |
52 | BOOST_GEOMETRY_STATIC_ASSERT( |
53 | (Dimension1 < dimension<Point>::value), | |
54 | "Coordinate Dimension1 is larger than Point's dimension.", | |
55 | std::integral_constant<std::size_t, Dimension1>); | |
7c673cae | 56 | |
20effc67 TL |
57 | BOOST_GEOMETRY_STATIC_ASSERT( |
58 | (Dimension2 < dimension<Point>::value), | |
59 | "Coordinate Dimension2 is larger than Point's dimension.", | |
60 | std::integral_constant<std::size_t, Dimension2>); | |
7c673cae FG |
61 | |
62 | two_dimensional_view(Point& point) | |
63 | : m_point(point) | |
64 | {} | |
65 | ||
66 | Point& m_point; | |
67 | }; | |
68 | ||
69 | ||
70 | } // namespace detail | |
71 | #endif // DOXYGEN_NO_DETAIL | |
72 | ||
73 | ||
74 | #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS | |
75 | namespace traits | |
76 | { | |
77 | ||
78 | ||
79 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
80 | struct tag | |
81 | < | |
82 | geometry::detail::two_dimensional_view | |
83 | < | |
84 | Point, Dimension1, Dimension2, point_tag | |
85 | > | |
86 | > | |
87 | { | |
88 | typedef point_tag type; | |
89 | }; | |
90 | ||
91 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
92 | struct coordinate_system | |
93 | < | |
94 | geometry::detail::two_dimensional_view | |
95 | < | |
96 | Point, Dimension1, Dimension2, point_tag | |
97 | > | |
98 | > : coordinate_system<typename geometry::point_type<Point>::type> | |
99 | {}; | |
100 | ||
101 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
102 | struct coordinate_type | |
103 | < | |
104 | geometry::detail::two_dimensional_view | |
105 | < | |
106 | Point, Dimension1, Dimension2, point_tag | |
107 | > | |
108 | > : coordinate_type<typename geometry::point_type<Point>::type> | |
109 | {}; | |
110 | ||
111 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
112 | struct dimension | |
113 | < | |
114 | geometry::detail::two_dimensional_view | |
115 | < | |
116 | Point, Dimension1, Dimension2, point_tag | |
117 | > | |
20effc67 | 118 | > : std::integral_constant<std::size_t, 2> |
7c673cae FG |
119 | {}; |
120 | ||
121 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
122 | struct point_type | |
123 | < | |
124 | geometry::detail::two_dimensional_view | |
125 | < | |
126 | Point, Dimension1, Dimension2, point_tag | |
127 | > | |
128 | > | |
129 | { | |
130 | typedef typename geometry::point_type<Point>::type type; | |
131 | }; | |
132 | ||
133 | ||
134 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
135 | struct access | |
136 | < | |
137 | geometry::detail::two_dimensional_view | |
138 | < | |
139 | Point, Dimension1, Dimension2, point_tag | |
140 | >, | |
141 | 0 | |
142 | > | |
143 | { | |
144 | typedef typename geometry::coordinate_type<Point>::type coordinate_type; | |
145 | typedef geometry::detail::two_dimensional_view | |
146 | < | |
147 | Point, Dimension1, Dimension2, point_tag | |
148 | > view_type; | |
149 | ||
150 | static inline coordinate_type get(view_type const& view) | |
151 | { | |
152 | return geometry::get<Dimension1>(view.m_point); | |
153 | } | |
154 | ||
155 | static inline void set(view_type& view, coordinate_type const& value) | |
156 | { | |
157 | geometry::set<Dimension1>(view.m_point, value); | |
158 | } | |
159 | }; | |
160 | ||
161 | template <typename Point, std::size_t Dimension1, std::size_t Dimension2> | |
162 | struct access | |
163 | < | |
164 | geometry::detail::two_dimensional_view | |
165 | < | |
166 | Point, Dimension1, Dimension2, point_tag | |
167 | >, | |
168 | 1 | |
169 | > | |
170 | { | |
171 | typedef typename geometry::coordinate_type<Point>::type coordinate_type; | |
172 | typedef geometry::detail::two_dimensional_view | |
173 | < | |
174 | Point, Dimension1, Dimension2, point_tag | |
175 | > view_type; | |
176 | ||
177 | static inline coordinate_type get(view_type const& view) | |
178 | { | |
179 | return geometry::get<Dimension2>(view.m_point); | |
180 | } | |
181 | ||
182 | static inline void set(view_type& view, coordinate_type const& value) | |
183 | { | |
184 | geometry::set<Dimension2>(view.m_point, value); | |
185 | } | |
186 | }; | |
187 | ||
188 | ||
189 | } // namespace traits | |
190 | #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS | |
191 | ||
192 | }} // namespace boost::geometry | |
193 | ||
194 | ||
195 | #endif // BOOST_GEOMETRY_VIEWS_DETAIL_TWO_DIMENSIONAL_VIEW_HPP |