Skip to content

Commit

Permalink
feat: add cmake support to examples
Browse files Browse the repository at this point in the history
- replace BOOST_FOREACH

- replace Boost.Assign

- replace typedef with using

- other minor changes
  • Loading branch information
barendgehrels committed Sep 30, 2024
1 parent 966567f commit 38adce6
Show file tree
Hide file tree
Showing 144 changed files with 670 additions and 563 deletions.
40 changes: 40 additions & 0 deletions doc/src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Boost.Geometry

# Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands.

# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

function(boost_geometry_add_example prefix item)
set(example_name "boost_geometry_example_${prefix}_${item}")
add_executable(${example_name} ${item}.cpp)

# Add a dependency to Boost.Geometry
target_link_libraries(${example_name}
PRIVATE
Boost::geometry
)

# Include the main Geometry test folder and the current folder
target_include_directories(${example_name}
PRIVATE
.)

# To compile with C++14
target_compile_features(${example_name} PRIVATE cxx_std_14)

endfunction()

foreach(item IN ITEMS
quick_start
)
boost_geometry_add_example("example" ${item})
endforeach()

add_subdirectory(algorithms)
add_subdirectory(core)
add_subdirectory(geometries)
add_subdirectory(io)
add_subdirectory(strategies)
add_subdirectory(views)
73 changes: 73 additions & 0 deletions doc/src/examples/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Boost.Geometry
# Copyright (c) 2024 Barend Gehrels, Amsterdam, the Netherlands.
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

foreach(item IN ITEMS
append
area
area_with_strategy
assign
assign_2d_point
assign_3d_point
assign_inverse
assign_points
buffer_with_strategies
centroid
clear
closest_points
closest_points_strategy
comparable_distance
convert
convex_hull
correct
densify
densify_strategy
discrete_frechet_distance
discrete_frechet_distance_strategy
discrete_hausdorff_distance
discrete_hausdorff_distance_strategy
difference
distance
envelope
equals
expand
for_each_point
for_each_point_const
for_each_segment_const
intersection_ls_ls_point
intersection_segment
intersects_linestring
is_simple
is_valid
is_valid_failure
is_valid_message
length
length_with_strategy
line_interpolate
line_interpolate_strategy
make_2d_point
make_3d_point
make_inverse
num_geometries
num_interior_rings
num_points
num_segments
return_envelope
relate
relation
reverse
simplify
sym_difference
transform
transform_with_strategy
union
unique
within
)

boost_geometry_add_example("algorithms" ${item})

endforeach()

18 changes: 8 additions & 10 deletions doc/src/examples/algorithms/append.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -16,32 +16,30 @@
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>

#include <boost/assign.hpp> /*< At the end to avoid conflicts with Boost.QVM >*/

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

int main()
{
using boost::assign::tuple_list_of;
using boost::make_tuple;
using boost::geometry::append;

typedef boost::geometry::model::polygon<boost::tuple<int, int> > polygon;
using vector = std::vector<boost::tuple<int, int>>;
using polygon = boost::geometry::model::polygon<boost::tuple<int, int>>;

polygon poly;

// Append a range
append(poly, tuple_list_of(0, 0)(0, 10)(11, 11)(10, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::append >*/
append(poly, vector{{0.0, 0.0}, {0.0, 10.0}, {11.0, 11.0}, {10.0, 0.0}}); /*< vector models a range and can therefore be used in boost::geometry::append >*/
// Append a point (in this case the closing point)
append(poly, make_tuple(0, 0));
append(poly, boost::make_tuple(0, 0));

// Create an interior ring (append does not do this automatically)
boost::geometry::interior_rings(poly).resize(1);

// Append a range to the interior ring
append(poly, tuple_list_of(2, 2)(2, 5)(6, 6)(5, 2), 0); /*< The last parameter ring_index 0 denotes the first interior ring >*/
append(poly, vector{{2, 2}, {2, 5}, {6, 6}, {5, 2}}, 0); /*< The last parameter ring_index 0 denotes the first interior ring >*/

// Append a point to the first interior ring
append(poly, make_tuple(2, 2), 0);
append(poly, boost::make_tuple(2, 2), 0);

std::cout << boost::geometry::dsv(poly) << std::endl;

Expand Down
4 changes: 2 additions & 2 deletions doc/src/examples/algorithms/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ namespace bg = boost::geometry; /*< Convenient namespace alias >*/
int main()
{
// Calculate the area of a cartesian polygon
bg::model::polygon<bg::model::d2::point_xy<double> > poly;
bg::model::polygon<bg::model::d2::point_xy<double>> poly;
bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
double area = bg::area(poly);
std::cout << "Area: " << area << std::endl;

// Calculate the area of a spherical equatorial polygon
bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree>>> sph_poly;
bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
area = bg::area(sph_poly);
std::cout << "Area: " << area << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions doc/src/examples/algorithms/area_with_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace bg = boost::geometry; /*< Convenient namespace alias >*/
int main()
{
// Create spherical polygon
bg::model::polygon<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
bg::model::polygon<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree>>> sph_poly;
bg::read_wkt("POLYGON((0 0,0 1,1 0,0 0))", sph_poly);

// Create spherical strategy with mean Earth radius in meters
Expand All @@ -36,7 +36,7 @@ int main()
std::cout << "Area: " << area << std::endl;

// Create geographic polygon
bg::model::polygon<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > > geo_poly;
bg::model::polygon<bg::model::point<double, 2, bg::cs::geographic<bg::degree>>> geo_poly;
bg::read_wkt("POLYGON((0 0,0 1,1 0,0 0))", geo_poly);

// Create geographic strategy with WGS84 spheroid
Expand Down
8 changes: 4 additions & 4 deletions doc/src/examples/algorithms/assign.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -22,9 +22,9 @@ BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

int main()
{
typedef boost::geometry::model::d2::point_xy<double> point;
typedef boost::geometry::model::box<point> box;
typedef boost::geometry::model::polygon<point> polygon;
using point = boost::geometry::model::d2::point_xy<double>;
using box = boost::geometry::model::box<point>;
using polygon = boost::geometry::model::polygon<point>;

point p1;
box b;
Expand Down
6 changes: 3 additions & 3 deletions doc/src/examples/algorithms/assign_box_corners.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -20,8 +20,8 @@ using namespace boost::geometry;

int main()
{
typedef model::d2::point_xy<double> point;
typedef model::box<point> box;
using point = model::d2::point_xy<double>;
using box = model::box<point>;

box b;
assign_values(b, 2, 2, 5, 5);
Expand Down
6 changes: 3 additions & 3 deletions doc/src/examples/algorithms/assign_inverse.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -20,8 +20,8 @@ using namespace boost::geometry;

int main()
{
typedef model::point<float, 3, cs::cartesian> point;
typedef model::box<point> box;
using point = model::point<float, 3, cs::cartesian>;
using box = model::box<point>;

box all;
assign_inverse(all);
Expand Down
6 changes: 3 additions & 3 deletions doc/src/examples/algorithms/assign_point_from_index.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -20,8 +20,8 @@ using namespace boost::geometry;

int main()
{
typedef model::d2::point_xy<double> point;
typedef model::segment<point> segment;
using point = model::d2::point_xy<double>;
using segment = model::segment<point>;

segment s;
assign_values(s, 1, 1, 2, 2);
Expand Down
6 changes: 3 additions & 3 deletions doc/src/examples/algorithms/assign_point_to_index.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -20,8 +20,8 @@ using namespace boost::geometry;

int main()
{
typedef model::d2::point_xy<int> point;
typedef model::box<point> box;
using point = model::d2::point_xy<int>;
using box = model::box<point>;

point lower_left(0, 0), upper_right(2, 2);

Expand Down
13 changes: 5 additions & 8 deletions doc/src/examples/algorithms/assign_points.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//[assign_points
//` Shows usage of Boost.Geometry's assign, Boost.Assign, and Boost.Range to assign ranges of a linestring
//` Shows usage of Boost.Geometry's assign, and Boost.Range to assign ranges of a linestring

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>

#include <boost/assign.hpp>
#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
Expand All @@ -41,14 +40,12 @@ private :

int main()
{
using namespace boost::assign;

typedef boost::geometry::model::linestring<boost::tuple<int, int> > ls;
using ls = boost::geometry::model::linestring<boost::tuple<int, int>>;

ls line1, line2, line3;

line1 = tuple_list_of(0, 0)(2, 3)(4, 0)(6, 3)(8, 0)(10, 3)(12, 0); /*< tuple_list_of is part of Boost.Assign and can be used for Boost.Geometry if points are tuples >*/
boost::geometry::assign_points(line2, tuple_list_of(0, 0)(2, 2)(4, 0)(6, 2)(8, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::assign >*/
line1 = {{0, 0}, {2, 3}, {4, 0}, {6, 3}, {8, 0}, {10, 3}, {12, 0}};
boost::geometry::assign_points(line2, ls({{0, 0}, {2, 2}, {4, 0}, {6, 2}, {8, 0}}));
boost::geometry::assign_points(line3, line1 | boost::adaptors::filtered(x_between<int>(4, 8))); /*< Boost.Range adaptors can also be used in boost::geometry::assign >*/

std::cout << "line 1: " << boost::geometry::dsv(line1) << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion doc/src/examples/algorithms/azimuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

int main()
{
typedef boost::geometry::model::d2::point_xy<double> point_type;
using point_type = boost::geometry::model::d2::point_xy<double>;

point_type p1(0, 0);
point_type p2(1, 1);
Expand Down
2 changes: 1 addition & 1 deletion doc/src/examples/algorithms/azimuth_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
int main()
{
namespace bg = boost::geometry;
typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type;
using point_type = bg::model::point<double, 2, bg::cs::geographic<bg::degree>>;

point_type p1(0, 0);
point_type p2(1, 1);
Expand Down
8 changes: 4 additions & 4 deletions doc/src/examples/algorithms/buffer_with_strategies.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2013, 2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013, 2024 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -17,9 +17,9 @@

int main()
{
typedef double coordinate_type;
typedef boost::geometry::model::d2::point_xy<coordinate_type> point;
typedef boost::geometry::model::polygon<point> polygon;
using coordinate_type = double;
using point = boost::geometry::model::d2::point_xy<coordinate_type>;
using polygon = boost::geometry::model::polygon<point>;

// Declare strategies
const double buffer_distance = 1.0;
Expand Down
Loading

0 comments on commit 38adce6

Please sign in to comment.