1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
14 #ifndef BOOST_GEOMETRY_GEOMETRIES_POINT_HPP
15 #define BOOST_GEOMETRY_GEOMETRIES_POINT_HPP
19 #include <boost/mpl/int.hpp>
20 #include <boost/static_assert.hpp>
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>
28 namespace boost { namespace geometry
31 // Silence warning C4127: conditional expression is constant
34 #pragma warning(disable : 4127)
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.
49 \tparam CoordinateType \tparam_numeric
50 \tparam DimensionCount number of coordinates, usually 2 or 3
51 \tparam CoordinateSystem coordinate system, for example cs::cartesian
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]}
61 typename CoordinateType,
62 std::size_t DimensionCount,
63 typename CoordinateSystem
69 /// @brief Default constructor, no initialization
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)
76 if (DimensionCount >= 1) m_values[0] = v0;
77 if (DimensionCount >= 2) m_values[1] = v1;
78 if (DimensionCount >= 3) m_values[2] = v2;
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
87 BOOST_STATIC_ASSERT(K < DimensionCount);
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)
97 BOOST_STATIC_ASSERT(K < DimensionCount);
103 CoordinateType m_values[DimensionCount];
109 // Adapt the point to the concept
110 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
115 typename CoordinateType,
116 std::size_t DimensionCount,
117 typename CoordinateSystem
119 struct tag<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
121 typedef point_tag type;
126 typename CoordinateType,
127 std::size_t DimensionCount,
128 typename CoordinateSystem
130 struct coordinate_type<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
132 typedef CoordinateType type;
137 typename CoordinateType,
138 std::size_t DimensionCount,
139 typename CoordinateSystem
141 struct coordinate_system<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
143 typedef CoordinateSystem type;
148 typename CoordinateType,
149 std::size_t DimensionCount,
150 typename CoordinateSystem
152 struct dimension<model::point<CoordinateType, DimensionCount, CoordinateSystem> >
153 : boost::mpl::int_<DimensionCount>
158 typename CoordinateType,
159 std::size_t DimensionCount,
160 typename CoordinateSystem,
161 std::size_t Dimension
163 struct access<model::point<CoordinateType, DimensionCount, CoordinateSystem>, Dimension>
165 static inline CoordinateType get(
166 model::point<CoordinateType, DimensionCount, CoordinateSystem> const& p)
168 return p.template get<Dimension>();
171 static inline void set(
172 model::point<CoordinateType, DimensionCount, CoordinateSystem>& p,
173 CoordinateType const& value)
175 p.template set<Dimension>(value);
179 } // namespace traits
180 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
182 #if defined(_MSC_VER)
186 }} // namespace boost::geometry
188 #endif // BOOST_GEOMETRY_GEOMETRIES_POINT_HPP