1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | |
3 | // Copyright (c) 2014, Oracle and/or its affiliates. |
4 | |
5 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle |
6 | |
7 | // Licensed under the Boost Software License version 1.0. |
8 | // http://www.boost.org/users/license.html |
9 | |
10 | #ifndef BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP |
11 | #define BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP |
12 | |
13 | #include <cstddef> |
14 | |
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> |
19 | |
20 | #include <boost/geometry/core/access.hpp> |
21 | #include <boost/geometry/core/assert.hpp> |
22 | #include <boost/geometry/core/coordinate_type.hpp> |
23 | |
24 | #include <boost/geometry/geometries/concepts/point_concept.hpp> |
25 | |
26 | namespace boost { namespace geometry |
27 | { |
28 | |
29 | namespace model |
30 | { |
31 | |
32 | // const or non-const segment type that is meant to be |
33 | // * default constructible |
34 | // * copy constructible |
35 | // * assignable |
36 | // referring_segment does not fit these requirements, hence the |
37 | // pointing_segment class |
38 | // |
39 | // this class is used by the segment_iterator as its value type |
40 | template <typename ConstOrNonConstPoint> |
41 | class pointing_segment |
42 | { |
43 | BOOST_CONCEPT_ASSERT( ( |
44 | typename boost::mpl::if_ |
45 | < |
46 | boost::is_const<ConstOrNonConstPoint>, |
47 | concept::Point<ConstOrNonConstPoint>, |
48 | concept::ConstPoint<ConstOrNonConstPoint> |
49 | > |
50 | ) ); |
51 | |
52 | typedef ConstOrNonConstPoint point_type; |
53 | |
54 | public: |
55 | point_type* first; |
56 | point_type* second; |
57 | |
58 | inline pointing_segment() |
59 | : first(NULL) |
60 | , second(NULL) |
61 | {} |
62 | |
63 | inline pointing_segment(point_type const& p1, point_type const& p2) |
64 | : first(boost::addressof(p1)) |
65 | , second(boost::addressof(p2)) |
66 | {} |
67 | }; |
68 | |
69 | |
70 | } // namespace model |
71 | |
72 | |
73 | // Traits specializations for segment above |
74 | #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS |
75 | namespace traits |
76 | { |
77 | |
78 | template <typename Point> |
79 | struct tag<model::pointing_segment<Point> > |
80 | { |
81 | typedef segment_tag type; |
82 | }; |
83 | |
84 | template <typename Point> |
85 | struct point_type<model::pointing_segment<Point> > |
86 | { |
87 | typedef Point type; |
88 | }; |
89 | |
90 | template <typename Point, std::size_t Dimension> |
91 | struct indexed_access<model::pointing_segment<Point>, 0, Dimension> |
92 | { |
93 | typedef model::pointing_segment<Point> segment_type; |
94 | typedef typename geometry::coordinate_type |
95 | < |
96 | segment_type |
97 | >::type coordinate_type; |
98 | |
99 | static inline coordinate_type get(segment_type const& s) |
100 | { |
101 | BOOST_GEOMETRY_ASSERT( s.first != NULL ); |
102 | return geometry::get<Dimension>(*s.first); |
103 | } |
104 | |
105 | static inline void set(segment_type& s, coordinate_type const& value) |
106 | { |
107 | BOOST_GEOMETRY_ASSERT( s.first != NULL ); |
108 | geometry::set<Dimension>(*s.first, value); |
109 | } |
110 | }; |
111 | |
112 | |
113 | template <typename Point, std::size_t Dimension> |
114 | struct indexed_access<model::pointing_segment<Point>, 1, Dimension> |
115 | { |
116 | typedef model::pointing_segment<Point> segment_type; |
117 | typedef typename geometry::coordinate_type |
118 | < |
119 | segment_type |
120 | >::type coordinate_type; |
121 | |
122 | static inline coordinate_type get(segment_type const& s) |
123 | { |
124 | BOOST_GEOMETRY_ASSERT( s.second != NULL ); |
125 | return geometry::get<Dimension>(*s.second); |
126 | } |
127 | |
128 | static inline void set(segment_type& s, coordinate_type const& value) |
129 | { |
130 | BOOST_GEOMETRY_ASSERT( s.second != NULL ); |
131 | geometry::set<Dimension>(*s.second, value); |
132 | } |
133 | }; |
134 | |
135 | |
136 | |
137 | } // namespace traits |
138 | #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS |
139 | |
140 | }} // namespace boost::geometry |
141 | |
142 | #endif // BOOST_GEOMETRY_GEOMETRIES_POINTING_SEGMENT_HPP |
143 | |