16
16
#include < boost/graph/properties.hpp>
17
17
#include < boost/graph/planar_detail/bucket_sort.hpp>
18
18
19
+ #include < boost/geometry/algorithms/crosses.hpp>
20
+ #include < boost/geometry/geometries/linestring.hpp>
21
+
19
22
#include < algorithm>
20
23
#include < vector>
21
- #include < set>
22
24
#include < map>
23
25
24
26
namespace boost
25
27
{
26
28
27
- // Return true exactly when the line segments s1 = ((x1,y1), (x2,y2)) and
28
- // s2 = ((a1,b1), (a2,b2)) intersect in a point other than the endpoints of
29
- // the line segments. The one exception to this rule is when s1 = s2, in
30
- // which case false is returned - this is to accomodate multiple edges
31
- // between the same pair of vertices, which shouldn't invalidate the straight
32
- // line embedding. A tolerance variable epsilon can also be used, which
33
- // defines how far away from the endpoints of s1 and s2 we want to consider
34
- // an intersection.
35
-
36
- inline bool intersects (double x1, double y1, double x2, double y2, double a1,
37
- double b1, double a2, double b2, double epsilon = 0.000001 )
38
- {
39
-
40
- if (x1 - x2 == 0 )
41
- {
42
- std::swap (x1, a1);
43
- std::swap (y1 , b1);
44
- std::swap (x2, a2);
45
- std::swap (y2, b2);
46
- }
47
-
48
- if (x1 - x2 == 0 )
49
- {
50
- BOOST_USING_STD_MAX ();
51
- BOOST_USING_STD_MIN ();
52
-
53
- // two vertical line segments
54
- double min_y = min BOOST_PREVENT_MACRO_SUBSTITUTION (y1 , y2);
55
- double max_y = max BOOST_PREVENT_MACRO_SUBSTITUTION (y1 , y2);
56
- double min_b = min BOOST_PREVENT_MACRO_SUBSTITUTION (b1, b2);
57
- double max_b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b1, b2);
58
- if ((max_y > max_b && max_b > min_y)
59
- || (max_b > max_y && max_y > min_b))
60
- return true ;
61
- else
62
- return false ;
63
- }
64
-
65
- double x_diff = x1 - x2;
66
- double y_diff = y1 - y2;
67
- double a_diff = a2 - a1;
68
- double b_diff = b2 - b1;
69
-
70
- double beta_denominator = b_diff - (y_diff / ((double )x_diff)) * a_diff;
71
-
72
- if (beta_denominator == 0 )
73
- {
74
- // parallel lines
75
- return false ;
76
- }
77
-
78
- double beta = (b2 - y2 - (y_diff / ((double )x_diff)) * (a2 - x2))
79
- / beta_denominator;
80
- double alpha = (a2 - x2 - beta * (a_diff)) / x_diff;
81
-
82
- double upper_bound = 1 - epsilon;
83
- double lower_bound = 0 + epsilon;
84
-
85
- return (beta < upper_bound && beta > lower_bound && alpha < upper_bound
86
- && alpha > lower_bound);
87
- }
88
29
89
30
template < typename Graph, typename GridPositionMap, typename VertexIndexMap >
90
31
bool is_straight_line_drawing (
@@ -152,6 +93,10 @@ bool is_straight_line_drawing(
152
93
}
153
94
else
154
95
{
96
+ using geometry::crosses;
97
+ using geometry::model::linestring;
98
+ using geometry::model::d2::point_xy;
99
+
155
100
active_map_iterator_t before, after;
156
101
if (a_itr == active_edges.begin ())
157
102
before = active_edges.end ();
@@ -168,10 +113,12 @@ bool is_straight_line_drawing(
168
113
vertex_t f_source (source (f, g));
169
114
vertex_t f_target (target (f, g));
170
115
171
- if (intersects (drawing[e_source].x , drawing[e_source].y ,
172
- drawing[e_target].x , drawing[e_target].y ,
173
- drawing[f_source].x , drawing[f_source].y ,
174
- drawing[f_target].x , drawing[f_target].y ))
116
+ linestring<point_xy<double >> source{{drawing[e_source].x , drawing[e_source].y },
117
+ {drawing[e_target].x , drawing[e_target].y }};
118
+ linestring<point_xy<double >> target{{drawing[f_source].x , drawing[f_source].y },
119
+ {drawing[f_target].x , drawing[f_target].y }};
120
+
121
+ if (crosses (source, target))
175
122
return false ;
176
123
}
177
124
@@ -184,10 +131,12 @@ bool is_straight_line_drawing(
184
131
vertex_t f_source (source (f, g));
185
132
vertex_t f_target (target (f, g));
186
133
187
- if (intersects (drawing[e_source].x , drawing[e_source].y ,
188
- drawing[e_target].x , drawing[e_target].y ,
189
- drawing[f_source].x , drawing[f_source].y ,
190
- drawing[f_target].x , drawing[f_target].y ))
134
+ linestring<point_xy<double >> source{{drawing[e_source].x , drawing[e_source].y },
135
+ {drawing[e_target].x , drawing[e_target].y }};
136
+ linestring<point_xy<double >> target{{drawing[f_source].x , drawing[f_source].y },
137
+ {drawing[f_target].x , drawing[f_target].y }};
138
+
139
+ if (crosses (source, target))
191
140
return false ;
192
141
}
193
142
0 commit comments