Skip to content

Commit 689eb04

Browse files
committed
Refactor the geometry details out into make and crosses
1 parent 1dbc818 commit 689eb04

File tree

1 file changed

+29
-36
lines changed

1 file changed

+29
-36
lines changed

include/boost/graph/is_straight_line_drawing.hpp

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <boost/geometry/algorithms/crosses.hpp>
2020
#include <boost/geometry/geometries/linestring.hpp>
21+
#include <boost/geometry/core/coordinate_type.hpp>
2122

2223
#include <boost/numeric/conversion/cast.hpp>
2324

@@ -27,7 +28,33 @@
2728

2829
namespace boost
2930
{
31+
// Overload of make from Boost.Geometry.
32+
template<typename Geometry, typename Graph, typename GridPositionMap>
33+
Geometry make(typename graph_traits<Graph>::edge_descriptor e,
34+
Graph const &g,
35+
GridPositionMap const &drawing)
36+
{
37+
auto e_source(source(e, g));
38+
auto e_target(target(e, g));
39+
using Float = typename geometry::coordinate_type<Geometry>::type;
40+
return {{numeric_cast<Float>(drawing[e_source].x), numeric_cast<Float>(drawing[e_source].y)},
41+
{numeric_cast<Float>(drawing[e_target].x), numeric_cast<Float>(drawing[e_target].y)}};
42+
}
3043

44+
// Overload of crosses from Boost.Geometry.
45+
template<typename Graph, typename GridPositionMap>
46+
bool crosses(typename graph_traits<Graph>::edge_descriptor e,
47+
typename graph_traits<Graph>::edge_descriptor f,
48+
Graph const &g,
49+
GridPositionMap const &drawing)
50+
{
51+
using geometry::crosses;
52+
using geometry::model::linestring;
53+
using geometry::model::d2::point_xy;
54+
using linestring2d = geometry::model::linestring<geometry::model::d2::point_xy<double>>;
55+
return crosses(make<linestring2d>(e, g, drawing),
56+
make<linestring2d>(f, g, drawing));
57+
}
3158

3259
template < typename Graph, typename GridPositionMap, typename VertexIndexMap >
3360
bool is_straight_line_drawing(
@@ -95,10 +122,6 @@ bool is_straight_line_drawing(
95122
}
96123
else
97124
{
98-
using geometry::crosses;
99-
using geometry::model::linestring;
100-
using geometry::model::d2::point_xy;
101-
102125
active_map_iterator_t before, after;
103126
if (a_itr == active_edges.begin())
104127
before = active_edges.end();
@@ -108,45 +131,15 @@ bool is_straight_line_drawing(
108131

109132
if (before != active_edges.end())
110133
{
111-
112134
edge_t f = before->second;
113-
vertex_t e_source(source(e, g));
114-
vertex_t e_target(target(e, g));
115-
vertex_t f_source(source(f, g));
116-
vertex_t f_target(target(f, g));
117-
118-
linestring<point_xy<double>> source{{numeric_cast<double>(drawing[e_source].x),
119-
numeric_cast<double>(drawing[e_source].y)},
120-
{numeric_cast<double>(drawing[e_target].x),
121-
numeric_cast<double>(drawing[e_target].y)}};
122-
linestring<point_xy<double>> target{{numeric_cast<double>(drawing[f_source].x),
123-
numeric_cast<double>(drawing[f_source].y)},
124-
{numeric_cast<double>(drawing[f_target].x),
125-
numeric_cast<double>(drawing[f_target].y)}};
126-
127-
if (crosses(source, target))
135+
if (crosses(e, f, g, drawing))
128136
return false;
129137
}
130138

131139
if (after != active_edges.end())
132140
{
133-
134141
edge_t f = after->second;
135-
vertex_t e_source(source(e, g));
136-
vertex_t e_target(target(e, g));
137-
vertex_t f_source(source(f, g));
138-
vertex_t f_target(target(f, g));
139-
140-
linestring<point_xy<double>> source{{numeric_cast<double>(drawing[e_source].x),
141-
numeric_cast<double>(drawing[e_source].y)},
142-
{numeric_cast<double>(drawing[e_target].x),
143-
numeric_cast<double>(drawing[e_target].y)}};
144-
linestring<point_xy<double>> target{{numeric_cast<double>(drawing[f_source].x),
145-
numeric_cast<double>(drawing[f_source].y)},
146-
{numeric_cast<double>(drawing[f_target].x),
147-
numeric_cast<double>(drawing[f_target].y)}};
148-
149-
if (crosses(source, target))
142+
if (crosses(e, f, g, drawing))
150143
return false;
151144
}
152145

0 commit comments

Comments
 (0)