Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / geometry / geometries / point.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #ifndef BOOST_GEOMETRY_GEOMETRIES_POINT_HPP
15 #define BOOST_GEOMETRY_GEOMETRIES_POINT_HPP
16
17 #include <cstddef>
18
19 #include <boost/mpl/int.hpp>
20 #include <boost/static_assert.hpp>
21
22 #include <boost/geometry/core/access.hpp>
23 #include <boost/geometry/core/coordinate_type.hpp>
24 #include <boost/geometry/core/coordinate_system.hpp>
25 #include <boost/geometry/core/coordinate_dimension.hpp>
26 #include <boost/geometry/util/math.hpp>
27
28 namespace boost { namespace geometry
29 {
30
31 // Silence warning C4127: conditional expression is constant
32 #if defined(_MSC_VER)
33 #pragma warning(push)
34 #pragma warning(disable : 4127)
35 #endif
36
37
38 namespace model
39 {
40
41 /*!
42 \brief Basic point class, having coordinates defined in a neutral way
43 \details Defines a neutral point class, fulfilling the Point Concept.
44     Library users can use this point class, or use their own point classes.
45     This point class is used in most of the samples and tests of Boost.Geometry
46     This point class is used occasionally within the library, where a temporary
47     point class is necessary.
48 \ingroup geometries
49 \tparam CoordinateType \tparam_numeric
50 \tparam DimensionCount number of coordinates, usually 2 or 3
51 \tparam CoordinateSystem coordinate system, for example cs::cartesian
52
53 \qbk{[include reference/geometries/point.qbk]}
54 \qbk{before.synopsis, [heading Model of]}
55 \qbk{before.synopsis, [link geometry.reference.concepts.concept_point Point Concept]}
56
57
58 */
59 template
60 <
61     typename CoordinateType,
62     std::size_t DimensionCount,
63     typename CoordinateSystem
64 >
65 class point
66 {
67 public:
68
69     /// @brief Default constructor, no initialization
70     inline point()
71     {}
72
73     /// @brief Constructor to set one, two or three values
74     explicit inline point(CoordinateType const& v0, CoordinateType const& v1 = 0, CoordinateType const& v2 = 0)
75     {
76         if (DimensionCount >= 1) m_values[0] = v0;
77         if (DimensionCount >= 2) m_values[1] = v1;
78         if (DimensionCount >= 3) m_values[2] = v2;
79     }
80
81     /// @brief Get a coordinate
82     /// @tparam K coordinate to get
83     /// @return the coordinate
84     template <std::size_t K>
85     inline CoordinateType const& get() const
86     {
87         BOOST_STATIC_ASSERT(K < DimensionCount);
88         return m_values[K];
89     }
90
91     /// @brief Set a coordinate
92     /// @tparam K coordinate to set
93     /// @param value value to set
94     template <std::size_t K>
95     inline void set(CoordinateType const& value)
96     {
97         BOOST_STATIC_ASSERT(K < DimensionCount);
98         m_values[K] = value;
99     }
100
101 private:
102
103     CoordinateType m_values[DimensionCount];
104 };
105
106
107 } // namespace model
108
109 // Adapt the point to the concept
110 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
111 namespace traits
112 {
113 template
114 <
115     typename CoordinateType,
116     std::size_t DimensionCount,
117     typename CoordinateSystem
118 >
119 struct tag<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
120 {
121     typedef point_tag type;
122 };
123
124 template
125 <
126     typename CoordinateType,
127     std::size_t DimensionCount,
128     typename CoordinateSystem
129 >
130 struct coordinate_type<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
131 {
132     typedef CoordinateType type;
133 };
134
135 template
136 <
137     typename CoordinateType,
138     std::size_t DimensionCount,
139     typename CoordinateSystem
140 >
141 struct coordinate_system<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
142 {
143     typedef CoordinateSystem type;
144 };
145
146 template
147 <
148     typename CoordinateType,
149     std::size_t DimensionCount,
150     typename CoordinateSystem
151 >
152 struct dimension<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
153     : boost::mpl::int_<DimensionCount>
154 {};
155
156 template
157 <
158     typename CoordinateType,
159     std::size_t DimensionCount,
160     typename CoordinateSystem,
161     std::size_t Dimension
162 >
163 struct access<model::point<CoordinateType, DimensionCount, CoordinateSystem>, Dimension>
164 {
165     static inline CoordinateType get(
166         model::point<CoordinateType, DimensionCount, CoordinateSystem> const& p)
167     {
168         return p.template get<Dimension>();
169     }
170
171     static inline void set(
172         model::point<CoordinateType, DimensionCount, CoordinateSystem>& p,
173         CoordinateType const& value)
174     {
175         p.template set<Dimension>(value);
176     }
177 };
178
179 } // namespace traits
180 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
181
182 #if defined(_MSC_VER)
183 #pragma warning(pop)
184 #endif
185
186 }} // namespace boost::geometry
187
188 #endif // BOOST_GEOMETRY_GEOMETRIES_POINT_HPP