]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/geometry/geometries/concepts/segment_concept.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / geometry / geometries / concepts / segment_concept.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
4 // Copyright (c) 2008-2011 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
6
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #ifndef BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP
15 #define BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP
16
17
18 #include <boost/concept_check.hpp>
19
20 #include <boost/geometry/geometries/concepts/point_concept.hpp>
21
22 #include <boost/geometry/core/access.hpp>
23 #include <boost/geometry/core/point_type.hpp>
24
25
26 namespace boost { namespace geometry { namespace concept
27 {
28
29
30 /*!
31 \brief Segment concept.
32 \ingroup concepts
33 \details Formal definition:
34 The segment concept is defined as following:
35 - there must be a specialization of traits::tag defining segment_tag as type
36 - there must be a specialization of traits::point_type to define the
37   underlying point type (even if it does not consist of points, it should define
38   this type, to indicate the points it can work with)
39 - there must be a specialization of traits::indexed_access, per index
40   and per dimension, with two functions:
41   - get to get a coordinate value
42   - set to set a coordinate value (this one is not checked for ConstSegment)
43
44 \note The segment concept is similar to the box concept, defining another tag.
45 However, the box concept assumes the index as min_corner, max_corner, while
46 for the segment concept there is no assumption.
47 */
48 template <typename Geometry>
49 class Segment
50 {
51 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
52     typedef typename point_type<Geometry>::type point_type;
53
54     BOOST_CONCEPT_ASSERT( (concept::Point<point_type>) );
55
56
57     template <size_t Index, size_t Dimension, size_t DimensionCount>
58     struct dimension_checker
59     {
60         static void apply()
61         {
62             Geometry* s = 0;
63             geometry::set<Index, Dimension>(*s, geometry::get<Index, Dimension>(*s));
64             dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
65         }
66     };
67
68     template <size_t Index, size_t DimensionCount>
69     struct dimension_checker<Index, DimensionCount, DimensionCount>
70     {
71         static void apply() {}
72     };
73
74 public :
75
76     BOOST_CONCEPT_USAGE(Segment)
77     {
78         static const size_t n = dimension<point_type>::type::value;
79         dimension_checker<0, 0, n>::apply();
80         dimension_checker<1, 0, n>::apply();
81     }
82 #endif
83 };
84
85
86 /*!
87 \brief Segment concept (const version).
88 \ingroup const_concepts
89 \details The ConstSegment concept verifies the same as the Segment concept,
90 but does not verify write access.
91 */
92 template <typename Geometry>
93 class ConstSegment
94 {
95 #ifndef DOXYGEN_NO_CONCEPT_MEMBERS
96     typedef typename point_type<Geometry>::type point_type;
97     typedef typename coordinate_type<Geometry>::type coordinate_type;
98
99     BOOST_CONCEPT_ASSERT( (concept::ConstPoint<point_type>) );
100
101
102     template <size_t Index, size_t Dimension, size_t DimensionCount>
103     struct dimension_checker
104     {
105         static void apply()
106         {
107             const Geometry* s = 0;
108             coordinate_type coord(geometry::get<Index, Dimension>(*s));
109             boost::ignore_unused_variable_warning(coord);
110             dimension_checker<Index, Dimension + 1, DimensionCount>::apply();
111         }
112     };
113
114     template <size_t Index, size_t DimensionCount>
115     struct dimension_checker<Index, DimensionCount, DimensionCount>
116     {
117         static void apply() {}
118     };
119
120 public :
121
122     BOOST_CONCEPT_USAGE(ConstSegment)
123     {
124         static const size_t n = dimension<point_type>::type::value;
125         dimension_checker<0, 0, n>::apply();
126         dimension_checker<1, 0, n>::apply();
127     }
128 #endif
129 };
130
131
132 }}} // namespace boost::geometry::concept
133
134
135 #endif // BOOST_GEOMETRY_GEOMETRIES_CONCEPTS_SEGMENT_CONCEPT_HPP