1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP
10 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP
11 
12 
13 #include <boost/array.hpp>
14 
15 #include <boost/geometry/core/coordinate_type.hpp>
16 #include <boost/geometry/algorithms/detail/overlay/segment_identifier.hpp>
17 
18 namespace boost { namespace geometry
19 {
20 
21 #ifndef DOXYGEN_NO_DETAIL
22 namespace detail { namespace overlay
23 {
24 
25 
26 enum operation_type
27 {
28     operation_none,
29     operation_union,
30     operation_intersection,
31     operation_blocked,
32     operation_continue,
33     operation_opposite
34 };
35 
36 
37 enum method_type
38 {
39     method_none,
40     method_disjoint,
41     method_crosses,
42     method_touch,
43     method_touch_interior,
44     method_collinear,
45     method_equal,
46     method_error
47 };
48 
49 
50 /*!
51     \brief Turn operation: operation
52     \details Information necessary for traversal phase (a phase
53         of the overlay process). The information is gathered during the
54         get_turns (segment intersection) phase.
55         The class is to be included in the turn_info class, either direct
56         or a derived or similar class with more (e.g. enrichment) information.
57  */
58 template <typename Point, typename SegmentRatio>
59 struct turn_operation
60 {
61     operation_type operation;
62     segment_identifier seg_id;
63     SegmentRatio fraction;
64 
65     typedef typename coordinate_type<Point>::type comparable_distance_type;
66     comparable_distance_type remaining_distance;
67 
turn_operationboost::geometry::detail::overlay::turn_operation68     inline turn_operation()
69         : operation(operation_none)
70         , remaining_distance(0)
71     {}
72 };
73 
74 
75 /*!
76     \brief Turn information: intersection point, method, and turn information
77     \details Information necessary for traversal phase (a phase
78         of the overlay process). The information is gathered during the
79         get_turns (segment intersection) phase.
80     \tparam Point point type of intersection point
81     \tparam Operation gives classes opportunity to add additional info
82     \tparam Container gives classes opportunity to define how operations are stored
83  */
84 template
85 <
86     typename Point,
87     typename SegmentRatio,
88     typename Operation = turn_operation<Point, SegmentRatio>,
89     typename Container = boost::array<Operation, 2>
90 >
91 struct turn_info
92 {
93     typedef Point point_type;
94     typedef Operation turn_operation_type;
95     typedef Container container_type;
96 
97     Point point;
98     method_type method;
99     bool discarded;
100     bool selectable_start; // Can be used as starting-turn in traverse
101     bool colocated;
102 
103 
104     Container operations;
105 
turn_infoboost::geometry::detail::overlay::turn_info106     inline turn_info()
107         : method(method_none)
108         , discarded(false)
109         , selectable_start(true)
110         , colocated(false)
111     {}
112 
bothboost::geometry::detail::overlay::turn_info113     inline bool both(operation_type type) const
114     {
115         return has12(type, type);
116     }
117 
hasboost::geometry::detail::overlay::turn_info118     inline bool has(operation_type type) const
119     {
120         return this->operations[0].operation == type
121             || this->operations[1].operation == type;
122     }
123 
combinationboost::geometry::detail::overlay::turn_info124     inline bool combination(operation_type type1, operation_type type2) const
125     {
126         return has12(type1, type2) || has12(type2, type1);
127     }
128 
blockedboost::geometry::detail::overlay::turn_info129     inline bool blocked() const
130     {
131         return both(operation_blocked);
132     }
oppositeboost::geometry::detail::overlay::turn_info133     inline bool opposite() const
134     {
135         return both(operation_opposite);
136     }
any_blockedboost::geometry::detail::overlay::turn_info137     inline bool any_blocked() const
138     {
139         return has(operation_blocked);
140     }
141 
142 
143 private :
has12boost::geometry::detail::overlay::turn_info144     inline bool has12(operation_type type1, operation_type type2) const
145     {
146         return this->operations[0].operation == type1
147             && this->operations[1].operation == type2
148             ;
149     }
150 
151 };
152 
153 
154 }} // namespace detail::overlay
155 #endif //DOXYGEN_NO_DETAIL
156 
157 
158 }} // namespace boost::geometry
159 
160 
161 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP
162