~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to include/ggl/algorithms/overlay/intersection_point.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Generic Geometry Library
 
2
//
 
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)
 
8
 
 
9
#ifndef GGL_ALGORITHMS_INTERSECTION_POINT_HPP
 
10
#define GGL_ALGORITHMS_INTERSECTION_POINT_HPP
 
11
 
 
12
#include <vector>
 
13
 
 
14
 
 
15
#include <ggl/core/access.hpp>
 
16
#include <ggl/core/coordinate_dimension.hpp>
 
17
 
 
18
#include <ggl/strategies/distance_result.hpp>
 
19
#include <ggl/strategies/strategy_traits.hpp>
 
20
 
 
21
#include <ggl/algorithms/overlay/segment_identifier.hpp>
 
22
 
 
23
 
 
24
namespace ggl
 
25
{
 
26
 
 
27
#ifndef DOXYGEN_NO_DETAIL
 
28
namespace detail { namespace intersection {
 
29
 
 
30
 
 
31
template<typename P>
 
32
struct intersection_info
 
33
{
 
34
    typedef typename distance_result<P, P>::type distance_type;
 
35
 
 
36
    inline intersection_info()
 
37
        : travels_to_vertex_index(-1)
 
38
        , travels_to_ip_index(-1)
 
39
        , next_ip_index(-1)
 
40
        , distance(ggl::make_distance_result<distance_type>(0))
 
41
        , direction(0)
 
42
        , how(0)
 
43
        , arrival(0)
 
44
    {}
 
45
 
 
46
    // Identifier of this segment (source,segment,ring,multi)
 
47
    segment_identifier seg_id;
 
48
 
 
49
 
 
50
    // vertex to which is free travel after this IP,
 
51
    // so from "segment_index+1" to "travels_to_vertex_index", without IP-s,
 
52
    // can be -1
 
53
    int travels_to_vertex_index;
 
54
 
 
55
    // same but now IP index, so "next IP index" but not on THIS segment
 
56
    int travels_to_ip_index;
 
57
 
 
58
    // index of next IP on this segment, -1 if there is no one
 
59
    int next_ip_index;
 
60
 
 
61
    distance_type distance; // distance-measurement from segment.first to IP
 
62
 
 
63
    // 1: left, -1: right, 0: collinear
 
64
    int direction;
 
65
 
 
66
    // Information about how intersection is done
 
67
    char how;
 
68
    int arrival;
 
69
};
 
70
 
 
71
 
 
72
template<typename P>
 
73
struct intersection_point
 
74
{
 
75
    public :
 
76
        inline intersection_point()
 
77
            : visit_code(0) // VISIT_NONE
 
78
            , shared_code(0)
 
79
        {
 
80
            // Init intersection point with zero
 
81
            ggl::assign_zero(point);
 
82
        }
 
83
 
 
84
 
 
85
#ifdef GGL_DEBUG_INTERSECTION
 
86
        static inline std::string dir(int d)
 
87
        {
 
88
            return d == 0 ? "-" : (d == 1 ? "L" : "R");
 
89
        }
 
90
        static inline std::string how(int h)
 
91
        {
 
92
            return h == 0 ? "-" : (h == 1 ? "A" : "D");
 
93
        }
 
94
 
 
95
        friend std::ostream& operator<<(std::ostream &os, intersection_point<P> const& p)
 
96
        {
 
97
            os << "IP (" << ggl::get<0>(p.point) << "," << ggl::get<1>(p.point) << ")"
 
98
                << " visited: " << int(p.visit_code)
 
99
                << " shared: " << p.shared_code
 
100
                << std::endl;
 
101
 
 
102
            for (unsigned int i = 0; i < p.info.size(); i++)
 
103
            {
 
104
                os  << "\t"
 
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)
 
113
                    << std::endl;
 
114
            }
 
115
            return os;
 
116
        }
 
117
#endif
 
118
        typedef intersection_info<P> traversal_type;
 
119
        typedef std::vector<traversal_type> traversal_vector;
 
120
 
 
121
        P point;
 
122
 
 
123
        int visit_code;
 
124
        short int shared_code; // 0 for nothing, 1 for is-shared, 2 for to-be-deleted
 
125
 
 
126
        // info about the two intersecting segments
 
127
        // usually two, but can be more if IP's are merged
 
128
        traversal_vector info;
 
129
 
 
130
 
 
131
        inline void clone_except_info(intersection_point& other) const
 
132
        {
 
133
            other.point = point;
 
134
            other.shared_code = shared_code;
 
135
            other.visit_code = visit_code;
 
136
        }
 
137
};
 
138
 
 
139
 
 
140
 
 
141
 
 
142
}} // namespace detail::intersection
 
143
#endif //DOXYGEN_NO_DETAIL
 
144
 
 
145
 
 
146
// Register the intersection point as being a point fulfilling the ggl Point Concept
 
147
namespace traits
 
148
{
 
149
 
 
150
    template <typename P>
 
151
    struct coordinate_type<ggl::detail::intersection::intersection_point<P> >
 
152
    {
 
153
        typedef typename ggl::coordinate_type<P>::type type;
 
154
    };
 
155
 
 
156
    template <typename P>
 
157
    struct coordinate_system<ggl::detail::intersection::intersection_point<P> >
 
158
    {
 
159
        typedef typename ggl::coordinate_system<P>::type type;
 
160
    };
 
161
 
 
162
    template <typename P>
 
163
    struct dimension<ggl::detail::intersection::intersection_point<P> >
 
164
        : ggl::dimension<P>
 
165
    {};
 
166
 
 
167
    template <typename P>
 
168
    struct tag<ggl::detail::intersection::intersection_point<P> >
 
169
    {
 
170
        typedef point_tag type;
 
171
    };
 
172
 
 
173
    template <typename P>
 
174
    struct access<ggl::detail::intersection::intersection_point<P> >
 
175
    {
 
176
        template <int Index>
 
177
        static inline typename coordinate_type<P>::type get(
 
178
                ggl::detail::intersection::intersection_point<P> const& p)
 
179
        {
 
180
            return ggl::get<Index>(p.point);
 
181
        }
 
182
 
 
183
        template <int Index>
 
184
        static inline void set(ggl::detail::intersection::intersection_point<P>& p,
 
185
                typename coordinate_type<P>::type const& value)
 
186
        {
 
187
            ggl::set<Index>(p.point, value);
 
188
        }
 
189
    };
 
190
 
 
191
}
 
192
 
 
193
 
 
194
} // namespace ggl
 
195
 
 
196
#endif // GGL_ALGORITHMS_INTERSECTION_POINT_HPP