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

« back to all changes in this revision

Viewing changes to include/builtin-ggl/ggl/strategies/intersection_result.hpp

Tags: upstream-0.15.3+svn20934
ImportĀ upstreamĀ versionĀ 0.15.3+svn20934

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_INTERSECTION_RESULT_HPP
 
10
#define GGL_INTERSECTION_RESULT_HPP
 
11
 
 
12
#if defined(HAVE_MATRIX_AS_STRING)
 
13
#include <string>
 
14
#endif
 
15
 
 
16
namespace ggl
 
17
{
 
18
 
 
19
/*!
 
20
    \brief Dimensionally Extended 9 Intersection Matrix
 
21
    \details
 
22
    \ingroup overlay
 
23
    \see http://gis.hsr.ch/wiki/images/3/3d/9dem_springer.pdf
 
24
*/
 
25
struct de9im
 
26
{
 
27
    int ii, ib, ie,
 
28
        bi, bb, be,
 
29
        ei, eb, ee;
 
30
 
 
31
    inline de9im()
 
32
        : ii(-1), ib(-1), ie(-1)
 
33
        , bi(-1), bb(-1), be(-1)
 
34
        , ei(-1), eb(-1), ee(-1)
 
35
    {
 
36
    }
 
37
 
 
38
    inline de9im(int ii0, int ib0, int ie0,
 
39
        int bi0, int bb0, int be0,
 
40
        int ei0, int eb0, int ee0)
 
41
        : ii(ii0), ib(ib0), ie(ie0)
 
42
        , bi(bi0), bb(bb0), be(be0)
 
43
        , ei(ei0), eb(eb0), ee(ee0)
 
44
    {}
 
45
 
 
46
    inline bool equals() const
 
47
    {
 
48
        return ii >= 0 && ie < 0 && be < 0 && ei < 0 && eb < 0;
 
49
    }
 
50
 
 
51
    inline bool disjoint() const
 
52
    {
 
53
        return ii < 0 && ib < 0 && bi < 0 && bb < 0;
 
54
    }
 
55
 
 
56
    inline bool intersects() const
 
57
    {
 
58
        return ii >= 0 || bb >= 0 || bi >= 0 || ib >= 0;
 
59
    }
 
60
 
 
61
    inline bool touches() const
 
62
    {
 
63
        return ii < 0 && (bb >= 0 || bi >= 0 || ib >= 0);
 
64
    }
 
65
 
 
66
    inline bool crosses() const
 
67
    {
 
68
        return (ii >= 0 && ie >= 0) || (ii == 0);
 
69
    }
 
70
 
 
71
    inline bool overlaps() const
 
72
    {
 
73
        return ii >= 0 && ie >= 0 && ei >= 0;
 
74
    }
 
75
 
 
76
    inline bool within() const
 
77
    {
 
78
        return ii >= 0 && ie < 0 && be < 0;
 
79
    }
 
80
 
 
81
    inline bool contains() const
 
82
    {
 
83
        return ii >= 0 && ei < 0 && eb < 0;
 
84
    }
 
85
 
 
86
 
 
87
    static inline char as_char(int v)
 
88
    {
 
89
        return v >= 0 && v < 10 ? ('0' + char(v)) : '-';
 
90
    }
 
91
 
 
92
#if defined(HAVE_MATRIX_AS_STRING)
 
93
    inline std::string matrix_as_string(std::string const& tab, std::string const& nl) const
 
94
    {
 
95
        std::string ret;
 
96
        ret.reserve(9 + tab.length() * 3 + nl.length() * 3);
 
97
        ret += tab; ret += as_char(ii); ret += as_char(ib); ret += as_char(ie); ret += nl;
 
98
        ret += tab; ret += as_char(bi); ret += as_char(bb); ret += as_char(be); ret += nl;
 
99
        ret += tab; ret += as_char(ei); ret += as_char(eb); ret += as_char(ee);
 
100
        return ret;
 
101
    }
 
102
 
 
103
    inline std::string matrix_as_string() const
 
104
    {
 
105
        return matrix_as_string("", "");
 
106
    }
 
107
#endif
 
108
 
 
109
};
 
110
 
 
111
struct de9im_segment : public de9im
 
112
{
 
113
    bool collinear; // true if segments are aligned (for equal,overlap,touch)
 
114
    bool opposite; // true if direction is reversed (for equal,overlap,touch)
 
115
    bool parallel;  // true if disjoint but parallel
 
116
    bool degenerate; // true for segment(s) of zero length
 
117
 
 
118
    double ra, rb; // temp
 
119
 
 
120
    inline de9im_segment()
 
121
        : de9im()
 
122
        , collinear(false)
 
123
        , opposite(false)
 
124
        , parallel(false)
 
125
        , degenerate(false)
 
126
    {}
 
127
 
 
128
    inline de9im_segment(double a, double b,
 
129
        int ii0, int ib0, int ie0,
 
130
        int bi0, int bb0, int be0,
 
131
        int ei0, int eb0, int ee0,
 
132
        bool c = false, bool o = false, bool p = false, bool d = false)
 
133
        : de9im(ii0, ib0, ie0, bi0, bb0, be0, ei0, eb0, ee0)
 
134
        , collinear(c)
 
135
        , opposite(o)
 
136
        , parallel(p)
 
137
        , degenerate(d)
 
138
        , ra(a), rb(b)
 
139
    {}
 
140
 
 
141
 
 
142
#if defined(HAVE_MATRIX_AS_STRING)
 
143
    inline std::string as_string() const
 
144
    {
 
145
        std::string ret = matrix_as_string();
 
146
        ret += collinear ? "c" : "-";
 
147
        ret += opposite ? "o" : "-";
 
148
        return ret;
 
149
    }
 
150
#endif
 
151
};
 
152
 
 
153
template <typename P>
 
154
struct segment_intersection_points
 
155
{
 
156
    int count;
 
157
    P intersections[2];
 
158
 
 
159
    segment_intersection_points()
 
160
        : count(0)
 
161
    {}
 
162
};
 
163
 
 
164
} // namespace ggl
 
165
 
 
166
 
 
167
#endif // GGL_INTERSECTION_RESULT_HPP