Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:28

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 
0007 // This file was modified by Oracle on 2020.
0008 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 
0011 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0012 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0013 
0014 // Use, modification and distribution is subject to the Boost Software License,
0015 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0016 // http://www.boost.org/LICENSE_1_0.txt)
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 \brief Class segment: small class containing two points
0043 \ingroup geometries
0044 \details From Wikipedia: In geometry, a line segment is a part of a line that is bounded
0045  by two distinct end points, and contains every point on the line between its end points.
0046 \note There is also a point-referring-segment, class referring_segment,
0047    containing point references, where points are NOT copied
0048 
0049 \qbk{[include reference/geometries/segment.qbk]}
0050 \qbk{before.synopsis,
0051 [heading Model of]
0052 [link geometry.reference.concepts.concept_segment Segment Concept]
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     /// \constructor_default_no_init
0063     constexpr segment() = default;
0064 
0065     /*!
0066         \brief Constructor taking the first and the second point
0067     */
0068     constexpr segment(Point const& p1, Point const& p2)
0069         : std::pair<Point, Point>(p1, p2)
0070     {}
0071 };
0072 
0073 
0074 /*!
0075 \brief Class segment: small class containing two (templatized) point references
0076 \ingroup geometries
0077 \details From Wikipedia: In geometry, a line segment is a part of a line that is bounded
0078  by two distinct end points, and contains every point on the line between its end points.
0079 \note The structure is like std::pair, and can often be used interchangeable.
0080 Difference is that it refers to points, does not have points.
0081 \note Like std::pair, points are public available.
0082 \note type is const or non const, so geometry::segment<P> or geometry::segment<P const>
0083 \note We cannot derive from std::pair<P&, P&> because of
0084 reference assignments.
0085 \tparam ConstOrNonConstPoint point type of the segment, maybe a point or a const point
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         \brief Constructor taking the first and the second point
0108     */
0109     inline referring_segment(point_type& p1, point_type& p2)
0110         : first(p1)
0111         , second(p2)
0112     {}
0113 };
0114 
0115 
0116 } // namespace model
0117 
0118 
0119 // Traits specializations for segment above
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 } // namespace traits
0237 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0238 
0239 }} // namespace boost::geometry
0240 
0241 #endif // BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP