Ifdefed some examples for release branch · boostorg/geometry@1431123 · GitHub
Skip to content

Commit 1431123

Browse files
committed
Ifdefed some examples for release branch
[SVN r70919]
1 parent 85810e3 commit 1431123

8 files changed

Lines changed: 67 additions & 22 deletions

‎doc/src/examples/algorithms/assign_2d_point.cpp‎

Lines changed: 3 additions & 3 deletions

‎doc/src/examples/algorithms/create_svg_overlay.hpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313

1414
#include <fstream>
1515
#include <boost/algorithm/string.hpp>
16-
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
16+
17+
#if defined(HAVE_SVG)
18+
# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
19+
#endif
1720

1821
template <typename Geometry, typename Range>
1922
void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range)
2023
{
24+
#if defined(HAVE_SVG)
2125
std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl;
2226

2327
typedef typename boost::geometry::point_type<Geometry>::type point_type;
@@ -38,6 +42,7 @@ void create_svg(std::string const& filename, Geometry const& a, Geometry const&
3842
mapper.text(boost::geometry::return_centroid<point_type>(g), out.str(),
3943
"fill:rgb(0,0,0);font-family:Arial;font-size:10px");
4044
}
45+
#endif
4146
}
4247

4348
// NOTE: convert manually from svg to png using Inkscape ctrl-shift-E

‎doc/src/examples/algorithms/create_svg_two.hpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313

1414
#include <fstream>
1515
#include <boost/algorithm/string.hpp>
16-
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
16+
17+
#if defined(HAVE_SVG)
18+
# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
19+
#endif
1720

1821
template <typename Geometry1, typename Geometry2>
1922
void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b)
2023
{
24+
#if defined(HAVE_SVG)
2125
std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl;
2226

2327
typedef typename boost::geometry::point_type<Geometry1>::type point_type;
@@ -36,6 +40,7 @@ void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const
3640
{
3741
mapper.map(b, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round");
3842
}
43+
#endif
3944
}
4045

4146
// NOTE: convert manually from svg to png using Inkscape ctrl-shift-E

‎example/05_a_overlay_polygon_example.cpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include <boost/geometry/geometry.hpp>
2222
#include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
2323

24-
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
24+
#if defined(HAVE_SVG)
25+
# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
26+
#endif
2527

2628

2729
int main(void)
@@ -32,8 +34,10 @@ int main(void)
3234
typedef bg::model::polygon<point_2d> polygon_2d;
3335

3436

37+
#if defined(HAVE_SVG)
3538
std::ofstream stream("05_a_intersection_polygon_example.svg");
3639
bg::svg_mapper<point_2d> svg(stream, 500, 500);
40+
#endif
3741

3842
// Define a polygons and fill the outer rings.
3943
polygon_2d a;
@@ -45,7 +49,6 @@ int main(void)
4549
}
4650
bg::correct(a);
4751
std::cout << "A: " << bg::dsv(a) << std::endl;
48-
svg.add(a);
4952

5053
polygon_2d b;
5154
{
@@ -56,10 +59,13 @@ int main(void)
5659
}
5760
bg::correct(b);
5861
std::cout << "B: " << bg::dsv(b) << std::endl;
62+
#if defined(HAVE_SVG)
63+
svg.add(a);
5964
svg.add(b);
6065

6166
svg.map(a, "opacity:0.6;fill:rgb(0,255,0);");
6267
svg.map(b, "opacity:0.6;fill:rgb(0,0,255);");
68+
#endif
6369

6470

6571
// Calculate interesection(s)
@@ -70,7 +76,9 @@ int main(void)
7076
BOOST_FOREACH(polygon_2d const& polygon, intersection)
7177
{
7278
std::cout << bg::dsv(polygon) << std::endl;
79+
#if defined(HAVE_SVG)
7380
svg.map(polygon, "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:6");
81+
#endif
7482
}
7583

7684
return 0;

‎example/05_b_overlay_linestring_polygon_example.cpp‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include <boost/geometry/geometry.hpp>
2222
#include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
2323

24-
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
24+
#if defined(HAVE_SVG)
25+
# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
26+
#endif
2527

2628

2729
int main(void)
@@ -43,6 +45,7 @@ int main(void)
4345
}
4446
bg::correct(p);
4547

48+
#if defined(HAVE_SVG)
4649
// Create SVG-mapper
4750
std::ofstream stream("05_b_overlay_linestring_polygon_example.svg");
4851
bg::svg_mapper<point_2d> svg(stream, 500, 500);
@@ -52,7 +55,7 @@ int main(void)
5255
// Map geometries
5356
svg.map(ls, "opacity:0.6;stroke:rgb(255,0,0);stroke-width:2;");
5457
svg.map(p, "opacity:0.6;fill:rgb(0,0,255);");
55-
58+
#endif
5659

5760
// Calculate intersection points (turn points)
5861
typedef bg::detail::overlay::turn_info<point_2d> turn_info;
@@ -76,8 +79,10 @@ int main(void)
7679

7780
}
7881
std::cout << action << " polygon at " << bg::dsv(turn.point) << std::endl;
82+
#if defined(HAVE_SVG)
7983
svg.map(turn.point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
8084
svg.text(turn.point, action, "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
85+
#endif
8186
}
8287

8388
return 0;

‎example/06_b_transformation_example.cpp‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
#include <boost/geometry/algorithms/centroid.hpp>
2020
#include <boost/geometry/strategies/transform.hpp>
2121
#include <boost/geometry/strategies/transform/matrix_transformers.hpp>
22-
#include <boost/geometry/extensions/io/svg/write_svg.hpp>
2322
#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
2423

24+
#if defined(HAVE_SVG)
25+
# include <boost/geometry/extensions/io/svg/write_svg.hpp>
26+
#endif
27+
2528
#include <boost/bind.hpp>
2629
#include <boost/random.hpp>
2730
#include <boost/range.hpp>
@@ -84,8 +87,9 @@ struct svg_output
8487
void put(G const& g, std::string const& label)
8588
{
8689
std::string style_str(style.fill(opacity) + style.stroke(5, opacity));
87-
os << ::boost::geometry::svg(g, style_str) << std::endl;
88-
90+
#if defined(HAVE_SVG)
91+
os << boost::geometry::svg(g, style_str) << std::endl;
92+
#endif
8993
if (!label.empty())
9094
{
9195
typename point_type<G>::type c;
@@ -101,6 +105,7 @@ struct svg_output
101105
random_style style;
102106
};
103107

108+
104109
int main()
105110
{
106111
using namespace boost::geometry::strategy::transform;

‎example/07_a_graph_route_example.cpp‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
// Yes, this example currently uses some extensions:
3131

3232
// For output:
33-
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
33+
#if defined(HAVE_SVG)
34+
# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
35+
#endif
3436

3537
// For distance-calculations over the Earth:
36-
#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
38+
//#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
3739

3840

3941

@@ -260,10 +262,11 @@ inline void build_route(Graph const& graph,
260262

261263
int main()
262264
{
263-
// Define a point in the Geographic coordinate system
265+
// Define a point in the Geographic coordinate system (currently Spherical)
266+
// (geographic calculations are in an extension; for sample it makes no difference)
264267
typedef boost::geometry::model::point
265268
<
266-
double, 2, boost::geometry::cs::geographic<boost::geometry::degree>
269+
double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
267270
> point_type;
268271

269272
typedef boost::geometry::model::linestring<point_type> line_type;
@@ -302,8 +305,12 @@ int main()
302305
double const km = 1000.0;
303306
std::cout << "distances, all in KM" << std::endl
304307
<< std::fixed << std::setprecision(0);
308+
309+
// To calculate distance, declare and construct a strategy with average earth radius
310+
boost::geometry::strategy::distance::haversine<point_type> haversine(6372795.0);
305311

306312
// Main functionality: calculate shortest routes from/to all cities
313+
307314

308315
// For the first one, the complete route is stored as a linestring
309316
bool first = true;
@@ -329,7 +336,7 @@ int main()
329336
if (! boost::equals(city1.get<1>(), city2.get<1>()))
330337
{
331338
double distance = costs[city2.get<2>()] / km;
332-
double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km;
339+
double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km;
333340

334341
std::cout
335342
<< std::setiosflags (std::ios_base::left) << std::setw(15)
@@ -351,6 +358,7 @@ int main()
351358
}
352359
}
353360

361+
#if defined(HAVE_SVG)
354362
// Create the SVG
355363
std::ofstream stream("routes.svg");
356364
boost::geometry::svg_mapper<point_type> mapper(stream, 600, 600);
@@ -378,6 +386,7 @@ int main()
378386
mapper.text(city.get<0>(), city.get<1>(),
379387
"fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
380388
}
389+
#endif
381390

382391
return 0;
383392
}

‎example/07_b_graph_route_example.cpp‎

Lines changed: 13 additions & 5 deletions

0 commit comments

Comments
 (0)