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_XY_HPP
15#define BOOST_GEOMETRY_GEOMETRIES_POINT_XY_HPP
16
17#include <cstddef>
18
19#include <boost/config.hpp>
20#include <boost/mpl/int.hpp>
21
22#include <boost/geometry/core/cs.hpp>
23#include <boost/geometry/geometries/point.hpp>
24
25namespace boost { namespace geometry
26{
27
28namespace model { namespace d2
29{
30
31/*!
32\brief 2D point in Cartesian coordinate system
33\tparam CoordinateType numeric type, for example, double, float, int
34\tparam CoordinateSystem coordinate system, defaults to cs::cartesian
35
36\qbk{[include reference/geometries/point_xy.qbk]}
37\qbk{before.synopsis,
38[heading Model of]
39[link geometry.reference.concepts.concept_point Point Concept]
40}
41
42\qbk{[include reference/geometries/point_assign_warning.qbk]}
43
44*/
45template<typename CoordinateType, typename CoordinateSystem = cs::cartesian>
46class point_xy : public model::point<CoordinateType, 2, CoordinateSystem>
47{
48public:
49
50#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
51 /// \constructor_default_no_init
52 point_xy() = default;
53#else
54 /// \constructor_default_no_init
55 inline point_xy()
56 {}
57#endif
58
59 /// Constructor with x/y values
60 inline point_xy(CoordinateType const& x, CoordinateType const& y)
61 : model::point<CoordinateType, 2, CoordinateSystem>(x, y)
62 {}
63
64 /// Get x-value
65 inline CoordinateType const& x() const
66 { return this->template get<0>(); }
67
68 /// Get y-value
69 inline CoordinateType const& y() const
70 { return this->template get<1>(); }
71
72 /// Set x-value
73 inline void x(CoordinateType const& v)
74 { this->template set<0>(v); }
75
76 /// Set y-value
77 inline void y(CoordinateType const& v)
78 { this->template set<1>(v); }
79};
80
81
82}} // namespace model::d2
83
84
85// Adapt the point_xy to the concept
86#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
87namespace traits
88{
89
90template <typename CoordinateType, typename CoordinateSystem>
91struct tag<model::d2::point_xy<CoordinateType, CoordinateSystem> >
92{
93 typedef point_tag type;
94};
95
96template<typename CoordinateType, typename CoordinateSystem>
97struct coordinate_type<model::d2::point_xy<CoordinateType, CoordinateSystem> >
98{
99 typedef CoordinateType type;
100};
101
102template<typename CoordinateType, typename CoordinateSystem>
103struct coordinate_system<model::d2::point_xy<CoordinateType, CoordinateSystem> >
104{
105 typedef CoordinateSystem type;
106};
107
108template<typename CoordinateType, typename CoordinateSystem>
109struct dimension<model::d2::point_xy<CoordinateType, CoordinateSystem> >
110 : boost::mpl::int_<2>
111{};
112
113template<typename CoordinateType, typename CoordinateSystem, std::size_t Dimension>
114struct access<model::d2::point_xy<CoordinateType, CoordinateSystem>, Dimension >
115{
116 static inline CoordinateType get(
117 model::d2::point_xy<CoordinateType, CoordinateSystem> const& p)
118 {
119 return p.template get<Dimension>();
120 }
121
122 static inline void set(model::d2::point_xy<CoordinateType, CoordinateSystem>& p,
123 CoordinateType const& value)
124 {
125 p.template set<Dimension>(value);
126 }
127};
128
129} // namespace traits
130#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
131
132}} // namespace boost::geometry
133
134#endif // BOOST_GEOMETRY_GEOMETRIES_POINT_XY_HPP
135

source code of boost/boost/geometry/geometries/point_xy.hpp