]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // | |
3 | // Copyright (c) 2008-2014 Bruno Lalande, Paris, France. | |
4 | // Copyright (c) 2008-2014 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | // Copyright (c) 2009-2014 Mateusz Loskot, London, UK. | |
6 | ||
1e59de90 TL |
7 | // This file was modified by Oracle on 2014-2021. |
8 | // Modifications copyright (c) 2014-2021, Oracle and/or its affiliates. | |
7c673cae FG |
9 | |
10 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
20effc67 | 11 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7c673cae FG |
12 | |
13 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library | |
14 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
15 | ||
16 | // Use, modification and distribution is subject to the Boost Software License, | |
17 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
18 | // http://www.boost.org/LICENSE_1_0.txt) | |
19 | ||
20 | #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP | |
21 | #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP | |
22 | ||
23 | #include <cstddef> | |
24 | ||
25 | #include <boost/concept_check.hpp> | |
26 | #include <boost/core/ignore_unused.hpp> | |
27 | ||
28 | #include <boost/geometry/core/access.hpp> | |
29 | #include <boost/geometry/core/coordinate_dimension.hpp> | |
30 | #include <boost/geometry/core/coordinate_system.hpp> | |
31 | ||
1e59de90 | 32 | #include <boost/geometry/geometries/concepts/concept_type.hpp> |
7c673cae FG |
33 | |
34 | ||
35 | namespace boost { namespace geometry { namespace concepts | |
36 | { | |
37 | ||
38 | /*! | |
39 | \brief Point concept. | |
40 | \ingroup concepts | |
41 | ||
42 | \par Formal definition: | |
43 | The point concept is defined as following: | |
44 | - there must be a specialization of traits::tag defining point_tag as type | |
45 | - there must be a specialization of traits::coordinate_type defining the type | |
46 | of its coordinates | |
47 | - there must be a specialization of traits::coordinate_system defining its | |
48 | coordinate system (cartesian, spherical, etc) | |
49 | - there must be a specialization of traits::dimension defining its number | |
50 | of dimensions (2, 3, ...) (derive it conveniently | |
20effc67 | 51 | from std::integral_constant<std::size_t, X> for X-D) |
7c673cae FG |
52 | - there must be a specialization of traits::access, per dimension, |
53 | with two functions: | |
54 | - \b get to get a coordinate value | |
55 | - \b set to set a coordinate value (this one is not checked for ConstPoint) | |
56 | - for non-Cartesian coordinate systems, the coordinate system's units | |
57 | must either be boost::geometry::degree or boost::geometry::radian | |
58 | ||
59 | ||
60 | \par Example: | |
61 | ||
62 | A legacy point, defining the necessary specializations to fulfil to the concept. | |
63 | ||
64 | Suppose that the following point is defined: | |
65 | \dontinclude doxygen_5.cpp | |
66 | \skip legacy_point1 | |
67 | \until }; | |
68 | ||
69 | It can then be adapted to the concept as following: | |
70 | \dontinclude doxygen_5.cpp | |
71 | \skip adapt legacy_point1 | |
72 | \until }} | |
73 | ||
74 | Note that it is done like above to show the system. Users will normally use the registration macro. | |
75 | ||
76 | \par Example: | |
77 | ||
78 | A read-only legacy point, using a macro to fulfil to the ConstPoint concept. | |
79 | It cannot be modified by the library but can be used in all algorithms where | |
80 | points are not modified. | |
81 | ||
82 | The point looks like the following: | |
83 | ||
84 | \dontinclude doxygen_5.cpp | |
85 | \skip legacy_point2 | |
86 | \until }; | |
87 | ||
88 | It uses the macro as following: | |
89 | \dontinclude doxygen_5.cpp | |
90 | \skip adapt legacy_point2 | |
91 | \until end adaptation | |
92 | ||
93 | */ | |
94 | ||
95 | template <typename Geometry> | |
96 | class Point | |
97 | { | |
98 | #ifndef DOXYGEN_NO_CONCEPT_MEMBERS | |
99 | ||
100 | typedef typename coordinate_type<Geometry>::type ctype; | |
101 | typedef typename coordinate_system<Geometry>::type csystem; | |
102 | ||
103 | // The following enum is used to fully instantiate the coordinate | |
104 | // system class; this is needed in order to check the units passed | |
105 | // to it for non-Cartesian coordinate systems. | |
106 | enum { cs_check = sizeof(csystem) }; | |
107 | ||
108 | enum { ccount = dimension<Geometry>::value }; | |
109 | ||
110 | template <typename P, std::size_t Dimension, std::size_t DimensionCount> | |
111 | struct dimension_checker | |
112 | { | |
113 | static void apply() | |
114 | { | |
115 | P* p = 0; | |
116 | geometry::set<Dimension>(*p, geometry::get<Dimension>(*p)); | |
117 | dimension_checker<P, Dimension+1, DimensionCount>::apply(); | |
118 | } | |
119 | }; | |
120 | ||
121 | ||
122 | template <typename P, std::size_t DimensionCount> | |
123 | struct dimension_checker<P, DimensionCount, DimensionCount> | |
124 | { | |
125 | static void apply() {} | |
126 | }; | |
127 | ||
128 | public: | |
129 | ||
130 | /// BCCL macro to apply the Point concept | |
131 | BOOST_CONCEPT_USAGE(Point) | |
132 | { | |
133 | dimension_checker<Geometry, 0, ccount>::apply(); | |
134 | } | |
135 | #endif | |
136 | }; | |
137 | ||
138 | ||
139 | /*! | |
140 | \brief point concept (const version). | |
141 | ||
142 | \ingroup const_concepts | |
143 | ||
144 | \details The ConstPoint concept apply the same as the Point concept, | |
145 | but does not apply write access. | |
146 | ||
147 | */ | |
148 | template <typename Geometry> | |
149 | class ConstPoint | |
150 | { | |
151 | #ifndef DOXYGEN_NO_CONCEPT_MEMBERS | |
152 | ||
153 | typedef typename coordinate_type<Geometry>::type ctype; | |
154 | typedef typename coordinate_system<Geometry>::type csystem; | |
155 | ||
156 | // The following enum is used to fully instantiate the coordinate | |
157 | // system class; this is needed in order to check the units passed | |
158 | // to it for non-Cartesian coordinate systems. | |
159 | enum { cs_check = sizeof(csystem) }; | |
160 | ||
161 | enum { ccount = dimension<Geometry>::value }; | |
162 | ||
163 | template <typename P, std::size_t Dimension, std::size_t DimensionCount> | |
164 | struct dimension_checker | |
165 | { | |
166 | static void apply() | |
167 | { | |
168 | const P* p = 0; | |
169 | ctype coord(geometry::get<Dimension>(*p)); | |
170 | boost::ignore_unused(p, coord); | |
171 | dimension_checker<P, Dimension+1, DimensionCount>::apply(); | |
172 | } | |
173 | }; | |
174 | ||
175 | ||
176 | template <typename P, std::size_t DimensionCount> | |
177 | struct dimension_checker<P, DimensionCount, DimensionCount> | |
178 | { | |
179 | static void apply() {} | |
180 | }; | |
181 | ||
182 | public: | |
183 | ||
184 | /// BCCL macro to apply the ConstPoint concept | |
185 | BOOST_CONCEPT_USAGE(ConstPoint) | |
186 | { | |
187 | dimension_checker<Geometry, 0, ccount>::apply(); | |
188 | } | |
189 | #endif | |
190 | }; | |
191 | ||
1e59de90 TL |
192 | |
193 | template <typename Geometry> | |
194 | struct concept_type<Geometry, point_tag> | |
195 | { | |
196 | using type = Point<Geometry>; | |
197 | }; | |
198 | ||
199 | template <typename Geometry> | |
200 | struct concept_type<Geometry const, point_tag> | |
201 | { | |
202 | using type = ConstPoint<Geometry>; | |
203 | }; | |
204 | ||
205 | ||
7c673cae FG |
206 | }}} // namespace boost::geometry::concepts |
207 | ||
208 | #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_POINT_CONCEPT_HPP |