File indexing completed on 2025-01-18 09:35:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP
0019 #define BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP
0020
0021 #include <cstddef>
0022 #include <utility>
0023 #include <type_traits>
0024
0025 #include <boost/concept/assert.hpp>
0026
0027 #include <boost/geometry/core/access.hpp>
0028 #include <boost/geometry/core/make.hpp>
0029 #include <boost/geometry/core/point_type.hpp>
0030 #include <boost/geometry/core/tag.hpp>
0031 #include <boost/geometry/core/tags.hpp>
0032
0033 #include <boost/geometry/geometries/concepts/point_concept.hpp>
0034
0035 namespace boost { namespace geometry
0036 {
0037
0038 namespace model
0039 {
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 template<typename Point>
0056 class segment : public std::pair<Point, Point>
0057 {
0058 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0059
0060 public :
0061
0062
0063 constexpr segment() = default;
0064
0065
0066
0067
0068 constexpr segment(Point const& p1, Point const& p2)
0069 : std::pair<Point, Point>(p1, p2)
0070 {}
0071 };
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 template<typename ConstOrNonConstPoint>
0088 class referring_segment
0089 {
0090 BOOST_CONCEPT_ASSERT( (
0091 typename std::conditional
0092 <
0093 std::is_const<ConstOrNonConstPoint>::value,
0094 concepts::Point<ConstOrNonConstPoint>,
0095 concepts::ConstPoint<ConstOrNonConstPoint>
0096 >
0097 ) );
0098
0099 typedef ConstOrNonConstPoint point_type;
0100
0101 public:
0102
0103 point_type& first;
0104 point_type& second;
0105
0106
0107
0108
0109 inline referring_segment(point_type& p1, point_type& p2)
0110 : first(p1)
0111 , second(p2)
0112 {}
0113 };
0114
0115
0116 }
0117
0118
0119
0120 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0121 namespace traits
0122 {
0123
0124 template <typename Point>
0125 struct tag<model::segment<Point> >
0126 {
0127 typedef segment_tag type;
0128 };
0129
0130 template <typename Point>
0131 struct point_type<model::segment<Point> >
0132 {
0133 typedef Point type;
0134 };
0135
0136 template <typename Point, std::size_t Dimension>
0137 struct indexed_access<model::segment<Point>, 0, Dimension>
0138 {
0139 typedef model::segment<Point> segment_type;
0140 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
0141
0142 static constexpr coordinate_type get(segment_type const& s)
0143 {
0144 return geometry::get<Dimension>(s.first);
0145 }
0146
0147 static void set(segment_type& s, coordinate_type const& value)
0148 {
0149 geometry::set<Dimension>(s.first, value);
0150 }
0151 };
0152
0153
0154 template <typename Point, std::size_t Dimension>
0155 struct indexed_access<model::segment<Point>, 1, Dimension>
0156 {
0157 typedef model::segment<Point> segment_type;
0158 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
0159
0160 static constexpr coordinate_type get(segment_type const& s)
0161 {
0162 return geometry::get<Dimension>(s.second);
0163 }
0164
0165 static void set(segment_type& s, coordinate_type const& value)
0166 {
0167 geometry::set<Dimension>(s.second, value);
0168 }
0169 };
0170
0171
0172 template <typename Point>
0173 struct make<model::segment<Point> >
0174 {
0175 typedef model::segment<Point> segment_type;
0176
0177 static const bool is_specialized = true;
0178
0179 static constexpr segment_type apply(Point const& p1, Point const& p2)
0180 {
0181 return segment_type(p1, p2);
0182 }
0183 };
0184
0185
0186
0187 template <typename ConstOrNonConstPoint>
0188 struct tag<model::referring_segment<ConstOrNonConstPoint> >
0189 {
0190 typedef segment_tag type;
0191 };
0192
0193 template <typename ConstOrNonConstPoint>
0194 struct point_type<model::referring_segment<ConstOrNonConstPoint> >
0195 {
0196 typedef ConstOrNonConstPoint type;
0197 };
0198
0199 template <typename ConstOrNonConstPoint, std::size_t Dimension>
0200 struct indexed_access<model::referring_segment<ConstOrNonConstPoint>, 0, Dimension>
0201 {
0202 typedef model::referring_segment<ConstOrNonConstPoint> segment_type;
0203 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
0204
0205 static inline coordinate_type get(segment_type const& s)
0206 {
0207 return geometry::get<Dimension>(s.first);
0208 }
0209
0210 static inline void set(segment_type& s, coordinate_type const& value)
0211 {
0212 geometry::set<Dimension>(s.first, value);
0213 }
0214 };
0215
0216
0217 template <typename ConstOrNonConstPoint, std::size_t Dimension>
0218 struct indexed_access<model::referring_segment<ConstOrNonConstPoint>, 1, Dimension>
0219 {
0220 typedef model::referring_segment<ConstOrNonConstPoint> segment_type;
0221 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
0222
0223 static inline coordinate_type get(segment_type const& s)
0224 {
0225 return geometry::get<Dimension>(s.second);
0226 }
0227
0228 static inline void set(segment_type& s, coordinate_type const& value)
0229 {
0230 geometry::set<Dimension>(s.second, value);
0231 }
0232 };
0233
0234
0235
0236 }
0237 #endif
0238
0239 }}
0240
0241 #endif