1
// Generic Geometry Library
3
// Copyright Barend Gehrels 1995-2009, Geodan Holding B.V. Amsterdam, the Netherlands.
4
// Copyright Bruno Lalande 2008, 2009
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)
9
#ifndef GGL_ALGORITHMS_INTERSECTION_POINT_HPP
10
#define GGL_ALGORITHMS_INTERSECTION_POINT_HPP
15
#include <ggl/core/access.hpp>
16
#include <ggl/core/coordinate_dimension.hpp>
18
#include <ggl/strategies/distance_result.hpp>
19
#include <ggl/strategies/strategy_traits.hpp>
21
#include <ggl/algorithms/overlay/segment_identifier.hpp>
27
#ifndef DOXYGEN_NO_DETAIL
28
namespace detail { namespace intersection {
32
struct intersection_info
34
typedef typename distance_result<P, P>::type distance_type;
36
inline intersection_info()
37
: travels_to_vertex_index(-1)
38
, travels_to_ip_index(-1)
40
, distance(ggl::make_distance_result<distance_type>(0))
46
// Identifier of this segment (source,segment,ring,multi)
47
segment_identifier seg_id;
50
// vertex to which is free travel after this IP,
51
// so from "segment_index+1" to "travels_to_vertex_index", without IP-s,
53
int travels_to_vertex_index;
55
// same but now IP index, so "next IP index" but not on THIS segment
56
int travels_to_ip_index;
58
// index of next IP on this segment, -1 if there is no one
61
distance_type distance; // distance-measurement from segment.first to IP
63
// 1: left, -1: right, 0: collinear
66
// Information about how intersection is done
73
struct intersection_point
76
inline intersection_point()
77
: visit_code(0) // VISIT_NONE
80
// Init intersection point with zero
81
ggl::assign_zero(point);
85
#ifdef GGL_DEBUG_INTERSECTION
86
static inline std::string dir(int d)
88
return d == 0 ? "-" : (d == 1 ? "L" : "R");
90
static inline std::string how(int h)
92
return h == 0 ? "-" : (h == 1 ? "A" : "D");
95
friend std::ostream& operator<<(std::ostream &os, intersection_point<P> const& p)
97
os << "IP (" << ggl::get<0>(p.point) << "," << ggl::get<1>(p.point) << ")"
98
<< " visited: " << int(p.visit_code)
99
<< " shared: " << p.shared_code
102
for (unsigned int i = 0; i < p.info.size(); i++)
105
<< " src: " << p.info[i].seg_id.source_index
106
<< " how: " << p.info[i].how << "[" << how(p.info[i].arrival) << "]"
107
<< " dir: " << dir(p.info[i].direction)
108
<< " seg: " << p.info[i].seg_id.segment_index
109
<< " - " << p.info[i].travels_to_vertex_index
110
<< " next ip: " << p.info[i].travels_to_ip_index
111
<< " , " << p.info[i].next_ip_index
112
<< " dist: " << double(p.info[i].distance)
118
typedef intersection_info<P> traversal_type;
119
typedef std::vector<traversal_type> traversal_vector;
124
short int shared_code; // 0 for nothing, 1 for is-shared, 2 for to-be-deleted
126
// info about the two intersecting segments
127
// usually two, but can be more if IP's are merged
128
traversal_vector info;
131
inline void clone_except_info(intersection_point& other) const
134
other.shared_code = shared_code;
135
other.visit_code = visit_code;
142
}} // namespace detail::intersection
143
#endif //DOXYGEN_NO_DETAIL
146
// Register the intersection point as being a point fulfilling the ggl Point Concept
150
template <typename P>
151
struct coordinate_type<ggl::detail::intersection::intersection_point<P> >
153
typedef typename ggl::coordinate_type<P>::type type;
156
template <typename P>
157
struct coordinate_system<ggl::detail::intersection::intersection_point<P> >
159
typedef typename ggl::coordinate_system<P>::type type;
162
template <typename P>
163
struct dimension<ggl::detail::intersection::intersection_point<P> >
167
template <typename P>
168
struct tag<ggl::detail::intersection::intersection_point<P> >
170
typedef point_tag type;
173
template <typename P>
174
struct access<ggl::detail::intersection::intersection_point<P> >
177
static inline typename coordinate_type<P>::type get(
178
ggl::detail::intersection::intersection_point<P> const& p)
180
return ggl::get<Index>(p.point);
184
static inline void set(ggl::detail::intersection::intersection_point<P>& p,
185
typename coordinate_type<P>::type const& value)
187
ggl::set<Index>(p.point, value);
196
#endif // GGL_ALGORITHMS_INTERSECTION_POINT_HPP