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/signed_size_type.hpp>
17 #include <boost/geometry/algorithms/detail/overlay/segment_identifier.hpp>
18 #include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp>
19 
20 namespace boost { namespace geometry
21 {
22 
23 #ifndef DOXYGEN_NO_DETAIL
24 namespace detail { namespace overlay
25 {
26 
27 enum method_type
28 {
29     method_none,
30     method_disjoint,
31     method_crosses,
32     method_touch,
33     method_touch_interior,
34     method_collinear,
35     method_equal,
36     method_error
37 };
38 
39 
40 /*!
41     \brief Turn operation: operation
42     \details Information necessary for traversal phase (a phase
43         of the overlay process). The information is gathered during the
44         get_turns (segment intersection) phase.
45         The class is to be included in the turn_info class, either direct
46         or a derived or similar class with more (e.g. enrichment) information.
47  */
48 template <typename Point, typename SegmentRatio>
49 struct turn_operation
50 {
51     typedef SegmentRatio segment_ratio_type;
52 
53     operation_type operation;
54     segment_identifier seg_id;
55     SegmentRatio fraction;
56 
57     typedef typename coordinate_type<Point>::type comparable_distance_type;
58     comparable_distance_type remaining_distance;
59 
turn_operationboost::geometry::detail::overlay::turn_operation60     inline turn_operation()
61         : operation(operation_none)
62         , remaining_distance(0)
63     {}
64 };
65 
66 
67 /*!
68     \brief Turn information: intersection point, method, and turn information
69     \details Information necessary for traversal phase (a phase
70         of the overlay process). The information is gathered during the
71         get_turns (segment intersection) phase.
72     \tparam Point point type of intersection point
73     \tparam Operation gives classes opportunity to add additional info
74     \tparam Container gives classes opportunity to define how operations are stored
75  */
76 template
77 <
78     typename Point,
79     typename SegmentRatio,
80     typename Operation = turn_operation<Point, SegmentRatio>,
81     typename Container = boost::array<Operation, 2>
82 >
83 struct turn_info
84 {
85     typedef Point point_type;
86     typedef SegmentRatio segment_ratio_type;
87     typedef Operation turn_operation_type;
88     typedef Container container_type;
89 
90     Point point;
91     method_type method;
92     bool touch_only; // True in case of method touch(interior) and lines do not cross
93     signed_size_type cluster_id; // For multiple turns on same location, >= 0. Else -1
94     bool discarded;
95 
96     // TODO: move this to enriched
97     bool colocated_ii; // Colocated with a ii turn (TODO: or a ix turn)
98     bool colocated_uu; // Colocated with a uu turn or a ux turn
99     bool switch_source; // For u/u turns which can either switch or not
100 
101     Container operations;
102 
turn_infoboost::geometry::detail::overlay::turn_info103     inline turn_info()
104         : method(method_none)
105         , touch_only(false)
106         , cluster_id(-1)
107         , discarded(false)
108         , colocated_ii(false)
109         , colocated_uu(false)
110         , switch_source(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 private :
has12boost::geometry::detail::overlay::turn_info143     inline bool has12(operation_type type1, operation_type type2) const
144     {
145         return this->operations[0].operation == type1
146             && this->operations[1].operation == type2
147             ;
148     }
149 
150 };
151 
152 
153 }} // namespace detail::overlay
154 #endif //DOXYGEN_NO_DETAIL
155 
156 
157 }} // namespace boost::geometry
158 
159 
160 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP
161