123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #ifndef BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP
- #define BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP
- #include <cstddef>
- #include <utility>
- #include <type_traits>
- #include <boost/concept/assert.hpp>
- #include <boost/geometry/core/access.hpp>
- #include <boost/geometry/core/make.hpp>
- #include <boost/geometry/core/point_type.hpp>
- #include <boost/geometry/core/tag.hpp>
- #include <boost/geometry/core/tags.hpp>
- #include <boost/geometry/geometries/concepts/point_concept.hpp>
- namespace boost { namespace geometry
- {
- namespace model
- {
- template<typename Point>
- class segment : public std::pair<Point, Point>
- {
- BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
- public :
-
- constexpr segment() = default;
-
- constexpr segment(Point const& p1, Point const& p2)
- : std::pair<Point, Point>(p1, p2)
- {}
- };
- template<typename ConstOrNonConstPoint>
- class referring_segment
- {
- BOOST_CONCEPT_ASSERT( (
- typename std::conditional
- <
- std::is_const<ConstOrNonConstPoint>::value,
- concepts::Point<ConstOrNonConstPoint>,
- concepts::ConstPoint<ConstOrNonConstPoint>
- >
- ) );
- typedef ConstOrNonConstPoint point_type;
- public:
- point_type& first;
- point_type& second;
-
- inline referring_segment(point_type& p1, point_type& p2)
- : first(p1)
- , second(p2)
- {}
- };
- }
- #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
- namespace traits
- {
- template <typename Point>
- struct tag<model::segment<Point> >
- {
- typedef segment_tag type;
- };
- template <typename Point>
- struct point_type<model::segment<Point> >
- {
- typedef Point type;
- };
- template <typename Point, std::size_t Dimension>
- struct indexed_access<model::segment<Point>, 0, Dimension>
- {
- typedef model::segment<Point> segment_type;
- typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
- static constexpr coordinate_type get(segment_type const& s)
- {
- return geometry::get<Dimension>(s.first);
- }
- static void set(segment_type& s, coordinate_type const& value)
- {
- geometry::set<Dimension>(s.first, value);
- }
- };
- template <typename Point, std::size_t Dimension>
- struct indexed_access<model::segment<Point>, 1, Dimension>
- {
- typedef model::segment<Point> segment_type;
- typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
- static constexpr coordinate_type get(segment_type const& s)
- {
- return geometry::get<Dimension>(s.second);
- }
- static void set(segment_type& s, coordinate_type const& value)
- {
- geometry::set<Dimension>(s.second, value);
- }
- };
- template <typename Point>
- struct make<model::segment<Point> >
- {
- typedef model::segment<Point> segment_type;
- static const bool is_specialized = true;
- static constexpr segment_type apply(Point const& p1, Point const& p2)
- {
- return segment_type(p1, p2);
- }
- };
- template <typename ConstOrNonConstPoint>
- struct tag<model::referring_segment<ConstOrNonConstPoint> >
- {
- typedef segment_tag type;
- };
- template <typename ConstOrNonConstPoint>
- struct point_type<model::referring_segment<ConstOrNonConstPoint> >
- {
- typedef ConstOrNonConstPoint type;
- };
- template <typename ConstOrNonConstPoint, std::size_t Dimension>
- struct indexed_access<model::referring_segment<ConstOrNonConstPoint>, 0, Dimension>
- {
- typedef model::referring_segment<ConstOrNonConstPoint> segment_type;
- typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
- static inline coordinate_type get(segment_type const& s)
- {
- return geometry::get<Dimension>(s.first);
- }
- static inline void set(segment_type& s, coordinate_type const& value)
- {
- geometry::set<Dimension>(s.first, value);
- }
- };
- template <typename ConstOrNonConstPoint, std::size_t Dimension>
- struct indexed_access<model::referring_segment<ConstOrNonConstPoint>, 1, Dimension>
- {
- typedef model::referring_segment<ConstOrNonConstPoint> segment_type;
- typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
- static inline coordinate_type get(segment_type const& s)
- {
- return geometry::get<Dimension>(s.second);
- }
- static inline void set(segment_type& s, coordinate_type const& value)
- {
- geometry::set<Dimension>(s.second, value);
- }
- };
- }
- #endif
- }}
- #endif
|