Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@16: // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@16: // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. Chris@16: // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. Chris@16: Chris@16: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@16: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP Chris@16: #define BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: namespace model Chris@16: { Chris@16: Chris@16: /*! Chris@16: \brief Class segment: small class containing two points Chris@16: \ingroup geometries Chris@16: \details From Wikipedia: In geometry, a line segment is a part of a line that is bounded Chris@16: by two distinct end points, and contains every point on the line between its end points. Chris@16: \note There is also a point-referring-segment, class referring_segment, Chris@16: containing point references, where points are NOT copied Chris@16: */ Chris@16: template Chris@16: class segment : public std::pair Chris@16: { Chris@16: public : Chris@16: inline segment() Chris@16: {} Chris@16: Chris@16: inline segment(Point const& p1, Point const& p2) Chris@16: { Chris@16: this->first = p1; Chris@16: this->second = p2; Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief Class segment: small class containing two (templatized) point references Chris@16: \ingroup geometries Chris@16: \details From Wikipedia: In geometry, a line segment is a part of a line that is bounded Chris@16: by two distinct end points, and contains every point on the line between its end points. Chris@16: \note The structure is like std::pair, and can often be used interchangeable. Chris@16: Difference is that it refers to points, does not have points. Chris@16: \note Like std::pair, points are public available. Chris@16: \note type is const or non const, so geometry::segment

or geometry::segment

Chris@16: \note We cannot derive from std::pair because of Chris@16: reference assignments. Chris@16: \tparam ConstOrNonConstPoint point type of the segment, maybe a point or a const point Chris@16: */ Chris@16: template Chris@16: class referring_segment Chris@16: { Chris@16: BOOST_CONCEPT_ASSERT( ( Chris@16: typename boost::mpl::if_ Chris@16: < Chris@16: boost::is_const, Chris@16: concept::Point, Chris@16: concept::ConstPoint Chris@16: > Chris@16: ) ); Chris@16: Chris@16: typedef ConstOrNonConstPoint point_type; Chris@16: Chris@16: public: Chris@16: Chris@16: point_type& first; Chris@16: point_type& second; Chris@16: Chris@16: inline referring_segment(point_type& p1, point_type& p2) Chris@16: : first(p1) Chris@16: , second(p2) Chris@16: {} Chris@16: }; Chris@16: Chris@16: Chris@16: } // namespace model Chris@16: Chris@16: Chris@16: // Traits specializations for segment above Chris@16: #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS Chris@16: namespace traits Chris@16: { Chris@16: Chris@16: template Chris@16: struct tag > Chris@16: { Chris@16: typedef segment_tag type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct point_type > Chris@16: { Chris@16: typedef Point type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct indexed_access, 0, Dimension> Chris@16: { Chris@16: typedef model::segment segment_type; Chris@16: typedef typename geometry::coordinate_type::type coordinate_type; Chris@16: Chris@16: static inline coordinate_type get(segment_type const& s) Chris@16: { Chris@16: return geometry::get(s.first); Chris@16: } Chris@16: Chris@16: static inline void set(segment_type& s, coordinate_type const& value) Chris@16: { Chris@16: geometry::set(s.first, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: struct indexed_access, 1, Dimension> Chris@16: { Chris@16: typedef model::segment segment_type; Chris@16: typedef typename geometry::coordinate_type::type coordinate_type; Chris@16: Chris@16: static inline coordinate_type get(segment_type const& s) Chris@16: { Chris@16: return geometry::get(s.second); Chris@16: } Chris@16: Chris@16: static inline void set(segment_type& s, coordinate_type const& value) Chris@16: { Chris@16: geometry::set(s.second, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: struct tag > Chris@16: { Chris@16: typedef segment_tag type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct point_type > Chris@16: { Chris@16: typedef ConstOrNonConstPoint type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct indexed_access, 0, Dimension> Chris@16: { Chris@16: typedef model::referring_segment segment_type; Chris@16: typedef typename geometry::coordinate_type::type coordinate_type; Chris@16: Chris@16: static inline coordinate_type get(segment_type const& s) Chris@16: { Chris@16: return geometry::get(s.first); Chris@16: } Chris@16: Chris@16: static inline void set(segment_type& s, coordinate_type const& value) Chris@16: { Chris@16: geometry::set(s.first, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: struct indexed_access, 1, Dimension> Chris@16: { Chris@16: typedef model::referring_segment segment_type; Chris@16: typedef typename geometry::coordinate_type::type coordinate_type; Chris@16: Chris@16: static inline coordinate_type get(segment_type const& s) Chris@16: { Chris@16: return geometry::get(s.second); Chris@16: } Chris@16: Chris@16: static inline void set(segment_type& s, coordinate_type const& value) Chris@16: { Chris@16: geometry::set(s.second, value); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: } // namespace traits Chris@16: #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: #endif // BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP