1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #ifndef BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP
11 #define BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP
15 #include <boost/concept/assert.hpp>
16 #include <boost/core/addressof.hpp>
17 #include <boost/mpl/if.hpp>
18 #include <boost/type_traits/is_const.hpp>
20 #include <boost/geometry/core/access.hpp>
21 #include <boost/geometry/core/assert.hpp>
22 #include <boost/geometry/core/coordinate_type.hpp>
24 #include <boost/geometry/geometries/concepts/point_concept.hpp>
26 namespace boost { namespace geometry
32 // const or non-const segment type that is meant to be
33 // * default constructible
34 // * copy constructible
36 // referring_segment does not fit these requirements, hence the
37 // pointing_segment class
39 // this class is used by the segment_iterator as its value type
40 template <typename ConstOrNonConstPoint>
41 class pointing_segment
43 BOOST_CONCEPT_ASSERT( (
44 typename boost::mpl::if_
46 boost::is_const<ConstOrNonConstPoint>,
47 concepts::Point<ConstOrNonConstPoint>,
48 concepts::ConstPoint<ConstOrNonConstPoint>
52 typedef ConstOrNonConstPoint point_type;
58 inline pointing_segment()
63 inline pointing_segment(point_type const& p1, point_type const& p2)
64 : first(boost::addressof(p1))
65 , second(boost::addressof(p2))
73 // Traits specializations for segment above
74 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
78 template <typename Point>
79 struct tag<model::pointing_segment<Point> >
81 typedef segment_tag type;
84 template <typename Point>
85 struct point_type<model::pointing_segment<Point> >
90 template <typename Point, std::size_t Dimension>
91 struct indexed_access<model::pointing_segment<Point>, 0, Dimension>
93 typedef model::pointing_segment<Point> segment_type;
94 typedef typename geometry::coordinate_type
97 >::type coordinate_type;
99 static inline coordinate_type get(segment_type const& s)
101 BOOST_GEOMETRY_ASSERT( s.first != NULL );
102 return geometry::get<Dimension>(*s.first);
105 static inline void set(segment_type& s, coordinate_type const& value)
107 BOOST_GEOMETRY_ASSERT( s.first != NULL );
108 geometry::set<Dimension>(*s.first, value);
113 template <typename Point, std::size_t Dimension>
114 struct indexed_access<model::pointing_segment<Point>, 1, Dimension>
116 typedef model::pointing_segment<Point> segment_type;
117 typedef typename geometry::coordinate_type
120 >::type coordinate_type;
122 static inline coordinate_type get(segment_type const& s)
124 BOOST_GEOMETRY_ASSERT( s.second != NULL );
125 return geometry::get<Dimension>(*s.second);
128 static inline void set(segment_type& s, coordinate_type const& value)
130 BOOST_GEOMETRY_ASSERT( s.second != NULL );
131 geometry::set<Dimension>(*s.second, value);
137 } // namespace traits
138 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
140 }} // namespace boost::geometry
142 #endif // BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP