diff options
Diffstat (limited to 'libs/geometry/doc/src/examples')
104 files changed, 5643 insertions, 0 deletions
diff --git a/libs/geometry/doc/src/examples/Jamfile.v2 b/libs/geometry/doc/src/examples/Jamfile.v2 new file mode 100644 index 000000000..faddc32a5 --- /dev/null +++ b/libs/geometry/doc/src/examples/Jamfile.v2 @@ -0,0 +1,21 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-src-example + : # requirements + ; + +exe quick_start : quick_start.cpp ; + +build-project algorithms ; +build-project core ; +build-project geometries ; +build-project views ; diff --git a/libs/geometry/doc/src/examples/algorithms/Jamfile.v2 b/libs/geometry/doc/src/examples/algorithms/Jamfile.v2 new file mode 100644 index 000000000..6adad2105 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/Jamfile.v2 @@ -0,0 +1,78 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-example-algorithms + : # requirements + ; + +exe append : append.cpp ; + +exe area : area.cpp ; +exe area_with_strategy : area_with_strategy.cpp ; + +exe assign : assign.cpp ; +exe assign_2d_point : assign_2d_point.cpp ; +exe assign_3d_point : assign_3d_point.cpp ; +exe assign_inverse : assign_inverse.cpp ; +exe assign_points : assign_points.cpp ; +# exe assign_box_corners : assign_box_corners.cpp ; +# exe assign_point_from_index : assign_point_from_index.cpp ; +# exe assign_point_to_index : assign_point_to_index.cpp ; + +exe centroid : centroid.cpp ; +exe clear : clear.cpp ; +exe comparable_distance : comparable_distance.cpp ; +exe convert : convert.cpp ; +exe convex_hull : convex_hull.cpp ; +exe correct : correct.cpp ; + +exe difference : difference.cpp ; +exe distance : distance.cpp ; + +exe envelope : envelope.cpp ; +exe equals : equals.cpp ; +exe expand : expand.cpp ; + +exe for_each_point : for_each_point.cpp ; +exe for_each_point_const : for_each_point_const.cpp ; +exe for_each_segment_const : for_each_segment_const.cpp ; + +exe intersection_ls_ls_point : intersection_ls_ls_point.cpp ; +exe intersection_segment : intersection_segment.cpp ; + +exe intersects_linestring : intersects_linestring.cpp ; + +exe length : length.cpp ; +exe length_with_strategy : length_with_strategy.cpp ; + +exe make_2d_point : make_2d_point.cpp ; +exe make_3d_point : make_3d_point.cpp ; +exe make_inverse : make_inverse.cpp ; +# exe make_with_range : make_with_range.cpp ; + +exe num_geometries : num_geometries.cpp ; +exe num_interior_rings : num_interior_rings.cpp ; +exe num_points : num_points.cpp ; + +exe return_envelope : return_envelope.cpp ; + +exe reverse : reverse.cpp ; + +exe simplify : length.cpp ; +exe sym_difference : sym_difference.cpp ; + +exe transform : transform.cpp ; +exe transform_with_strategy : transform_with_strategy.cpp ; + +exe union : union.cpp ; +exe unique : unique.cpp ; + +exe within : within.cpp ; diff --git a/libs/geometry/doc/src/examples/algorithms/append.cpp b/libs/geometry/doc/src/examples/algorithms/append.cpp new file mode 100644 index 000000000..f5a3085b5 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/append.cpp @@ -0,0 +1,61 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[append +//` Shows usage of Boost.Geometry's append to append a point or a range to a polygon + +#include <iostream> + +#include <boost/assign.hpp> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +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; + + 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 a point (in this case the closing point) + append(poly, 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 a point to the first interior ring + append(poly, make_tuple(2, 2), 0); + + std::cout << boost::geometry::dsv(poly) << std::endl; + + return 0; +} + +//] + + +//[append_output +/*` +Output: +[pre +(((0, 0), (0, 10), (11, 11), (10, 0), (0, 0)), ((2, 2), (2, 5), (6, 6), (5, 2), (2, 2))) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/area.cpp b/libs/geometry/doc/src/examples/algorithms/area.cpp new file mode 100644 index 000000000..5816db719 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/area.cpp @@ -0,0 +1,50 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[area +//` Calculate the area of a polygon + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +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::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::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly); + area = bg::area(sph_poly); + std::cout << "Area: " << area << std::endl; + + return 0; +} + +//] + + +//[area_output +/*` +Output: +[pre +Area: 16 +Area: 0.339837 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp b/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp new file mode 100644 index 000000000..c0a7bfc18 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/area_with_strategy.cpp @@ -0,0 +1,50 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[area_with_strategy +//` Calculate the area of a polygon + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +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::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 polygon (for latitude: 0 at equator) + 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; + + return 0; +} + +//] + + +//[area_with_strategy_output +/*` +Output: +[pre +Area: 16 +Area: 0.339837 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign.cpp b/libs/geometry/doc/src/examples/algorithms/assign.cpp new file mode 100644 index 000000000..857eebb34 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign.cpp @@ -0,0 +1,66 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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 +//` Shows how to assign a geometry from another geometry + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +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; + + point p1; + box b; + boost::geometry::assign_values(p1, 1, 1); + boost::geometry::assign_values(b, 1, 1, 2, 2); + + // Assign a box to a polygon (target = source) + polygon p; + boost::geometry::assign(p, b); + + // Assign a point to another point type (conversion of point-type) + boost::tuple<double, double> p2; + boost::geometry::assign(p2, p1); + + using boost::geometry::dsv; + std::cout + << "box: " << dsv(b) << std::endl + << "polygon: " << dsv(p) << std::endl + << "point: " << dsv(p1) << std::endl + << "point tuples: " << dsv(p2) << std::endl + ; + + return 0; +} + +//] + + +//[assign_output +/*` +Output: +[pre +box: ((1, 1), (2, 2)) +polygon: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))) +point: (1, 1) +point tuples: (1, 1) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp b/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp new file mode 100644 index 000000000..b03dc0519 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp @@ -0,0 +1,62 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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_2d_point +//` Shows the usage of assign to set point coordinates, and, besides that, shows how you can initialize ttmath points with high precision + +#include <iostream> +#include <iomanip> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#if defined(HAVE_TTMATH) +# include <boost/geometry/extensions/contrib/ttmath_stub.hpp> +#endif + + +int main() +{ + using boost::geometry::assign_values; + + + boost::geometry::model::d2::point_xy<double> p1; + assign_values(p1, 1.2345, 2.3456); + +#if defined(HAVE_TTMATH) + boost::geometry::model::d2::point_xy<ttmath::Big<1,4> > p2; + assign_values(p2, "1.2345", "2.3456"); /*< It is possible to assign coordinates with other types than the coordinate type. + For ttmath, you can e.g. conveniently use strings. The advantage is that it then has higher precision, because + if doubles are used for assignments the double-precision is used. + >*/ +#endif + + std::cout + << std::setprecision(20) + << boost::geometry::dsv(p1) << std::endl +#if defined(HAVE_TTMATH) + << boost::geometry::dsv(p2) << std::endl +#endif + ; + + return 0; +} + +//] + + +//[assign_2d_point_output +/*` +Output: +[pre +(1.2344999999999999, 2.3456000000000001) +(1.2345, 2.3456) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp b/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp new file mode 100644 index 000000000..9475416e7 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_3d_point.cpp @@ -0,0 +1,39 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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_3d_point +//` Use assign to set three coordinates of a 3D point + +#include <iostream> +#include <iomanip> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point.hpp> + +int main() +{ + boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> p; + boost::geometry::assign_values(p, 1.2345, 2.3456, 3.4567); + + std::cout << boost::geometry::dsv(p) << std::endl; + + return 0; +} + +//] + + +//[assign_3d_point_output +/*` +Output: +[pre +(1.2345, 2.3456, 3.4567) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_box_corners.cpp b/libs/geometry/doc/src/examples/algorithms/assign_box_corners.cpp new file mode 100644 index 000000000..9d3e9f3b2 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_box_corners.cpp @@ -0,0 +1,60 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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_box_corners +//` Shows how four point can be assigned from a 2D box + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +using namespace boost::geometry; + +int main() +{ + typedef model::d2::point_xy<double> point; + typedef model::box<point> box; + + box b; + assign_values(b, 2, 2, 5, 5); + + point ll, lr, ul, ur; + assign_box_corners(b, ll, lr, ul, ur); + + std::cout << "box: " << dsv(b) << std::endl << std::endl; + + std::cout << dsv(ul) << " --- " << dsv(ur) << std::endl; + for (int i = 0; i < 3; i++) + { + std::cout << " | |" << std::endl; + } + std::cout << dsv(ll) << " --- " << dsv(lr) << std::endl; + + return 0; +} + +//] + + +//[assign_box_corners_output +/*` +Output: +[pre +box: ((2, 2), (5, 5)) + +(2, 5) --- (5, 5) + | | + | | + | | +(2, 2) --- (5, 2) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_inverse.cpp b/libs/geometry/doc/src/examples/algorithms/assign_inverse.cpp new file mode 100644 index 000000000..3390ac1b8 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_inverse.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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_inverse +//` Usage of assign_inverse and expand to conveniently determine bounding 3D box of two points + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point.hpp> + +using namespace boost::geometry; + +int main() +{ + typedef model::point<float, 3, cs::cartesian> point; + typedef model::box<point> box; + + box all; + assign_inverse(all); + std::cout << dsv(all) << std::endl; + expand(all, point(0, 0, 0)); + expand(all, point(1, 2, 3)); + std::cout << dsv(all) << std::endl; + + return 0; +} + +//] + + +//[assign_inverse_output +/*` +Output: +[pre +((3.40282e+038, 3.40282e+038, 3.40282e+038), (-3.40282e+038, -3.40282e+038, -3.40282e+038)) +((0, 0, 0), (1, 2, 3))] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp b/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp new file mode 100644 index 000000000..6bcc89d83 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_point_from_index.cpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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_point_from_index +//` Shows how to retrieve one point from a box (either lower-left or upper-right) or segment + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/segment.hpp> + +using namespace boost::geometry; + +int main() +{ + typedef model::d2::point_xy<double> point; + typedef model::segment<point> segment; + + segment s; + assign_values(s, 1, 1, 2, 2); + + point first, second; + assign_point_from_index<0>(s, first); + assign_point_from_index<1>(s, second); + std::cout + << "segment: " << dsv(s) << std::endl + << "first: " << dsv(first) << std::endl + << "second: " << dsv(second) << std::endl; + + return 0; +} + +//] + + +//[assign_point_from_index_output +/*` +Output: +[pre +segment: ((1, 1), (2, 2)) +first: (1, 1) +second: (2, 2) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_point_to_index.cpp b/libs/geometry/doc/src/examples/algorithms/assign_point_to_index.cpp new file mode 100644 index 000000000..450d3c61f --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_point_to_index.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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_point_to_index +//` Shows how to assign the lower-left or upper-right point from a box + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +using namespace boost::geometry; + +int main() +{ + typedef model::d2::point_xy<int> point; + typedef model::box<point> box; + + point lower_left(0, 0), upper_right(2, 2); + + box b; + assign_point_to_index<0>(lower_left, b); + assign_point_to_index<1>(upper_right, b); + std::cout << "box: " << dsv(b) << std::endl; + + return 0; +} + +//] + + +//[assign_point_to_index_output +/*` +Output: +[pre +box: ((0, 0), (2, 2)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/assign_points.cpp b/libs/geometry/doc/src/examples/algorithms/assign_points.cpp new file mode 100644 index 000000000..9ec1df019 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/assign_points.cpp @@ -0,0 +1,73 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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 + +#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) + +template <typename T> +struct x_between +{ + x_between(T a, T b) + : fa(a), fb(b) + {} + + template <typename P> + bool operator()(P const& p) const + { + return boost::geometry::get<0>(p) >= fa + && boost::geometry::get<0>(p) <= fb; + } +private : + T fa, fb; +}; + + +int main() +{ + using namespace boost::assign; + + typedef boost::geometry::model::linestring<boost::tuple<int, int> > ls; + + 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 >*/ + 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; + std::cout << "line 2: " << boost::geometry::dsv(line2) << std::endl; + std::cout << "line 3: " << boost::geometry::dsv(line3) << std::endl; + + return 0; +} + +//] + + +//[assign_points_output +/*` +Output: +[pre +line 1: ((0, 0), (2, 3), (4, 0), (6, 3), (8, 0), (10, 3), (12, 0)) +line 2: ((0, 0), (2, 2), (4, 0), (6, 2), (8, 0)) +line 3: ((4, 0), (6, 3), (8, 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/centroid.cpp b/libs/geometry/doc/src/examples/algorithms/centroid.cpp new file mode 100644 index 000000000..2e6c8d761 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/centroid.cpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[centroid +//` Shows calculation of a centroid of a polygon + +#include <iostream> +#include <list> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> +/*<-*/ #include "create_svg_two.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + + polygon_type poly; + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly); + + point_type p; + boost::geometry::centroid(poly, p); + + std::cout << "centroid: " << boost::geometry::dsv(p) << std::endl; + /*<-*/ create_svg("centroid.svg", poly, p); /*->*/ + return 0; +} + +//] + +//[centroid_output +/*` +Output: +[pre +centroid: (4.04663, 1.6349) +[$img/algorithms/centroid.png] +] +Note that the centroid might be located in a hole or outside a polygon, easily. +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/clear.cpp b/libs/geometry/doc/src/examples/algorithms/clear.cpp new file mode 100644 index 000000000..da41711a8 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/clear.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[clear +//` Shows how to clear a ring or polygon + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +#include <boost/assign.hpp> + +int main() +{ + using boost::assign::tuple_list_of; + + typedef boost::tuple<float, float> point; + typedef boost::geometry::model::polygon<point> polygon; + typedef boost::geometry::model::ring<point> ring; + + polygon poly; + + // Fill the polygon (using its own methods + Boost.Assign) + poly.outer() = tuple_list_of(0, 0)(0, 9)(10, 10)(0, 0); + poly.inners().push_back(tuple_list_of(1, 2)(4, 6)(2, 8)(1, 2)); + + std::cout << boost::geometry::dsv(poly) << std::endl; + boost::geometry::clear(poly); + std::cout << boost::geometry::dsv(poly) << std::endl; + + // Create a ring using Boost.Assign + ring r = tuple_list_of(0, 0)(0, 9)(8, 8)(0, 0); + + std::cout << boost::geometry::dsv(r) << std::endl; + boost::geometry::clear(r); + std::cout << boost::geometry::dsv(r) << std::endl; + + return 0; +} + +//] + + +//[clear_output +/*` +Output: +[pre +(((0, 0), (0, 10), (11, 11), (0, 0)), ((0, 0), (0, 10), (11, 11), (0, 0))) +(()) +((0, 0), (0, 9), (8, 8), (0, 0)) +() +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/comparable_distance.cpp b/libs/geometry/doc/src/examples/algorithms/comparable_distance.cpp new file mode 100644 index 000000000..87b5100ce --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/comparable_distance.cpp @@ -0,0 +1,67 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[comparable_distance +//` Shows how to efficiently get the closest point + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#include <boost/numeric/conversion/bounds.hpp> +#include <boost/foreach.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + + point_type p(1.4, 2.6); + + std::vector<point_type> v; + for (double x = 0.0; x <= 4.0; x++) + { + for (double y = 0.0; y <= 4.0; y++) + { + v.push_back(point_type(x, y)); + } + } + + point_type min_p; + double min_d = boost::numeric::bounds<double>::highest(); + BOOST_FOREACH(point_type const& pv, v) + { + double d = boost::geometry::comparable_distance(p, pv); + if (d < min_d) + { + min_d = d; + min_p = pv; + } + } + + std::cout + << "Closest: " << boost::geometry::dsv(min_p) << std::endl + << "At: " << boost::geometry::distance(p, min_p) << std::endl; + + return 0; +} + +//] + + +//[comparable_distance_output +/*` +Output: +[pre +Closest: (1, 3) +At: 0.565685 +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/convert.cpp b/libs/geometry/doc/src/examples/algorithms/convert.cpp new file mode 100644 index 000000000..6d43fd4d8 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/convert.cpp @@ -0,0 +1,64 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[convert +//` Shows how to convert a geometry into another geometry + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +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; + + point p1(1, 1); + box bx = boost::geometry::make<box>(1, 1, 2, 2); + + // Assign a box to a polygon (conversion box->poly) + polygon poly; + boost::geometry::convert(bx, poly); + + // Convert a point to another point type (conversion of point-type) + boost::tuple<double, double> p2; + boost::geometry::convert(p1, p2); // source -> target + + using boost::geometry::dsv; + std::cout + << "box: " << dsv(bx) << std::endl + << "polygon: " << dsv(poly) << std::endl + << "point: " << dsv(p1) << std::endl + << "point tuples: " << dsv(p2) << std::endl + ; + + return 0; +} + +//] + + +//[convert_output +/*` +Output: +[pre +box: ((1, 1), (2, 2)) +polygon: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))) +point: (1, 1) +point tuples: (1, 1) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/convex_hull.cpp b/libs/geometry/doc/src/examples/algorithms/convex_hull.cpp new file mode 100644 index 000000000..2d9394f73 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/convex_hull.cpp @@ -0,0 +1,57 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[convex_hull +//` Shows how to generate the convex_hull of a geometry + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +/*<-*/ #include "create_svg_two.hpp" /*->*/ +int main() +{ + typedef boost::tuple<double, double> point; + typedef boost::geometry::model::polygon<point> polygon; + + polygon poly; + boost::geometry::read_wkt("polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0" + ", 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))", poly); + + polygon hull; + boost::geometry::convex_hull(poly, hull); + + using boost::geometry::dsv; + std::cout + << "polygon: " << dsv(poly) << std::endl + << "hull: " << dsv(hull) << std::endl + ; + + /*<-*/ create_svg("hull.svg", poly, hull); /*->*/ + return 0; +} + +//] + + +//[convex_hull_output +/*` +Output: +[pre +polygon: (((2, 1.3), (2.4, 1.7), (2.8, 1.8), (3.4, 1.2), (3.7, 1.6), (3.4, 2), (4.1, 3), (5.3, 2.6), (5.4, 1.2), (4.9, 0.8), (2.9, 0.7), (2, 1.3))) +hull: (((2, 1.3), (2.4, 1.7), (4.1, 3), (5.3, 2.6), (5.4, 1.2), (4.9, 0.8), (2.9, 0.7), (2, 1.3))) + +[$img/algorithms/convex_hull.png] +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/correct.cpp b/libs/geometry/doc/src/examples/algorithms/correct.cpp new file mode 100644 index 000000000..c33ace9ae --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/correct.cpp @@ -0,0 +1,68 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[correct +//` Shows how to correct a polygon with respect to its orientation and closure + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +#include <boost/assign.hpp> + +int main() +{ + using boost::assign::tuple_list_of; + + typedef boost::geometry::model::polygon + < + boost::tuple<int, int> + > clockwise_closed_polygon; + + clockwise_closed_polygon cwcp; + + // Fill it counterclockwise (so wrongly), forgetting the closing point + boost::geometry::exterior_ring(cwcp) = tuple_list_of(0, 0)(10, 10)(0, 9); + + // Add a counterclockwise closed inner ring (this is correct) + boost::geometry::interior_rings(cwcp).push_back(tuple_list_of(1, 2)(4, 6)(2, 8)(1, 2)); + + // Its area should be negative (because of wrong orientation) + // and wrong (because of omitted closing point) + double area_before = boost::geometry::area(cwcp); + + // Correct it! + boost::geometry::correct(cwcp); + + // Check its new area + double area_after = boost::geometry::area(cwcp); + + // And output it + std::cout << boost::geometry::dsv(cwcp) << std::endl; + std::cout << area_before << " -> " << area_after << std::endl; + + return 0; +} + +//] + + +//[correct_output +/*` +Output: +[pre +(((0, 0), (0, 9), (10, 10), (0, 0)), ((1, 2), (4, 6), (2, 8), (1, 2))) +-7 -> 38 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp b/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp new file mode 100644 index 000000000..53d81d6d6 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp @@ -0,0 +1,60 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2011-2012 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) + +// Code to create SVG for examples + +#ifndef CREATE_SVG_OVERLAY_HPP +#define CREATE_SVG_OVERLAY_HPP + +#include <fstream> + +#include <boost/foreach.hpp> +#include <boost/algorithm/string.hpp> + +#if defined(HAVE_SVG) +# include <boost/geometry/io/svg/svg_mapper.hpp> +#endif + +template <typename Geometry, typename Range> +void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range) +{ +#if defined(HAVE_SVG) + std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl; + + typedef typename boost::geometry::point_type<Geometry>::type point_type; + std::ofstream svg(filename.c_str()); + + boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400); + mapper.add(a); + mapper.add(b); + + mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2"); + mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2"); + int i = 0; + BOOST_FOREACH(typename boost::range_value<Range>::type const& g, range) + { + mapper.map(g, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round"); + std::ostringstream out; + out << i++; + mapper.text(boost::geometry::return_centroid<point_type>(g), out.str(), + "fill:rgb(0,0,0);font-family:Arial;font-size:10px"); + } +#else + boost::ignore_unused_variable_warning(filename); + boost::ignore_unused_variable_warning(a); + boost::ignore_unused_variable_warning(b); + boost::ignore_unused_variable_warning(range); +#endif +} + +// NOTE: convert manually from svg to png using Inkscape ctrl-shift-E +// and copy png to html/img/algorithms/ + + +#endif // CREATE_SVG_OVERLAY_HPP + diff --git a/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp b/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp new file mode 100644 index 000000000..6dbdb60d9 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp @@ -0,0 +1,55 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2011-2012 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) + +// Code to create SVG for examples + +#ifndef CREATE_SVG_TWO_HPP +#define CREATE_SVG_TWO_HPP + +#include <fstream> +#include <boost/algorithm/string.hpp> + +#if defined(HAVE_SVG) +# include <boost/geometry/io/svg/svg_mapper.hpp> +#endif + +template <typename Geometry1, typename Geometry2> +void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b) +{ +#if defined(HAVE_SVG) + std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl; + + typedef typename boost::geometry::point_type<Geometry1>::type point_type; + std::ofstream svg(filename.c_str()); + + boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400); + mapper.add(a); + mapper.add(b); + + mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2"); + if (boost::geometry::geometry_id<Geometry2>::value == 1) + { + mapper.map(b, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1"); + } + else + { + mapper.map(b, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round"); + } +#else + boost::ignore_unused_variable_warning(filename); + boost::ignore_unused_variable_warning(a); + boost::ignore_unused_variable_warning(b); +#endif +} + +// NOTE: convert manually from svg to png using Inkscape ctrl-shift-E +// and copy png to html/img/algorithms/ + + +#endif // CREATE_SVG_TWO_HPP + diff --git a/libs/geometry/doc/src/examples/algorithms/difference.cpp b/libs/geometry/doc/src/examples/algorithms/difference.cpp new file mode 100644 index 000000000..77c935de9 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/difference.cpp @@ -0,0 +1,90 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[difference +//` Shows how to subtract one polygon from another polygon + +#include <iostream> +#include <list> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> +/*<-*/ #include "create_svg_overlay.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; + + polygon green, blue; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green); + + boost::geometry::read_wkt( + "POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue); + + std::list<polygon> output; + boost::geometry::difference(green, blue, output); + + int i = 0; + std::cout << "green - blue:" << std::endl; + BOOST_FOREACH(polygon const& p, output) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("difference_a.svg", green, blue, output); /*->*/ + output.clear(); + boost::geometry::difference(blue, green, output); + + i = 0; + std::cout << "blue - green:" << std::endl; + BOOST_FOREACH(polygon const& p, output) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("difference_b.svg", green, blue, output); /*->*/ + return 0; +} + +//] + + +//[difference_output +/*` +Output: +[pre +green - blue: +0: 0.02375 +1: 0.542951 +2: 0.0149697 +3: 0.226855 +4: 0.839424 + +[$img/algorithms/difference_a.png] + +blue - green: +0: 0.525154 +1: 0.015 +2: 0.181136 +3: 0.128798 +4: 0.340083 +5: 0.307778 + +[$img/algorithms/difference_b.png] +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/difference_inserter.cpp b/libs/geometry/doc/src/examples/algorithms/difference_inserter.cpp new file mode 100644 index 000000000..5ba4d0c23 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/difference_inserter.cpp @@ -0,0 +1,88 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[difference_inserter +//` Shows how the difference_inserter function can be used + +#include <iostream> +#include <vector> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> +/*<-*/ #include "create_svg_overlay.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; + + polygon green, blue; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green); + + boost::geometry::read_wkt( + "POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue); + + std::vector<polygon> output; + + // Note that this sample simulates the symmetric difference, + // which is also available as a separate algorithm. + // It chains the output iterator returned by the function to the second instance. + boost::geometry::difference_inserter<polygon> + ( + green, blue, + boost::geometry::difference_inserter<polygon> + ( + blue, green, + std::back_inserter(output) + ) + ); + + + int i = 0; + std::cout << "(blue \ green) u (green \ blue):" << std::endl; + BOOST_FOREACH(polygon const& p, output) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("difference_inserter.svg", green, blue, output); /*->*/ + return 0; +} + +//] + + +//[difference_inserter_output +/*` +Output: +[pre +(blue \\ green) u (green \\ blue): +0: 0.525154 +1: 0.015 +2: 0.181136 +3: 0.128798 +4: 0.340083 +5: 0.307778 +6: 0.02375 +7: 0.542951 +8: 0.0149697 +9: 0.226855 +10: 0.839424 + +[$img/algorithms/sym_difference.png] + +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/distance.cpp b/libs/geometry/doc/src/examples/algorithms/distance.cpp new file mode 100644 index 000000000..89a629641 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/distance.cpp @@ -0,0 +1,68 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[distance +//` Shows calculation of distance of point to some other geometries + +#include <iostream> +#include <list> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/multi/geometries/multi_point.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + typedef boost::geometry::model::linestring<point_type> linestring_type; + typedef boost::geometry::model::multi_point<point_type> multi_point_type; + + point_type p(1,2); + polygon_type poly; + linestring_type line; + multi_point_type mp; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly); + line.push_back(point_type(0,0)); + line.push_back(point_type(0,3)); + mp.push_back(point_type(0,0)); + mp.push_back(point_type(3,3)); + + std::cout + << "Point-Poly: " << boost::geometry::distance(p, poly) << std::endl + << "Point-Line: " << boost::geometry::distance(p, line) << std::endl + << "Point-MultiPoint: " << boost::geometry::distance(p, mp) << std::endl; + + return 0; +} + +//] + + +//[distance_output +/*` +Output: +[pre +Point-Poly: 1.22066 +Point-Line: 1 +Point-MultiPoint: 2.23607 +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/envelope.cpp b/libs/geometry/doc/src/examples/algorithms/envelope.cpp new file mode 100644 index 000000000..1a3c6e454 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/envelope.cpp @@ -0,0 +1,55 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[envelope +//` Shows how to calculate the bounding box of a polygon + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +/*<-*/ #include "create_svg_two.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point; + + boost::geometry::model::polygon<point> polygon; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", polygon); + + boost::geometry::model::box<point> box; + boost::geometry::envelope(polygon, box); + + std::cout << "envelope:" << boost::geometry::dsv(box) << std::endl; + + /*<-*/ create_svg("envelope.svg", polygon, box); /*->*/ + return 0; +} + +//] + + +//[envelope_output +/*` +Output: +[pre +envelope:((2, 0.7), (5.4, 3)) + +[$img/algorithms/envelope.png] +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/equals.cpp b/libs/geometry/doc/src/examples/algorithms/equals.cpp new file mode 100644 index 000000000..fe2836a48 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/equals.cpp @@ -0,0 +1,61 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[equals +//` Shows the predicate equals, which returns true if two geometries are spatially equal + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +#include <boost/assign.hpp> + +int main() +{ + using boost::assign::tuple_list_of; + + typedef boost::tuple<int, int> point; + + boost::geometry::model::polygon<point> poly1, poly2; + boost::geometry::exterior_ring(poly1) = tuple_list_of(0, 0)(0, 5)(5, 5)(5, 0)(0, 0); + boost::geometry::exterior_ring(poly2) = tuple_list_of(5, 0)(0, 0)(0, 5)(5, 5)(5, 0); + + std::cout + << "polygons are spatially " + << (boost::geometry::equals(poly1, poly2) ? "equal" : "not equal") + << std::endl; + + boost::geometry::model::box<point> box; + boost::geometry::assign_values(box, 0, 0, 5, 5); + + std::cout + << "polygon and box are spatially " + << (boost::geometry::equals(box, poly2) ? "equal" : "not equal") + << std::endl; + + + return 0; +} + +//] + + +//[equals_output +/*` +Output: +[pre +polygons are spatially equal +polygon and box are spatially equal +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/expand.cpp b/libs/geometry/doc/src/examples/algorithms/expand.cpp new file mode 100644 index 000000000..cba03b247 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/expand.cpp @@ -0,0 +1,48 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[expand +//` Shows the usage of expand + +#include <iostream> +#include <list> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<short int> point_type; + typedef boost::geometry::model::box<point_type> box_type; + + using boost::geometry::expand; + + box_type box = boost::geometry::make_inverse<box_type>(); /*< expand is usually preceded by a call to assign_inverse or make_inverse >*/ + + expand(box, point_type(0, 0)); + expand(box, point_type(1, 2)); + expand(box, point_type(5, 4)); + expand(box, boost::geometry::make<box_type>(3, 3, 5, 5)); + + std::cout << boost::geometry::dsv(box) << std::endl; + + return 0; +} + +//] + +//[expand_output +/*` +Output: +[pre +((0, 0), (5, 5)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/for_each_point.cpp b/libs/geometry/doc/src/examples/algorithms/for_each_point.cpp new file mode 100644 index 000000000..86547c940 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/for_each_point.cpp @@ -0,0 +1,69 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[for_each_point +//` Convenient usage of for_each_point, rounding all points of a geometry + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + + + +template <typename Point> +class round_coordinates +{ +private : + typedef typename boost::geometry::coordinate_type<Point>::type coordinate_type; + coordinate_type factor; + + inline coordinate_type round(coordinate_type value) + { + return floor(0.5 + (value / factor)) * factor; + } + +public : + round_coordinates(coordinate_type f) + : factor(f) + {} + + inline void operator()(Point& p) + { + using boost::geometry::get; + using boost::geometry::set; + set<0>(p, round(get<0>(p))); + set<1>(p, round(get<1>(p))); + } +}; + + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point; + boost::geometry::model::polygon<point> poly; + boost::geometry::read_wkt("POLYGON((0 0,1.123 9.987,8.876 2.234,0 0),(3.345 4.456,7.654 8.765,9.123 5.432,3.345 4.456))", poly); + boost::geometry::for_each_point(poly, round_coordinates<point>(0.1)); + std::cout << "Rounded: " << boost::geometry::wkt(poly) << std::endl; + return 0; +} + +//] + + +//[for_each_point_output +/*` +Output: +[pre + Rounded: POLYGON((0 0,1.1 10,8.9 2.2,0 0),(3.3 4.5,7.7 8.8,9.1 5.4,3.3 4.5)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/for_each_point_const.cpp b/libs/geometry/doc/src/examples/algorithms/for_each_point_const.cpp new file mode 100644 index 000000000..42c5bf016 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/for_each_point_const.cpp @@ -0,0 +1,50 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[for_each_point_const +//` Sample using for_each_point, using a function to list coordinates + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + + +template <typename Point> +void list_coordinates(Point const& p) +{ + using boost::geometry::get; + std::cout << "x = " << get<0>(p) << " y = " << get<1>(p) << std::endl; +} + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point; + boost::geometry::model::polygon<point> poly; + boost::geometry::read_wkt("POLYGON((0 0,0 4,4 0,0 0))", poly); + boost::geometry::for_each_point(poly, list_coordinates<point>); + return 0; +} + +//] + + +//[for_each_point_const_output +/*` +Output: +[pre +x = 0 y = 0 +x = 0 y = 4 +x = 4 y = 0 +x = 0 y = 0 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/for_each_segment_const.cpp b/libs/geometry/doc/src/examples/algorithms/for_each_segment_const.cpp new file mode 100644 index 000000000..f7296bc76 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/for_each_segment_const.cpp @@ -0,0 +1,95 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[for_each_segment_const +//` Sample using for_each_segment, using a functor to get the minimum and maximum length of a segment in a linestring + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#include <boost/assign.hpp> + + +template <typename Segment> +struct gather_segment_statistics +{ + // Remember that if coordinates are integer, the length might be floating point + // So use "double" for integers. In other cases, use coordinate type + typedef typename boost::geometry::select_most_precise + < + typename boost::geometry::coordinate_type<Segment>::type, + double + >::type type; + + type min_length, max_length; + + // Initialize min and max + gather_segment_statistics() + : min_length(1e38) + , max_length(-1) + {} + + // This operator is called for each segment + inline void operator()(Segment const& s) + { + type length = boost::geometry::length(s); + if (length < min_length) min_length = length; + if (length > max_length) max_length = length; + } +}; + +int main() +{ + // Bring "+=" for a vector into scope + using namespace boost::assign; + + // Define a type + typedef boost::geometry::model::d2::point_xy<double> point; + + // Declare a linestring + boost::geometry::model::linestring<point> polyline; + + // Use Boost.Assign to initialize a linestring + polyline += point(0, 0), point(3, 3), point(5, 1), point(6, 2), + point(8, 0), point(4, -4), point(1, -1), point(3, 2); + + + // Declare the gathering class... + gather_segment_statistics + < + boost::geometry::model::referring_segment<point> + > functor; + + // ... and use it, the essention. + // As also in std::for_each it is a const value, so retrieve it as a return value. + functor = boost::geometry::for_each_segment(polyline, functor); + + // Output the results + std::cout + << "Min segment length: " << functor.min_length << std::endl + << "Max segment length: " << functor.max_length << std::endl; + + return 0; +} + +//] + + +//[for_each_segment_const_output +/*` +Output: +[pre +Min segment length: 1.41421 +Max segment length: 5.65685 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/intersection_ls_ls_point.cpp b/libs/geometry/doc/src/examples/algorithms/intersection_ls_ls_point.cpp new file mode 100644 index 000000000..630c60cd6 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/intersection_ls_ls_point.cpp @@ -0,0 +1,55 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[intersection_ls_ls_point +//` Calculate the intersection of two linestrings + +#include <iostream> +#include <deque> + +#include <boost/geometry.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/linestring.hpp> + +#include <boost/foreach.hpp> + +BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector) + + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> P; + std::vector<P> line1, line2; + boost::geometry::read_wkt("linestring(1 1,2 2,3 1)", line1); + boost::geometry::read_wkt("linestring(1 2,2 1,3 2)", line2); + + std::deque<P> intersection_points; + boost::geometry::intersection(line1, line2, intersection_points); + + BOOST_FOREACH(P const& p, intersection_points) + { + std::cout << " " << boost::geometry::wkt(p); + } + std::cout << std::endl; + + return 0; +} + +//] + + +//[intersection_ls_ls_point_output +/*` +Output: +[pre + POINT(1.5 1.5) POINT(2.5 1.5) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/intersection_poly_poly.cpp b/libs/geometry/doc/src/examples/algorithms/intersection_poly_poly.cpp new file mode 100644 index 000000000..a6034e439 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/intersection_poly_poly.cpp @@ -0,0 +1,66 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[intersection +//` Shows the intersection of two polygons + +#include <iostream> +#include <deque> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> +/*<-*/ #include "create_svg_overlay.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; + + polygon green, blue; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green); + + boost::geometry::read_wkt( + "POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue); + + std::deque<polygon> output; + boost::geometry::intersection(green, blue, output); + + int i = 0; + std::cout << "green && blue:" << std::endl; + BOOST_FOREACH(polygon const& p, output) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("intersection.svg", green, blue, output); /*->*/ + return 0; +} + +//] + + +//[intersection_output +/*` +Output: +[pre +green && blue: +0: 2.50205 + +[$img/algorithms/intersection.png] + +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/intersection_segment.cpp b/libs/geometry/doc/src/examples/algorithms/intersection_segment.cpp new file mode 100644 index 000000000..367b9b4fb --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/intersection_segment.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[intersection_segment +//` Calculate the intersection point (or points) of two segments + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> + + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> P; + boost::geometry::model::segment<P> segment1, segment2; + boost::geometry::read_wkt("linestring(1 1,2 2)", segment1); + boost::geometry::read_wkt("linestring(2 1,1 2)", segment2); + + std::vector<P> intersections; + boost::geometry::intersection(segment1, segment2, intersections); + + BOOST_FOREACH(P const& p, intersections) + { + std::cout << " " << boost::geometry::wkt(p); + } + std::cout << std::endl; + + return 0; +} + +//] + + +//[intersection_segment_output +/*` +Output: +[pre + POINT(1.5 1.5) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/intersects_linestring.cpp b/libs/geometry/doc/src/examples/algorithms/intersects_linestring.cpp new file mode 100644 index 000000000..ec8dd89dd --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/intersects_linestring.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[intersects_linestring +//` Check if two linestrings intersect each other + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +int main() +{ + // Calculate the intersects of a cartesian polygon + typedef boost::geometry::model::d2::point_xy<double> P; + boost::geometry::model::linestring<P> line1, line2; + + boost::geometry::read_wkt("linestring(1 1,2 2,3 3)", line1); + boost::geometry::read_wkt("linestring(2 1,1 2,4 0)", line2); + + bool b = boost::geometry::intersects(line1, line2); + + std::cout << "Intersects: " << (b ? "YES" : "NO") << std::endl; + + return 0; +} + +//] + + +//[intersects_linestring_output +/*` +Output: +[pre +Intersects: YES +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/intersects_segment.cpp b/libs/geometry/doc/src/examples/algorithms/intersects_segment.cpp new file mode 100644 index 000000000..223d9b079 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/intersects_segment.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[intersects +//` Check if two linestrings intersect each other + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +int main() +{ + // Calculate the intersects of a cartesian polygon + typedef boost::geometry::model::d2::point_xy<double> P; + bg::model::linestring<P> line1, line2; + + boost::geometry::read_wkt("linestring(1 1,2 2)", line1); + boost::geometry::read_wkt("linestring(2 1,1 2)", line2); + + bool b = boost::geometry::intersects(line1, line2); + + std::cout << "Intersects: " << (b ? "YES" : "NO") << std::endl; + + return 0; +} + +//] + + +//[intersects_output +/*` +Output: +[pre +Intersects: YES +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/length.cpp b/libs/geometry/doc/src/examples/algorithms/length.cpp new file mode 100644 index 000000000..35fa50ea3 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/length.cpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[length + //` The following simple example shows the calculation of the length of a linestring containing three points + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + + +int main() +{ + using namespace boost::geometry; + model::linestring<model::d2::point_xy<double> > line; + read_wkt("linestring(0 0,1 1,4 8,3 2)", line); + std::cout << "linestring length is " + << length(line) + << " units" << std::endl; + + return 0; +} + +//] + + +//[length_output +/*` +Output: +[pre +linestring length is 15.1127 units +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/length_with_strategy.cpp b/libs/geometry/doc/src/examples/algorithms/length_with_strategy.cpp new file mode 100644 index 000000000..99c15fb19 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/length_with_strategy.cpp @@ -0,0 +1,43 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[length_with_strategy +//`The following example shows the length measured over a sphere, expressed in kilometers. To do that the radius of the sphere must be specified in the constructor of the strategy. + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> + +int main() +{ + using namespace boost::geometry; + typedef model::point<float, 2, cs::spherical_equatorial<degree> > P; + model::linestring<P> line; + line.push_back(P(2, 41)); + line.push_back(P(2, 48)); + line.push_back(P(5, 52)); + double const mean_radius = 6371.0; /*< [@http://en.wikipedia.org/wiki/Earth_radius Wiki] >*/ + std::cout << "length is " + << length(line, strategy::distance::haversine<P>(mean_radius) ) + << " kilometers " << std::endl; + + return 0; +} + +//] + + +//[length_with_strategy_output +/*` +Output: +[pre +length is 1272.03 kilometers +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/make_2d_point.cpp b/libs/geometry/doc/src/examples/algorithms/make_2d_point.cpp new file mode 100644 index 000000000..92f7b0259 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/make_2d_point.cpp @@ -0,0 +1,63 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[make_2d_point +//` Shows the usage of make as a generic constructor for different point types + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/point.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon/point.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +struct mypoint { float _x, _y; }; + +BOOST_GEOMETRY_REGISTER_POINT_2D(mypoint, float, cs::cartesian, _x, _y) + +template <typename Point> +void construct_and_display() +{ + using boost::geometry::make; + using boost::geometry::get; + + Point p = make<Point>(1, 2); + + std::cout << "x=" << get<0>(p) << " y=" << get<1>(p) + << " (" << typeid(Point).name() << ")" + << std::endl; +} + +int main() +{ + construct_and_display<boost::geometry::model::d2::point_xy<double> >(); + construct_and_display<boost::geometry::model::d2::point_xy<int> >(); + construct_and_display<boost::tuple<double, double> >(); + construct_and_display<boost::polygon::point_data<int> >(); + construct_and_display<mypoint>(); + return 0; +} + +//] + +//[make_2d_point_output +/*` +Output (compiled using gcc): +[pre +x=1 y=2 (N5boost8geometry5model2d28point_xyIdNS0_2cs9cartesianEEE) +x=1 y=2 (N5boost8geometry5model2d28point_xyIiNS0_2cs9cartesianEEE) +x=1 y=2 (N5boost6tuples5tupleIddNS0_9null_typeES2_S2_S2_S2_S2_S2_S2_EE) +x=1 y=2 (N5boost7polygon10point_dataIiEE) +x=1 y=2 (7mypoint) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/make_3d_point.cpp b/libs/geometry/doc/src/examples/algorithms/make_3d_point.cpp new file mode 100644 index 000000000..6b7e8e7db --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/make_3d_point.cpp @@ -0,0 +1,36 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[make_3d_point +//` Using make to construct a three dimensional point + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point.hpp> + +int main() +{ + typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type; + point_type p = boost::geometry::make<point_type>(1, 2, 3); + std::cout << boost::geometry::dsv(p) << std::endl; + return 0; +} + +//] + + +//[make_3d_point_output +/*` +Output: +[pre +(1, 2, 3) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/make_inverse.cpp b/libs/geometry/doc/src/examples/algorithms/make_inverse.cpp new file mode 100644 index 000000000..339b0f4b1 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/make_inverse.cpp @@ -0,0 +1,47 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[make_inverse +//` Usage of make_inverse and expand to conveniently determine bounding box of several objects + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +using namespace boost::geometry; + +int main() +{ + + typedef model::d2::point_xy<double> point; + typedef model::box<point> box; + + box all = make_inverse<box>(); + std::cout << dsv(all) << std::endl; + expand(all, make<box>(0, 0, 3, 4)); + expand(all, make<box>(2, 2, 5, 6)); + std::cout << dsv(all) << std::endl; + + return 0; +} + +//] + + +//[make_inverse_output +/*` +Output: +[pre +((1.79769e+308, 1.79769e+308), (-1.79769e+308, -1.79769e+308)) +((0, 0), (5, 6)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/make_with_range.cpp b/libs/geometry/doc/src/examples/algorithms/make_with_range.cpp new file mode 100644 index 000000000..56ff34c45 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/make_with_range.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[make_with_range +//` Using make to construct a linestring with two different range types + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) /*< Necessary to register a C array like {1,2} as a point >*/ + +int main() +{ + using boost::geometry::make; + using boost::geometry::detail::make::make_points; + + typedef boost::geometry::model::d2::point_xy<double> point; + typedef boost::geometry::model::linestring<point> linestring; + + double coordinates[][2] = {{1,2}, {3,4}, {5, 6}}; /*< Initialize with C array points >*/ + linestring ls = make_points<linestring>(coordinates); + std::cout << boost::geometry::dsv(ls) << std::endl; + + point points[3] = { make<point>(9,8), make<point>(7,6), make<point>(5,4) }; /*< Construct array with points, using make which should work for any point type >*/ + std::cout << boost::geometry::dsv(make_points<linestring>(points)) << std::endl; /*< Construct linestring with point-array and output it as Delimiter Separated Values >*/ + + return 0; +} + +//] + + +//[make_with_range_output +/*` +Output: +[pre +((1, 2), (3, 4), (5, 6)) +((9, 8), (7, 6), (5, 4)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/num_geometries.cpp b/libs/geometry/doc/src/examples/algorithms/num_geometries.cpp new file mode 100644 index 000000000..8a350d5b8 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/num_geometries.cpp @@ -0,0 +1,48 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[num_geometries +//` Get the number of geometries making up a multi-geometry + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + + +int main() +{ + boost::geometry::model::multi_polygon + < + boost::geometry::model::polygon + < + boost::geometry::model::d2::point_xy<double> + > + > mp; + boost::geometry::read_wkt("MULTIPOLYGON(((0 0,0 10,10 0,0 0),(1 1,1 9,9 1,1 1)),((10 10,10 7,7 10,10 10)))", mp); + std::cout << "Number of geometries: " << boost::geometry::num_geometries(mp) << std::endl; + + return 0; +} + +//] + + +//[num_geometries_output +/*` +Output: +[pre + Number of geometries: 2 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/num_interior_rings.cpp b/libs/geometry/doc/src/examples/algorithms/num_interior_rings.cpp new file mode 100644 index 000000000..aeb8c92b7 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/num_interior_rings.cpp @@ -0,0 +1,48 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[num_interior_rings +//` Get the number of interior rings in a multi-polygon + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + + +int main() +{ + boost::geometry::model::multi_polygon + < + boost::geometry::model::polygon + < + boost::geometry::model::d2::point_xy<double> + > + > mp; + boost::geometry::read_wkt("MULTIPOLYGON(((0 0,0 10,10 0,0 0),(1 1,1 9,9 1,1 1)),((10 10,10 7,7 10,10 10)))", mp); + std::cout << "Number of interior rings: " << boost::geometry::num_interior_rings(mp) << std::endl; + + return 0; +} + +//] + + +//[num_interior_rings_output +/*` +Output: +[pre + Number of interior rings: 1 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/num_points.cpp b/libs/geometry/doc/src/examples/algorithms/num_points.cpp new file mode 100644 index 000000000..2e3c5c678 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/num_points.cpp @@ -0,0 +1,49 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[num_points +//` Get the number of points in a geometry + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/multi/multi.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + + +int main() +{ + boost::geometry::model::multi_polygon + < + boost::geometry::model::polygon + < + boost::geometry::model::d2::point_xy<double> + > + > mp; + boost::geometry::read_wkt("MULTIPOLYGON(((0 0,0 10,10 0,0 0),(1 1,1 9,9 1,1 1)),((10 10,10 7,7 10,10 10)))", mp); + std::cout << "Number of points: " << boost::geometry::num_points(mp) << std::endl; + + return 0; +} + +//] + + +//[num_points_output +/*` +Output: +[pre + Number of points: 12 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/return_envelope.cpp b/libs/geometry/doc/src/examples/algorithms/return_envelope.cpp new file mode 100644 index 000000000..3c8ef3045 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/return_envelope.cpp @@ -0,0 +1,63 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[return_envelope +//` Shows how to return the envelope of a ring + +#include <iostream> + + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/ring.hpp> + +#include <boost/assign.hpp> + +/*<-*/ #include "create_svg_two.hpp" /*->*/ + +int main() +{ + using namespace boost::assign; + + typedef boost::geometry::model::d2::point_xy<double> point; + + boost::geometry::model::ring<point> ring; + ring += + point(4.0, -0.5), point(3.5, 1.0), + point(2.0, 1.5), point(3.5, 2.0), + point(4.0, 3.5), point(4.5, 2.0), + point(6.0, 1.5), point(4.5, 1.0), + point(4.0, -0.5); + + typedef boost::geometry::model::box<point> box; + + std::cout + << "return_envelope:" + << boost::geometry::dsv(boost::geometry::return_envelope<box>(ring)) + << std::endl; + + /*<-*/ create_svg("return_envelope.svg", ring, boost::geometry::return_envelope<box>(ring)); /*->*/ + return 0; +} + +//] + + +//[return_envelope_output +/*` +Output: +[pre +return_envelope:((2, -0.5), (6, 3.5)) + +[$img/algorithms/return_envelope.png] +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/reverse.cpp b/libs/geometry/doc/src/examples/algorithms/reverse.cpp new file mode 100644 index 000000000..89e299e56 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/reverse.cpp @@ -0,0 +1,67 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[reverse +//` Shows how to reverse a ring or polygon + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +#include <boost/assign.hpp> + +int main() +{ + using boost::assign::tuple_list_of; + + typedef boost::tuple<int, int> point; + typedef boost::geometry::model::polygon<point> polygon; + typedef boost::geometry::model::ring<point> ring; + + + polygon poly; + boost::geometry::exterior_ring(poly) = tuple_list_of(0, 0)(0, 9)(10, 10)(0, 0); + boost::geometry::interior_rings(poly).push_back(tuple_list_of(1, 2)(4, 6)(2, 8)(1, 2)); + + double area_before = boost::geometry::area(poly); + boost::geometry::reverse(poly); + double area_after = boost::geometry::area(poly); + std::cout << boost::geometry::dsv(poly) << std::endl; + std::cout << area_before << " -> " << area_after << std::endl; + + ring r = tuple_list_of(0, 0)(0, 9)(8, 8)(0, 0); + + area_before = boost::geometry::area(r); + boost::geometry::reverse(r); + area_after = boost::geometry::area(r); + std::cout << boost::geometry::dsv(r) << std::endl; + std::cout << area_before << " -> " << area_after << std::endl; + + return 0; +} + +//] + + +//[reverse_output +/*` +Output: +[pre +(((0, 0), (10, 10), (0, 9), (0, 0)), ((1, 2), (2, 8), (4, 6), (1, 2))) +38 -> -38 +((0, 0), (8, 8), (0, 9), (0, 0)) +36 -> -36 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/simplify.cpp b/libs/geometry/doc/src/examples/algorithms/simplify.cpp new file mode 100644 index 000000000..2d9b77d09 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/simplify.cpp @@ -0,0 +1,54 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[simplify +//` Example showing how to simplify a linestring + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +/*< For this example we use Boost.Assign to add points >*/ +#include <boost/assign.hpp> + +using namespace boost::assign; + + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> xy; + + boost::geometry::model::linestring<xy> line; + line += xy(1.1, 1.1), xy(2.5, 2.1), xy(3.1, 3.1), xy(4.9, 1.1), xy(3.1, 1.9); /*< With Boost.Assign >*/ + + // Simplify it, using distance of 0.5 units + boost::geometry::model::linestring<xy> simplified; + boost::geometry::simplify(line, simplified, 0.5); + std::cout + << " original: " << boost::geometry::dsv(line) << std::endl + << "simplified: " << boost::geometry::dsv(simplified) << std::endl; + + + return 0; +} + +//] + + +//[simplify_output +/*` +Output: +[pre + original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/simplify_insert.cpp b/libs/geometry/doc/src/examples/algorithms/simplify_insert.cpp new file mode 100644 index 000000000..b80686f91 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/simplify_insert.cpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[simplify_inserter +//` Simplify a linestring using a back inserter + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> P; + typedef boost::geometry::model::linestring<P> L; + + L line; + line.push_back(P(1.1, 1.1)); + line.push_back(P(2.5, 2.1)); + line.push_back(P(3.1, 3.1)); + line.push_back(P(4.9, 1.1)); + line.push_back(P(3.1, 1.9)); + + L simplified; + boost::geometry::simplify_inserter(line, std::back_inserter(simplified), 0.5); + + std::cout + << " original: " << boost::geometry::dsv(line) << std::endl + << "simplified: " << boost::geometry::dsv(simplified) << std::endl; + + return 0; +} + +//] + + +//[simplify_inserter_output +/*` +Output: +[pre + original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/simplify_insert_with_strategy.cpp b/libs/geometry/doc/src/examples/algorithms/simplify_insert_with_strategy.cpp new file mode 100644 index 000000000..95deab38d --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/simplify_insert_with_strategy.cpp @@ -0,0 +1,72 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[simplify_inserter +//` Simplify a linestring using an output iterator + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> P; + typedef boost::geometry::model::linestring<P> L; + + L line; + boost::geometry::read_wkt("linestring(1.1 1.1, 2.5 2.1, 3.1 3.1, 4.9 1.1, 3.1 1.9)", line); + + typedef boost::geometry::strategy::distance::projected_point<P, P> DS; + typedef boost::geometry::strategy::simplify::douglas_peucker<P, DS> simplification; + + L simplified; + boost::geometry::simplify_inserter(line, std::back_inserter(simplified), 0.5, simplification()); //std::ostream_iterator<P>(std::cout, "\n"), 0.5);//); + //std::cout << simplified[0]; + //boost::geometry::simplify_inserter(line, std::ostream_iterator<P>(std::cout, "\n"), 0.5);//, simplification()); + + std::ostream_iterator<P> out(std::cout, "\n"); + std::copy(simplified.begin(), simplified.end(), out); + + std::cout + << " original: " << boost::geometry::dsv(line) << std::endl + << "simplified: " << boost::geometry::dsv(simplified) << std::endl; + + return 0; +} + +//] + + +//[simplify_inserter_output +/*` +Output: +[pre +simplify_inserter: 16 +simplify_inserter: 0.339837 +] +*/ +//] +/* +OUTPUT +POINT(1.1 1.1) original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +*/ +/* +OUTPUT +POINT(1.1 1.1) original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +*/ +/* +OUTPUT +POINT(1.1 1.1) original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9)) +*/ diff --git a/libs/geometry/doc/src/examples/algorithms/sym_difference.cpp b/libs/geometry/doc/src/examples/algorithms/sym_difference.cpp new file mode 100644 index 000000000..1bb955bcd --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/sym_difference.cpp @@ -0,0 +1,80 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[sym_difference +//` Shows how to calculate the symmetric difference (XOR) of two polygons + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> +/*<-*/ #include "create_svg_overlay.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; + + polygon green, blue; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green); + + boost::geometry::read_wkt( + "POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue); + + boost::geometry::model::multi_polygon<polygon> multi; + + boost::geometry::sym_difference(green, blue, multi); + + std::cout + << "green XOR blue:" << std::endl + << "total: " << boost::geometry::area(multi) << std::endl; + int i = 0; + BOOST_FOREACH(polygon const& p, multi) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("sym_difference.svg", green, blue, multi); /*->*/ + return 0; +} + +//] + + +//[sym_difference_output +/*` +Output: +[pre +green XOR blue: +total: 3.1459 +0: 0.02375 +1: 0.542951 +2: 0.0149697 +3: 0.226855 +4: 0.839424 +5: 0.525154 +6: 0.015 +7: 0.181136 +8: 0.128798 +9: 0.340083 +10: 0.307778 + +[$img/algorithms/sym_difference.png] + +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/transform.cpp b/libs/geometry/doc/src/examples/algorithms/transform.cpp new file mode 100644 index 000000000..97aea3c3d --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/transform.cpp @@ -0,0 +1,54 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[transform +//` Shows how points can be transformed using the default strategy + +#include <iostream> +#include <boost/geometry.hpp> + + +int main() +{ + namespace bg = boost::geometry; + + // Select a point near the pole (theta=5.0, phi=15.0) + bg::model::point<long double, 2, bg::cs::spherical<bg::degree> > p1(15.0, 5.0); + + // Transform from degree to radian. Default strategy is automatically selected, + // it will convert from degree to radian + bg::model::point<long double, 2, bg::cs::spherical<bg::radian> > p2; + bg::transform(p1, p2); + + // Transform from degree (lon-lat) to 3D (x,y,z). Default strategy is automatically selected, + // it will consider points on a unit sphere + bg::model::point<long double, 3, bg::cs::cartesian> p3; + bg::transform(p1, p3); + + std::cout + << "p1: " << bg::dsv(p1) << std::endl + << "p2: " << bg::dsv(p2) << std::endl + << "p3: " << bg::dsv(p3) << std::endl; + + return 0; +} + +//] + + +//[transform_output +/*` +Output: +[pre +p1: (15, 5) +p2: (0.261799, 0.0872665) +p3: (0.084186, 0.0225576, 0.996195) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/transform_with_strategy.cpp b/libs/geometry/doc/src/examples/algorithms/transform_with_strategy.cpp new file mode 100644 index 000000000..df44d6336 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/transform_with_strategy.cpp @@ -0,0 +1,63 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[transform_with_strategy +//` Shows how points can be scaled, translated or rotated + +#include <iostream> +#include <boost/geometry.hpp> + + +int main() +{ + namespace trans = boost::geometry::strategy::transform; + using boost::geometry::dsv; + + typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> point_type; + + point_type p1(1.0, 1.0); + + // Translate over (1.5, 1.5) + point_type p2; + trans::translate_transformer<point_type, point_type> translate(1.5, 1.5); + boost::geometry::transform(p1, p2, translate); + + // Scale with factor 3.0 + point_type p3; + trans::scale_transformer<point_type, point_type> scale(3.0); + boost::geometry::transform(p1, p3, scale); + + // Rotate with respect to the origin (0,0) over 90 degrees (clockwise) + point_type p4; + trans::rotate_transformer<point_type, point_type, boost::geometry::degree> rotate(90.0); + boost::geometry::transform(p1, p4, rotate); + + std::cout + << "p1: " << dsv(p1) << std::endl + << "p2: " << dsv(p2) << std::endl + << "p3: " << dsv(p3) << std::endl + << "p4: " << dsv(p4) << std::endl; + + return 0; +} + +//] + + +//[transform_with_strategy_output +/*` +Output: +[pre +p1: (1, 1) +p2: (2.5, 2.5) +p3: (3, 3) +p4: (1, -1) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/union.cpp b/libs/geometry/doc/src/examples/algorithms/union.cpp new file mode 100644 index 000000000..cf93a1db9 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/union.cpp @@ -0,0 +1,66 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[union +//` Shows how to get a united geometry of two polygons + +#include <iostream> +#include <vector> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +#include <boost/foreach.hpp> +/*<-*/ #include "create_svg_overlay.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; + + polygon green, blue; + + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green); + + boost::geometry::read_wkt( + "POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue); + + std::vector<polygon> output; + boost::geometry::union_(green, blue, output); + + int i = 0; + std::cout << "green || blue:" << std::endl; + BOOST_FOREACH(polygon const& p, output) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("union.svg", green, blue, output); /*->*/ + return 0; +} + +//] + + +//[union_output +/*` +Output: +[pre +green || blue: +0: 5.64795 + +[$img/algorithms/union.png] + +] +*/ +//] + diff --git a/libs/geometry/doc/src/examples/algorithms/unique.cpp b/libs/geometry/doc/src/examples/algorithms/unique.cpp new file mode 100644 index 000000000..0b975698e --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/unique.cpp @@ -0,0 +1,41 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[unique +//` Shows how to make a so-called minimal set of a polygon by removing duplicate points + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +int main() +{ + boost::geometry::model::polygon<boost::tuple<double, double> > poly; + boost::geometry::read_wkt("POLYGON((0 0,0 0,0 5,5 5,5 5,5 5,5 0,5 0,0 0,0 0,0 0,0 0))", poly); + boost::geometry::unique(poly); + std::cout << boost::geometry::wkt(poly) << std::endl; + + return 0; +} + +//] + + +//[unique_output +/*` +Output: +[pre +POLYGON((0 0,0 5,5 5,5 0,0 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/algorithms/within.cpp b/libs/geometry/doc/src/examples/algorithms/within.cpp new file mode 100644 index 000000000..487753fc7 --- /dev/null +++ b/libs/geometry/doc/src/examples/algorithms/within.cpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[within +//` Shows how to detect if a point is inside a polygon, or not + +#include <iostream> +#include <list> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> +/*<-*/ #include "create_svg_two.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + + polygon_type poly; + boost::geometry::read_wkt( + "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" + "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly); + + point_type p(4, 1); + + std::cout << "within: " << (boost::geometry::within(p, poly) ? "yes" : "no") << std::endl; + /*<-*/ create_svg("within.svg", poly, p); /*->*/ + return 0; +} + +//] + +//[within_output +/*` +Output: +[pre +within: yes + +[$img/algorithms/within.png] +] + +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/Jamfile.v2 b/libs/geometry/doc/src/examples/core/Jamfile.v2 new file mode 100644 index 000000000..4f46ca1de --- /dev/null +++ b/libs/geometry/doc/src/examples/core/Jamfile.v2 @@ -0,0 +1,33 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-example-core + : # requirements + ; + +exe get_point : get_point.cpp ; +exe get_box : get_box.cpp ; +exe set_point : set_point.cpp ; +exe set_box : set_box.cpp ; +exe degree_radian : degree_radian.cpp ; + +exe coordinate_type : coordinate_type.cpp ; +exe coordinate_system : coordinate_system.cpp ; +exe coordinate_dimension : coordinate_dimension.cpp ; +exe point_order : point_order.cpp ; +exe closure : closure.cpp ; + +exe interior_type : interior_type.cpp ; +exe point_type : point_type.cpp ; +exe ring_type : ring_type.cpp ; +exe rings : rings.cpp ; +exe tag : tag.cpp ; +exe tag_cast : tag_cast.cpp ; diff --git a/libs/geometry/doc/src/examples/core/closure.cpp b/libs/geometry/doc/src/examples/core/closure.cpp new file mode 100644 index 000000000..62c6c1895 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/closure.cpp @@ -0,0 +1,45 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[closure +//` Examine if a polygon is defined as "should be closed" + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + + boost::geometry::closure_selector clos = boost::geometry::closure<polygon_type>::value; + + std::cout << "closure: " << clos << std::endl + << "(open = " << boost::geometry::open + << ", closed = " << boost::geometry::closed + << ") "<< std::endl; + + return 0; +} + +//] + + +//[closure_output +/*` +Output: +[pre +closure: 1 +(open = 0, closed = 1) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/coordinate_dimension.cpp b/libs/geometry/doc/src/examples/core/coordinate_dimension.cpp new file mode 100644 index 000000000..05881d274 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/coordinate_dimension.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[dimension +//` Examine the number of coordinates making up the points in a linestring type + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian); + +int main() +{ + int dim = boost::geometry::dimension + < + boost::geometry::model::linestring + < + boost::tuple<float, float, float> + > + >::value; + + std::cout << "dimensions: " << dim << std::endl; + + return 0; +} + +//] + + +//[dimension_output +/*` +Output: +[pre +dimensions: 3 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/coordinate_system.cpp b/libs/geometry/doc/src/examples/core/coordinate_system.cpp new file mode 100644 index 000000000..63db3a5dc --- /dev/null +++ b/libs/geometry/doc/src/examples/core/coordinate_system.cpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[coordinate_system +//` Examine the coordinate system of a point + +#include <iostream> +#include <typeinfo> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + + typedef boost::geometry::coordinate_system<polygon_type>::type system; + + std::cout << "system: " << typeid(system).name() << std::endl; + + return 0; +} + +//] + + +//[coordinate_system_output +/*` +Output (using MSVC): +[pre +system: struct boost::geometry::cs::cartesian +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/coordinate_type.cpp b/libs/geometry/doc/src/examples/core/coordinate_type.cpp new file mode 100644 index 000000000..dd043bddb --- /dev/null +++ b/libs/geometry/doc/src/examples/core/coordinate_type.cpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[coordinate_type +//` Examine the coordinate type of a point + +#include <iostream> +#include <typeinfo> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + + typedef boost::geometry::coordinate_type<polygon_type>::type ctype; + + std::cout << "type: " << typeid(ctype).name() << std::endl; + + return 0; +} + +//] + + +//[coordinate_type_output +/*` +Output (using MSVC): +[pre +type: double +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/degree_radian.cpp b/libs/geometry/doc/src/examples/core/degree_radian.cpp new file mode 100644 index 000000000..aed6bbead --- /dev/null +++ b/libs/geometry/doc/src/examples/core/degree_radian.cpp @@ -0,0 +1,47 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[degree_radian +//` Specify two coordinate systems, one in degrees, one in radians. + +#include <iostream> +#include <boost/geometry.hpp> + +using namespace boost::geometry; + +int main() +{ + typedef model::point<double, 2, cs::spherical_equatorial<degree> > degree_point; + typedef model::point<double, 2, cs::spherical_equatorial<radian> > radian_point; + + degree_point d(4.893, 52.373); + radian_point r(0.041, 0.8527); + + double dist = distance(d, r); + std::cout + << "distance:" << std::endl + << dist << " over unit sphere" << std::endl + << dist * 3959 << " over a spherical earth, in miles" << std::endl; + + return 0; +} + +//] + + +//[degree_radian_output +/*` +Output: +[pre +distance: +0.0675272 over unit sphere +267.34 over a spherical earth, in miles +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/get_box.cpp b/libs/geometry/doc/src/examples/core/get_box.cpp new file mode 100644 index 000000000..a159d4c73 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/get_box.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[get_box +//` Get the coordinate of a box + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +namespace bg = boost::geometry; + +int main() +{ + bg::model::box<bg::model::d2::point_xy<double> > box; + + bg::assign_values(box, 1, 3, 5, 6); + + std::cout << "Box:" + << " " << bg::get<bg::min_corner, 0>(box) + << " " << bg::get<bg::min_corner, 1>(box) + << " " << bg::get<bg::max_corner, 0>(box) + << " " << bg::get<bg::max_corner, 1>(box) + << std::endl; + + return 0; +} + +//] + + +//[get_box_output +/*` +Output: +[pre +Box: 1 3 5 6 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/get_point.cpp b/libs/geometry/doc/src/examples/core/get_point.cpp new file mode 100644 index 000000000..458c9877c --- /dev/null +++ b/libs/geometry/doc/src/examples/core/get_point.cpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[get_point +//` Get the coordinate of a point + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +namespace bg = boost::geometry; + +int main() +{ + bg::model::d2::point_xy<double> point(1, 2); + + double x = bg::get<0>(point); + double y = bg::get<1>(point); + + std::cout << "x=" << x << " y=" << y << std::endl; + + return 0; +} + +//] + + +//[get_point_output +/*` +Output: +[pre +x=1 y=2 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/interior_type.cpp b/libs/geometry/doc/src/examples/core/interior_type.cpp new file mode 100644 index 000000000..61096bf47 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/interior_type.cpp @@ -0,0 +1,49 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[interior_type +//`Shows how to use the interior_type metafunction + +#include <iostream> +#include <typeinfo> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_array.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(cs::cartesian) + +int main() +{ + // Define a polygon storing points in a deque and storing interior rings + // in a list (note that std::list is not supported by most algorithms + // because not supporting a random access iterator) + typedef boost::geometry::model::polygon + < + boost::array<short, 3>, + true, true, + std::deque, std::list + > polygon; + + std::cout << typeid(boost::geometry::interior_type<polygon>::type).name() << std::endl; + + return 0; +} + +//] + +//[interior_type_output +/*` +Output (using MSVC) is a long story (part manually replaced with ellipsis): +[pre +class std::list<class boost::geometry::model::ring<class boost::array<short,3>,1,1,class std::deque,class std::allocator>,class std::allocator<...> > > +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/point_order.cpp b/libs/geometry/doc/src/examples/core/point_order.cpp new file mode 100644 index 000000000..2f8b7058e --- /dev/null +++ b/libs/geometry/doc/src/examples/core/point_order.cpp @@ -0,0 +1,45 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[point_order +//` Examine the expected point order of a polygon type + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type, false> polygon_type; + + boost::geometry::order_selector order = boost::geometry::point_order<polygon_type>::value; + + std::cout << "order: " << order << std::endl + << "(clockwise = " << boost::geometry::clockwise + << ", counterclockwise = " << boost::geometry::counterclockwise + << ") "<< std::endl; + + return 0; +} + +//] + + +//[point_order_output +/*` +Output: +[pre +order: 2 +(clockwise = 1, counterclockwise = 2) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/point_type.cpp b/libs/geometry/doc/src/examples/core/point_type.cpp new file mode 100644 index 000000000..17ab38ffc --- /dev/null +++ b/libs/geometry/doc/src/examples/core/point_type.cpp @@ -0,0 +1,44 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[point_type +//` Examine the point type of a multi_polygon + +#include <iostream> +#include <typeinfo> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point_type; + typedef boost::geometry::model::polygon<point_type> polygon_type; + typedef boost::geometry::model::multi_polygon<polygon_type> mp_type; + + typedef boost::geometry::point_type<mp_type>::type ptype; + + std::cout << "point type: " << typeid(ptype).name() << std::endl; + + return 0; +} + +//] + + +//[point_type_output +/*` +Output (in MSVC): +[pre +point type: class boost::geometry::model::d2::point_xy<double,struct boost::geometry::cs::cartesian> +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/ring_type.cpp b/libs/geometry/doc/src/examples/core/ring_type.cpp new file mode 100644 index 000000000..9e19bd421 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/ring_type.cpp @@ -0,0 +1,56 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[ring_type +//`Shows how to use the ring_type metafunction, as well as interior_type + +#include <iostream> +#include <typeinfo> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point; + typedef boost::geometry::model::polygon<point> polygon; + + typedef boost::geometry::ring_type<polygon>::type ring_type; + typedef boost::geometry::interior_type<polygon>::type int_type; + + std::cout << typeid(ring_type).name() << std::endl; + std::cout << typeid(int_type).name() << std::endl; + + // So int_type defines a collection of rings, + // which is a Boost.Range compatible range + // The type of an element of the collection is the very same ring type again. + // We show that. + typedef boost::range_value<int_type>::type int_ring_type; + + std::cout + << std::boolalpha + << boost::is_same<ring_type, int_ring_type>::value + << std::endl; + + return 0; +} + +//] + +//[ring_type_output +/*` +Output (using gcc): +[pre + N5boost8geometry5model4ringINS1_2d28point_xyIdNS0_2cs9cartesianEEELb1ELb1ESt6vectorSaEE +St6vectorIN5boost8geometry5model4ringINS2_2d28point_xyIdNS1_2cs9cartesianEEELb1ELb1ES_SaEESaIS9_EE +true +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/rings.cpp b/libs/geometry/doc/src/examples/core/rings.cpp new file mode 100644 index 000000000..81f1ded65 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/rings.cpp @@ -0,0 +1,77 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[rings +/*` +Shows how to access the exterior ring (one) +and interior rings (zero or more) of a polygon. +Also shows the related ring_type and interior_type. +*/ + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + + +int main() +{ + typedef boost::geometry::model::d2::point_xy<double> point; + typedef boost::geometry::model::polygon<point> polygon_type; + + polygon_type poly; + + typedef boost::geometry::ring_type<polygon_type>::type ring_type; + ring_type& ring = boost::geometry::exterior_ring(poly); + + // For a ring of model::polygon, you can call "push_back". + // (internally, it is done using a traits::push_back class) + ring.push_back(point(0, 0)); + ring.push_back(point(0, 5)); + ring.push_back(point(5, 4)); + ring.push_back(point(0, 0)); + + ring_type inner; + inner.push_back(point(1, 1)); + inner.push_back(point(2, 1)); + inner.push_back(point(2, 2)); + inner.push_back(point(1, 1)); + + typedef boost::geometry::interior_type<polygon_type>::type int_type; + int_type& interiors = boost::geometry::interior_rings(poly); + interiors.push_back(inner); + + std::cout << boost::geometry::dsv(poly) << std::endl; + + // So int_type defines a collection of rings, + // which is a Boost.Range compatible range + // The type of an element of the collection is the very same ring type again. + // We show that. + typedef boost::range_value<int_type>::type int_ring_type; + + std::cout + << std::boolalpha + << boost::is_same<ring_type, int_ring_type>::value + << std::endl; + + return 0; +} + +//] + +//[rings_output +/*` +Output: +[pre +(((0, 0), (0, 5), (5, 4), (0, 0)), ((1, 1), (2, 1), (2, 2), (1, 1))) +true +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/set_box.cpp b/libs/geometry/doc/src/examples/core/set_box.cpp new file mode 100644 index 000000000..c95e31042 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/set_box.cpp @@ -0,0 +1,44 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[set_box +//` Set the coordinate of a box + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +namespace bg = boost::geometry; + +int main() +{ + bg::model::box<bg::model::d2::point_xy<double> > box; + + bg::set<bg::min_corner, 0>(box, 0); + bg::set<bg::min_corner, 1>(box, 2); + bg::set<bg::max_corner, 0>(box, 4); + bg::set<bg::max_corner, 1>(box, 5); + + std::cout << "Extent: " << bg::dsv(box) << std::endl; + + return 0; +} + +//] + + +//[set_box_output +/*` +Output: +[pre +Extent: ((0, 2), (4, 5)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/set_point.cpp b/libs/geometry/doc/src/examples/core/set_point.cpp new file mode 100644 index 000000000..adab1fbe6 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/set_point.cpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[set_point +//` Set the coordinate of a point + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +namespace bg = boost::geometry; + +int main() +{ + bg::model::d2::point_xy<double> point; + + bg::set<0>(point, 1); + bg::set<1>(point, 2); + + std::cout << "Location: " << bg::dsv(point) << std::endl; + + return 0; +} + +//] + + +//[set_point_output +/*` +Output: +[pre +Location: (1, 2) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/tag.cpp b/libs/geometry/doc/src/examples/core/tag.cpp new file mode 100644 index 000000000..13bf4ff79 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/tag.cpp @@ -0,0 +1,110 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[tag +//` Shows how tag dispatching essentially works in Boost.Geometry + +#include <iostream> + +#include <boost/assign.hpp> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +template <typename Tag> struct dispatch {}; + +// Specialization for points +template <> struct dispatch<boost::geometry::point_tag> +{ + template <typename Point> + static inline void apply(Point const& p) + { + // Use the Boost.Geometry free function "get" + // working on all supported point types + std::cout << "Hello POINT, you are located at: " + << boost::geometry::get<0>(p) << ", " + << boost::geometry::get<1>(p) + << std::endl; + } +}; + +// Specialization for polygons +template <> struct dispatch<boost::geometry::polygon_tag> +{ + template <typename Polygon> + static inline void apply(Polygon const& p) + { + // Use the Boost.Geometry manipulator "dsv" + // working on all supported geometries + std::cout << "Hello POLYGON, you look like: " + << boost::geometry::dsv(p) + << std::endl; + } +}; + +// Specialization for multipolygons +template <> struct dispatch<boost::geometry::multi_polygon_tag> +{ + template <typename MultiPolygon> + static inline void apply(MultiPolygon const& m) + { + // Use the Boost.Range free function "size" because all + // multigeometries comply to Boost.Range + std::cout << "Hello MULTIPOLYGON, you contain: " + << boost::size(m) << " polygon(s)" + << std::endl; + } +}; + +template <typename Geometry> +inline void hello(Geometry const& geometry) +{ + // Call the metafunction "tag" to dispatch, and call method (here "apply") + dispatch + < + typename boost::geometry::tag<Geometry>::type + >::apply(geometry); +} + +int main() +{ + // Define polygon type (here: based on a Boost.Tuple) + typedef boost::geometry::model::polygon<boost::tuple<int, int> > polygon_type; + + // Declare and fill a polygon and a multipolygon + polygon_type poly; + boost::geometry::exterior_ring(poly) = boost::assign::tuple_list_of(0, 0)(0, 10)(10, 5)(0, 0); + + boost::geometry::model::multi_polygon<polygon_type> multi; + multi.push_back(poly); + + // Call "hello" for point, polygon, multipolygon + hello(boost::make_tuple(2, 3)); + hello(poly); + hello(multi); + + return 0; +} + +//] + +//[tag_output +/*` +Output: +[pre +Hello POINT, you are located at: 2, 3 +Hello POLYGON, you look like: (((0, 0), (0, 10), (10, 5), (0, 0))) +Hello MULTIPOLYGON, you contain: 1 polygon(s) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/core/tag_cast.cpp b/libs/geometry/doc/src/examples/core/tag_cast.cpp new file mode 100644 index 000000000..2e85f3d34 --- /dev/null +++ b/libs/geometry/doc/src/examples/core/tag_cast.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[tag_cast +//` Check if the polygon_tag can be casted to the areal_tag + +#include <iostream> +#include <typeinfo> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +namespace geo = boost::geometry; +int main() +{ + typedef geo::model::d2::point_xy<double> point_type; + typedef geo::model::polygon<point_type> polygon_type; + + typedef geo::tag<polygon_type>::type tag; + typedef geo::tag_cast<tag, geo::linear_tag, geo::areal_tag>::type base_tag; + + std::cout << "tag: " << typeid(tag).name() << std::endl + << "base tag: " << typeid(base_tag).name() << std::endl; + + return 0; +} + +//] + + +//[tag_cast_output +/*` +Output (in MSVC): +[pre +tag: struct boost::geometry::polygon_tag +base tag: struct boost::geometry::areal_tag +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/Jamfile.v2 b/libs/geometry/doc/src/examples/geometries/Jamfile.v2 new file mode 100644 index 000000000..68a99b57a --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/Jamfile.v2 @@ -0,0 +1,19 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-src-example-geometries + : # requirements + ; + +exe point : point.cpp ; + +build-project adapted ; +build-project register ; diff --git a/libs/geometry/doc/src/examples/geometries/adapted/Jamfile.v2 b/libs/geometry/doc/src/examples/geometries/adapted/Jamfile.v2 new file mode 100644 index 000000000..2fd3aefaa --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/Jamfile.v2 @@ -0,0 +1,22 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-src-example-geometries-adapted + : # requirements + ; + +exe c_array : c_array.cpp ; +exe boost_array : boost_array.cpp ; +exe boost_fusion : boost_fusion.cpp ; +exe boost_polygon : boost_polygon.cpp ; +exe boost_tuple : boost_tuple.cpp ; + +build-project boost_range ; diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_array.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_array.cpp new file mode 100644 index 000000000..846c0be7b --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_array.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_array +//` Shows how to use a Boost.Array using Boost.Geometry's distance, set and assign_values algorithms + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/adapted/boost_array.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(cs::cartesian) + +int main() +{ + boost::array<float, 2> a = { {1, 2} }; + boost::array<double, 2> b = { {2, 3} }; + std::cout << boost::geometry::distance(a, b) << std::endl; + + boost::geometry::set<0>(a, 1.1); + boost::geometry::set<1>(a, 2.2); + std::cout << boost::geometry::distance(a, b) << std::endl; + + boost::geometry::assign_values(b, 2.2, 3.3); + std::cout << boost::geometry::distance(a, b) << std::endl; + + boost::geometry::model::linestring<boost::array<double, 2> > line; + line.push_back(b); + + return 0; +} + +//] + +//[boost_array_output +/*` +Output: +[pre +1.41421 +1.20416 +1.55563 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_fusion.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_fusion.cpp new file mode 100644 index 000000000..89f044699 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_fusion.cpp @@ -0,0 +1,62 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_fusion +//` Shows how to combine Boost.Fusion with Boost.Geometry + +#include <iostream> + +#include <boost/fusion/include/adapt_struct_named.hpp> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/adapted/boost_fusion.hpp> + + +struct sample_point +{ + double x, y, z; +}; + +BOOST_FUSION_ADAPT_STRUCT(sample_point, (double, x) (double, y) (double, z)) +BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::cartesian) + +int main() +{ + sample_point a, b, c; + + // Set coordinates the Boost.Geometry way (one of the ways) + boost::geometry::assign_values(a, 3, 2, 1); + + // Set coordinates the Boost.Fusion way + boost::fusion::at_c<0>(b) = 6; + boost::fusion::at_c<1>(b) = 5; + boost::fusion::at_c<2>(b) = 4; + + // Set coordinates the native way + c.x = 9; + c.y = 8; + c.z = 7; + + std::cout << "Distance a-b: " << boost::geometry::distance(a, b) << std::endl; + std::cout << "Distance a-c: " << boost::geometry::distance(a, c) << std::endl; + + return 0; +} + +//] + +//[boost_fusion_output +/*` +Output: +[pre +Distance a-b: 5.19615 +Distance a-c: 10.3923 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_polygon.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_polygon.cpp new file mode 100644 index 000000000..3f71990fa --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_polygon.cpp @@ -0,0 +1,38 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_polygon +//`Shows how to use Boost.Polygon points within Boost.Geometry + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/adapted/boost_polygon.hpp> + +int main() +{ + boost::polygon::point_data<int> a(1, 2), b(3, 4); + std::cout << "Distance (using Boost.Geometry): " + << boost::geometry::distance(a, b) << std::endl; + std::cout << "Distance (using Boost.Polygon): " + << boost::polygon::euclidean_distance(a, b) << std::endl; + + return 0; +} + +//] + +//[boost_polygon_output +/*` +Output: +[pre +Distance (using Boost.Geometry): 2.82843 +Distance (using Boost.Polygon): 2.82843 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_range/Jamfile.v2 b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/Jamfile.v2 new file mode 100644 index 000000000..364d30181 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/Jamfile.v2 @@ -0,0 +1,22 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-src-example-geometries-adapted-boost_range + : # requirements + ; + +exe filtered : filtered.cpp ; +exe reversed : reversed.cpp ; +exe sliced : sliced.cpp ; +exe strided : strided.cpp ; +# exe uniqued : uniqued.cpp ; + + diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_range/filtered.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/filtered.cpp new file mode 100644 index 000000000..ffc394a5e --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/filtered.cpp @@ -0,0 +1,64 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_range_filtered +//` Shows how to use a Boost.Geometry linestring, filtered by Boost.Range adaptor + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp> + +struct not_two +{ + template <typename P> + bool operator()(P const& p) const + { + return boost::geometry::get<1>(p) != 2; + } +}; + + +int main() +{ + typedef boost::geometry::model::d2::point_xy<int> xy; + boost::geometry::model::linestring<xy> line; + line.push_back(xy(0, 0)); + line.push_back(xy(1, 1)); + line.push_back(xy(2, 2)); + line.push_back(xy(3, 1)); + line.push_back(xy(4, 0)); + line.push_back(xy(5, 1)); + line.push_back(xy(6, 2)); + line.push_back(xy(7, 1)); + line.push_back(xy(8, 0)); + + using boost::adaptors::filtered; + std::cout + << boost::geometry::length(line) << std::endl + << boost::geometry::length(line | filtered(not_two())) << std::endl + << boost::geometry::dsv(line | filtered(not_two())) << std::endl; + + return 0; +} + +//] + +//[boost_range_filtered_output +/*` +Output: +[pre +11.3137 +9.65685 +((0, 0), (1, 1), (3, 1), (4, 0), (5, 1), (7, 1), (8, 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_range/reversed.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/reversed.cpp new file mode 100644 index 000000000..a73343850 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/reversed.cpp @@ -0,0 +1,43 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_range_reversed +//` Shows how to use a Boost.Geometry linestring, reversed by Boost.Range adaptor + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/boost_range/reversed.hpp> + +int main() +{ + typedef boost::geometry::model::d2::point_xy<int> xy; + boost::geometry::model::linestring<xy> line; + line.push_back(xy(0, 0)); + line.push_back(xy(1, 1)); + + std::cout + << boost::geometry::dsv(line | boost::adaptors::reversed) + << std::endl; + + return 0; +} + +//] + +//[boost_range_reversed_output +/*` +Output: +[pre +((1, 1), (0, 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_range/sliced.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/sliced.cpp new file mode 100644 index 000000000..b07d6d584 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/sliced.cpp @@ -0,0 +1,50 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_range_sliced +//` Shows how to use a Boost.Geometry linestring, sliced by Boost.Range adaptor + +#include <iostream> + +#include <boost/assign.hpp> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/adapted/boost_range/sliced.hpp> + + +int main() +{ + using namespace boost::assign; + + typedef boost::geometry::model::d2::point_xy<int> xy; + boost::geometry::model::linestring<xy> line; + line += xy(0, 0); + line += xy(1, 1); + line += xy(2, 2); + line += xy(3, 3); + line += xy(4, 4); + + std::cout + << boost::geometry::dsv(line | boost::adaptors::sliced(1, 3)) << std::endl; + + return 0; +} + +//] + +//[boost_range_sliced_output +/*` +Output: +[pre +((1, 1), (2, 2)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_range/strided.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/strided.cpp new file mode 100644 index 000000000..95a130acb --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/strided.cpp @@ -0,0 +1,56 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_range_strided +//` Shows how to use a Boost.Geometry ring, strided by Boost.Range adaptor + +#include <iostream> + +#include <boost/assign.hpp> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_range/strided.hpp> + + +int main() +{ + using namespace boost::assign; + using boost::adaptors::strided; + + typedef boost::geometry::model::d2::point_xy<int> xy; + boost::geometry::model::ring<xy> ring; + ring += xy(0, 0); + ring += xy(0, 1); + ring += xy(0, 2); + ring += xy(1, 2); + ring += xy(2, 2); + ring += xy(2, 0); + + boost::geometry::correct(ring); + + std::cout + << "Normal : " << boost::geometry::dsv(ring) << std::endl + << "Strided: " << boost::geometry::dsv(ring | strided(2)) << std::endl; + + return 0; +} + +//] + +//[boost_range_strided_output +/*` +Output: +[pre +Normal : ((0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 0), (0, 0)) +Strided: ((0, 0), (0, 2), (2, 2), (0, 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_range/uniqued.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/uniqued.cpp new file mode 100644 index 000000000..9f138b00c --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_range/uniqued.cpp @@ -0,0 +1,64 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_range_uniqued +//` Shows how to use a Boost.Geometry ring, made unique by Boost.Range adaptor + +#include <iostream> + +#include <boost/assign.hpp> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp> + +typedef boost::geometry::model::d2::point_xy<int> xy; + +inline bool operator==(xy const& left, xy const& right) +{ + boost::geometry::equal_to<xy> eq; + return eq(left, right); +} + + +int main() +{ + using namespace boost::assign; + using boost::adaptors::uniqued; + + boost::geometry::model::ring<xy> ring; + ring += xy(0, 0); + ring += xy(0, 1); + ring += xy(0, 2); + ring += xy(1, 2); + ring += xy(2, 2); + ring += xy(2, 2); + ring += xy(2, 2); + ring += xy(2, 0); + ring += xy(0, 0); + + std::cout + << "Normal: " << boost::geometry::dsv(ring) << std::endl + << "Unique: " << boost::geometry::dsv(ring | uniqued) << std::endl; + + return 0; +} + +//] + +//[boost_range_uniqued_output +/*` +Output: +[pre +Normal : ((0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 0), (0, 0)) +uniqued: ((0, 0), (0, 2), (2, 2), (0, 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/boost_tuple.cpp b/libs/geometry/doc/src/examples/geometries/adapted/boost_tuple.cpp new file mode 100644 index 000000000..747df8881 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/boost_tuple.cpp @@ -0,0 +1,54 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[boost_tuple +/*` +Shows how to use Boost.Tuple points in Boost.Geometry + +Working with Boost.Tuples in Boost.Geometry is straightforward and shown in +various other examples as well. + +*/ + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +int main() +{ + boost::geometry::model::polygon<boost::tuple<double, double> > poly; + poly.outer().push_back(boost::make_tuple(1.0, 2.0)); + poly.outer().push_back(boost::make_tuple(6.0, 4.0)); + poly.outer().push_back(boost::make_tuple(5.0, 1.0)); + poly.outer().push_back(boost::make_tuple(1.0, 2.0)); + + std::cout << "Area: " << boost::geometry::area(poly) << std::endl; + std::cout << "Contains (1.5, 2.5): " + << std::boolalpha + << boost::geometry::within(boost::make_tuple(1.5, 2.5), poly) + << std::endl; + + return 0; +} + +//] + +//[boost_tuple_output +/*` +Output: +[pre +Area: 6.5 +Contains (1.5, 2.5): false +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/adapted/c_array.cpp b/libs/geometry/doc/src/examples/geometries/adapted/c_array.cpp new file mode 100644 index 000000000..335346b89 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/adapted/c_array.cpp @@ -0,0 +1,38 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[c_array +//` Small example showing the combination of an array with a Boost.Geometry algorithm + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) + +int main() +{ + int a[3] = {1, 2, 3}; + int b[3] = {2, 3, 4}; + + std::cout << boost::geometry::distance(a, b) << std::endl; + + return 0; +} + +//] + +//[c_array_output +/*` +Output: +[pre +1.73205 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/point.cpp b/libs/geometry/doc/src/examples/geometries/point.cpp new file mode 100644 index 000000000..82774cd83 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/point.cpp @@ -0,0 +1,42 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[point +//` Declaration and use of the Boost.Geometry model::point, modelling the Point Concept + +#include <iostream> +#include <boost/geometry.hpp> + +namespace bg = boost::geometry; + +int main() +{ + bg::model::point<double, 2, bg::cs::cartesian> point1; + bg::model::point<double, 3, bg::cs::cartesian> point2(1.0, 2.0, 3.0); /*< Construct, assigning three coordinates >*/ + point1.set<0>(1.0); /*< Set a coordinate. [*Note]: prefer using `bg::set<0>(point1, 1.0);` >*/ + point1.set<1>(2.0); + + double x = point1.get<0>(); /*< Get a coordinate. [*Note]: prefer using `x = bg::get<0>(point1);` >*/ + double y = point1.get<1>(); + + std::cout << x << ", " << y << std::endl; + return 0; +} + +//] + + +//[point_output +/*` +Output: +[pre +1, 2 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/Jamfile.v2 b/libs/geometry/doc/src/examples/geometries/register/Jamfile.v2 new file mode 100644 index 000000000..662bd6ee7 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/Jamfile.v2 @@ -0,0 +1,30 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-src-example-geometries-register + : # requirements + ; + +exe box : box.cpp ; +exe box_templated : box_templated.cpp ; +exe box_2d_4values : box_2d_4values.cpp ; +exe point : point.cpp ; + +exe linestring : linestring.cpp ; +exe linestring_templated : linestring_templated.cpp ; +exe ring : ring.cpp ; +exe ring_templated : ring_templated.cpp ; + +exe multi_point : multi_point.cpp ; +exe multi_point_templated : multi_point_templated.cpp ; + +exe multi_linestring : multi_linestring.cpp ; +exe multi_polygon : multi_polygon.cpp ; diff --git a/libs/geometry/doc/src/examples/geometries/register/box.cpp b/libs/geometry/doc/src/examples/geometries/register/box.cpp new file mode 100644 index 000000000..d4b8f6f81 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/box.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_box +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_BOX + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/register/point.hpp> +#include <boost/geometry/geometries/register/box.hpp> + +struct my_point +{ + double x, y; +}; + +struct my_box +{ + my_point ll, ur; +}; + +// Register the point type +BOOST_GEOMETRY_REGISTER_POINT_2D(my_point, double, cs::cartesian, x, y) + +// Register the box type, also notifying that it is based on "my_point" +BOOST_GEOMETRY_REGISTER_BOX(my_box, my_point, ll, ur) + +int main() +{ + my_box b = boost::geometry::make<my_box>(0, 0, 2, 2); + std::cout << "Area: " << boost::geometry::area(b) << std::endl; + return 0; +} + +//] + + +//[register_box_output +/*` +Output: +[pre +Area: 4 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/box_2d_4values.cpp b/libs/geometry/doc/src/examples/geometries/register/box_2d_4values.cpp new file mode 100644 index 000000000..0ae971512 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/box_2d_4values.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_box_2d_4values +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/register/point.hpp> +#include <boost/geometry/geometries/register/box.hpp> + +struct my_point +{ + int x, y; +}; + +struct my_box +{ + int left, top, right, bottom; +}; + +BOOST_GEOMETRY_REGISTER_POINT_2D(my_point, int, cs::cartesian, x, y) + +// Register the box type, also notifying that it is based on "my_point" +// (even if it does not contain it) +BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(my_box, my_point, left, top, right, bottom) + +int main() +{ + my_box b = boost::geometry::make<my_box>(0, 0, 2, 2); + std::cout << "Area: " << boost::geometry::area(b) << std::endl; + return 0; +} + +//] + + +//[register_box_2d_4values_output +/*` +Output: +[pre +Area: 4 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/box_templated.cpp b/libs/geometry/doc/src/examples/geometries/register/box_templated.cpp new file mode 100644 index 000000000..c54e19e06 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/box_templated.cpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_box_templated +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/box.hpp> + +template <typename P> +struct my_box +{ + P ll, ur; +}; + +// Register the box type +BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED(my_box, ll, ur) + +int main() +{ + typedef my_box<boost::geometry::model::d2::point_xy<double> > box; + box b = boost::geometry::make<box>(0, 0, 2, 2); + std::cout << "Area: " << boost::geometry::area(b) << std::endl; + return 0; +} + +//] + + +//[register_box_templated_output +/*` +Output: +[pre +Area: 4 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/linestring.cpp b/libs/geometry/doc/src/examples/geometries/register/linestring.cpp new file mode 100644 index 000000000..ce4d97d7b --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/linestring.cpp @@ -0,0 +1,54 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_linestring +//` Show the use of BOOST_GEOMETRY_REGISTER_LINESTRING + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/linestring.hpp> + +typedef boost::geometry::model::d2::point_xy<double> point_2d; + +BOOST_GEOMETRY_REGISTER_LINESTRING(std::vector<point_2d>) + +int main() +{ + // Normal usage of std:: + std::vector<point_2d> line; + line.push_back(point_2d(1, 1)); + line.push_back(point_2d(2, 2)); + line.push_back(point_2d(3, 1)); + + // Usage of Boost.Geometry's length and wkt functions + std::cout << "Length: " + << boost::geometry::length(line) + << std::endl; + + std::cout << "WKT: " + << boost::geometry::wkt(line) + << std::endl; + + return 0; +} + +//] + + +//[register_linestring_output +/*` +Output: +[pre +Length: 2.82843 +WKT: LINESTRING(1 1,2 2,3 1) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/linestring_templated.cpp b/libs/geometry/doc/src/examples/geometries/register/linestring_templated.cpp new file mode 100644 index 000000000..064f78eee --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/linestring_templated.cpp @@ -0,0 +1,47 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_linestring_templated +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED + +#include <iostream> +#include <deque> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/linestring.hpp> + +// Adapt any deque to Boost.Geometry Linestring Concept +BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque) + +int main() +{ + std::deque<boost::geometry::model::d2::point_xy<double> > line(2); + boost::geometry::assign_values(line[0], 1, 1); + boost::geometry::assign_values(line[1], 2, 2); + + // Boost.Geometry algorithms work on any deque now + std::cout << "Length: " << boost::geometry::length(line) << std::endl; + std::cout << "Line: " << boost::geometry::dsv(line) << std::endl; + + return 0; +} + +//] + + +//[register_linestring_templated_output +/*` +Output: +[pre +Length: 1.41421 +Line: ((1, 1), (2, 2)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/multi_linestring.cpp b/libs/geometry/doc/src/examples/geometries/register/multi_linestring.cpp new file mode 100644 index 000000000..9ed40da73 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/multi_linestring.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_multi_linestring +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_MULTI_LINESTRING + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/multi/geometries/register/multi_linestring.hpp> + +typedef boost::geometry::model::linestring + < + boost::tuple<float, float> + > linestring_type; + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_MULTI_LINESTRING(std::deque<linestring_type>) + +int main() +{ + // Normal usage of std:: + std::deque<linestring_type> lines(2); + boost::geometry::read_wkt("LINESTRING(0 0,1 1)", lines[0]); + boost::geometry::read_wkt("LINESTRING(2 2,3 3)", lines[1]); + + // Usage of Boost.Geometry + std::cout << "LENGTH: " << boost::geometry::length(lines) << std::endl; + + return 0; +} + +//] + + +//[register_multi_linestring_output +/*` +Output: +[pre +LENGTH: 2.82843 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/multi_point.cpp b/libs/geometry/doc/src/examples/geometries/register/multi_point.cpp new file mode 100644 index 000000000..e854da2b0 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/multi_point.cpp @@ -0,0 +1,47 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_multi_point +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_MULTI_POINT + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/multi/geometries/register/multi_point.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + +typedef boost::tuple<float, float> point_type; + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_MULTI_POINT(std::deque< ::point_type >) + +int main() +{ + // Normal usage of std:: + std::deque<point_type> multi_point; + multi_point.push_back(point_type(1, 1)); + multi_point.push_back(point_type(3, 2)); + + // Usage of Boost.Geometry + std::cout << "WKT: " << boost::geometry::wkt(multi_point) << std::endl; + + return 0; +} + +//] + + +//[register_multi_point_output +/*` +Output: +[pre +WKT: MULTIPOINT((1 1),(3 2)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/multi_point_templated.cpp b/libs/geometry/doc/src/examples/geometries/register/multi_point_templated.cpp new file mode 100644 index 000000000..bba16bbbd --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/multi_point_templated.cpp @@ -0,0 +1,47 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_multi_point_templated +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_MULTI_POINT_TEMPLATED + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/multi/geometries/register/multi_point.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + + +BOOST_GEOMETRY_REGISTER_MULTI_POINT_TEMPLATED(std::deque) + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + +int main() +{ + // Normal usage of std:: + std::deque<boost::tuple<float, float> > multi_point; + multi_point.push_back(boost::tuple<float, float>(1, 1)); + multi_point.push_back(boost::tuple<float, float>(3, 2)); + + // Usage of Boost.Geometry + std::cout << "WKT: " << boost::geometry::wkt(multi_point) << std::endl; + + return 0; +} + +//] + + +//[register_multi_point_templated_output +/*` +Output: +[pre +WKT: MULTIPOINT((1 1),(3 2)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/multi_polygon.cpp b/libs/geometry/doc/src/examples/geometries/register/multi_polygon.cpp new file mode 100644 index 000000000..f21f3cf95 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/multi_polygon.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_multi_polygon +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_MULTI_POLYGON + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/polygon.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <boost/geometry/multi/geometries/register/multi_polygon.hpp> + +typedef boost::geometry::model::polygon + < + boost::tuple<float, float> + > polygon_type; + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(std::vector<polygon_type>) + +int main() +{ + // Normal usage of std:: + std::vector<polygon_type> polygons(2); + boost::geometry::read_wkt("POLYGON((0 0,0 1,1 1,1 0,0 0))", polygons[0]); + boost::geometry::read_wkt("POLYGON((3 0,3 1,4 1,4 0,3 0))", polygons[1]); + + // Usage of Boost.Geometry + std::cout << "AREA: " << boost::geometry::area(polygons) << std::endl; + + return 0; +} + +//] + + +//[register_multi_polygon_output +/*` +Output: +[pre +AREA: 2 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/point.cpp b/libs/geometry/doc/src/examples/geometries/register/point.cpp new file mode 100644 index 000000000..9d898b2e0 --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/point.cpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_point_2d +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_POINT_2D + +#include <iostream> +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/register/point.hpp> + +/*< Somewhere, any legacy point struct is defined >*/ +struct legacy_point +{ + double x, y; +}; + +BOOST_GEOMETRY_REGISTER_POINT_2D(legacy_point, double, cs::cartesian, x, y) /*< The magic: adapt it to Boost.Geometry Point Concept >*/ + +int main() +{ + legacy_point p1, p2; + + namespace bg = boost::geometry; + + /*< Any Boost.Geometry function can be used for legacy point now. Here: assign_values and distance >*/ + bg::assign_values(p1, 1, 1); + bg::assign_values(p2, 2, 2); + + double d = bg::distance(p1, p2); + + std::cout << "Distance: " << d << std::endl; + + return 0; +} + +//] + + +//[register_point_2d_output +/*` +Output: +[pre +Distance: 1.41421 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/ring.cpp b/libs/geometry/doc/src/examples/geometries/register/ring.cpp new file mode 100644 index 000000000..4d7ca2a0a --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/ring.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_ring +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_RING + +#include <iostream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/ring.hpp> + +typedef boost::geometry::model::d2::point_xy<double> point_2d; + +BOOST_GEOMETRY_REGISTER_RING(std::vector<point_2d>) /*< The magic: adapt vector to Boost.Geometry Ring Concept >*/ + +int main() +{ + // Normal usage of std:: + std::vector<point_2d> ring; + ring.push_back(point_2d(1, 1)); + ring.push_back(point_2d(2, 2)); + ring.push_back(point_2d(2, 1)); + + + // Usage of Boost.Geometry + boost::geometry::correct(ring); + std::cout << "Area: " << boost::geometry::area(ring) << std::endl; + std::cout << "WKT: " << boost::geometry::wkt(ring) << std::endl; + + return 0; +} + +//] + + +//[register_ring_output +/*` +Output: +[pre +Area: 0.5 +WKT: POLYGON((1 1,2 2,2 1,1 1)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/geometries/register/ring_templated.cpp b/libs/geometry/doc/src/examples/geometries/register/ring_templated.cpp new file mode 100644 index 000000000..0a27c99ca --- /dev/null +++ b/libs/geometry/doc/src/examples/geometries/register/ring_templated.cpp @@ -0,0 +1,49 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[register_ring_templated +//` Show the use of the macro BOOST_GEOMETRY_REGISTER_RING_TEMPLATED + +#include <iostream> +#include <deque> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/register/ring.hpp> + +// Adapt any deque to Boost.Geometry Ring Concept +BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(std::deque) + +int main() +{ + std::deque<boost::geometry::model::d2::point_xy<double> > ring(3); + boost::geometry::assign_values(ring[0], 0, 0); + boost::geometry::assign_values(ring[2], 4, 1); + boost::geometry::assign_values(ring[1], 1, 4); + + // Boost.Geometry algorithms work on any deque now + boost::geometry::correct(ring); + std::cout << "Area: " << boost::geometry::area(ring) << std::endl; + std::cout << "Contents: " << boost::geometry::wkt(ring) << std::endl; + + return 0; +} + +//] + + +//[register_ring_templated_output +/*` +Output: +[pre +Area: 7.5 +Line: ((0, 0), (1, 4), (4, 1), (0, 0)) +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/io/svg.cpp b/libs/geometry/doc/src/examples/io/svg.cpp new file mode 100644 index 000000000..1a423b8c2 --- /dev/null +++ b/libs/geometry/doc/src/examples/io/svg.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2013 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) + +//[svg_mapper +//` Shows the usage of svg_mapper + +#include <iostream> +#include <fstream> + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +int main() +{ + // Specify the basic type + typedef boost::geometry::model::d2::point_xy<double> point_type; + + // Declare some geometries and set their values + point_type a; + boost::geometry::assign_values(a, 3, 6); + + boost::geometry::model::polygon<point_type> b; + boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", b); + + boost::geometry::model::linestring<point_type> c; + c.push_back(point_type(3, 4)); + c.push_back(point_type(4, 5)); + + // Declare a stream and an SVG mapper + std::ofstream svg("my_map.svg"); + boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400); + + // Add geometries such that all these geometries fit on the map + mapper.add(a); + mapper.add(b); + mapper.add(c); + + // Draw the geometries on the SVG map, using a specific SVG style + mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2", 5); + mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2"); + mapper.map(c, "opacity:0.4;fill:none;stroke:rgb(212,0,0);stroke-width:5"); + + // Destructor of map will be called - adding </svg> + // Destructor of stream will be called, closing the file + + return 0; +} + +//] + + +//[svg_mapper_output +/*` +Output: + +[$img/io/svg_mapper.png] +*/ +//] diff --git a/libs/geometry/doc/src/examples/quick_start.cpp b/libs/geometry/doc/src/examples/quick_start.cpp new file mode 100644 index 000000000..9a739efab --- /dev/null +++ b/libs/geometry/doc/src/examples/quick_start.cpp @@ -0,0 +1,167 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Quickbook Examples, for main page + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, 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) +// + + +#if defined(_MSC_VER) +// We deliberately mix float/double's here so turn off warning +//#pragma warning( disable : 4244 ) +#endif // defined(_MSC_VER) + +//[quickstart_include + +#include <boost/geometry.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +using namespace boost::geometry; +//] + +#include <boost/geometry/geometries/register/point.hpp> + + +//[quickstart_register_c_array +#include <boost/geometry/geometries/adapted/c_array.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +//] + +//[quickstart_register_boost_tuple +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> + +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) +//] + +// Small QRect simulations following http://doc.trolltech.com/4.4/qrect.html +// Todo: once work the traits out further, would be nice if there is a real example of this. +// However for the example it makes no difference, it will work any way. +struct QPoint +{ + int x, y; + // In Qt these are methods but for example below it makes no difference +}; + +struct QRect +{ + int x, y, width, height; + QRect(int _x, int _y, int w, int h) + : x(_x), y(_y), width(w), height(h) + {} + // In Qt these are methods but that will work as well, requires changing traits below +}; + + +// Would be get/set with x(),y(),setX(),setY() +BOOST_GEOMETRY_REGISTER_POINT_2D(QPoint, int, cs::cartesian, x, y) + + +// Register the QT rectangle. The macro(s) does not offer (yet) enough flexibility to do this in one line, +// but the traits classes do their job perfectly. +namespace boost { namespace geometry { namespace traits +{ + +template <> struct tag<QRect> { typedef box_tag type; }; +template <> struct point_type<QRect> { typedef QPoint type; }; + +template <size_t C, size_t D> +struct indexed_access<QRect, C, D> +{ + static inline int get(const QRect& qr) + { + // Would be: x(), y(), width(), height() + return C == min_corner && D == 0 ? qr.x + : C == min_corner && D == 1 ? qr.y + : C == max_corner && D == 0 ? qr.x + qr.width + : C == max_corner && D == 1 ? qr.y + qr.height + : 0; + } + + static inline void set(QRect& qr, const int& value) + { + // Would be: setX, setY, setWidth, setHeight + if (C == min_corner && D == 0) qr.x = value; + else if (C == min_corner && D == 1) qr.y = value; + else if (C == max_corner && D == 0) qr.width = value - qr.x; + else if (C == max_corner && D == 1) qr.height = value - qr.y; + } +}; + + +}}} + + +int main(void) +{ + //[quickstart_distance + model::d2::point_xy<int> p1(1, 1), p2(2, 2); + std::cout << "Distance p1-p2 is: " << distance(p1, p2) << std::endl; + //] + + //[quickstart_distance_c_array + int a[2] = {1,1}; + int b[2] = {2,3}; + double d = distance(a, b); + std::cout << "Distance a-b is: " << d << std::endl; + //] + + //[quickstart_point_in_polygon + double points[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}}; + model::polygon<model::d2::point_xy<double> > poly; + append(poly, points); + boost::tuple<double, double> p = boost::make_tuple(3.7, 2.0); + std::cout << "Point p is in polygon? " << std::boolalpha << within(p, poly) << std::endl; + //] + + //[quickstart_area + std::cout << "Area: " << area(poly) << std::endl; + //] + + //[quickstart_distance_mixed + double d2 = distance(a, p); + std::cout << "Distance a-p is: " << d2 << std::endl; + //] + + //[quick_start_spherical + typedef boost::geometry::model::point + < + double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree> + > spherical_point; + + spherical_point amsterdam(4.90, 52.37); + spherical_point paris(2.35, 48.86); + + double const earth_radius = 3959; // miles + std::cout << "Distance in miles: " << distance(amsterdam, paris) * earth_radius << std::endl; + //] + + /*** + Now extension + point_ll_deg amsterdam, paris; + parse(amsterdam, "52 22 23 N", "4 53 32 E"); + parse(paris, "48 52 0 N", "2 19 59 E"); + std::cout << "Distance A'dam-Paris: " << distance(amsterdam, paris) / 1000.0 << " kilometers " << std::endl; + ***/ + + //[quickstart_qt + QRect r1(100, 200, 15, 15); + QRect r2(110, 210, 20, 20); + if (overlaps(r1, r2)) + { + assign_values(r2, 200, 300, 220, 320); + } + //] + + return 0; +} + diff --git a/libs/geometry/doc/src/examples/views/Jamfile.v2 b/libs/geometry/doc/src/examples/views/Jamfile.v2 new file mode 100644 index 000000000..4dd82eab8 --- /dev/null +++ b/libs/geometry/doc/src/examples/views/Jamfile.v2 @@ -0,0 +1,17 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +# 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) + + +project boost-geometry-doc-example-views + : # requirements + ; + +exe box_view : box_view.cpp ; +exe segment_view : segment_view.cpp ; diff --git a/libs/geometry/doc/src/examples/views/box_view.cpp b/libs/geometry/doc/src/examples/views/box_view.cpp new file mode 100644 index 000000000..e95b54ecb --- /dev/null +++ b/libs/geometry/doc/src/examples/views/box_view.cpp @@ -0,0 +1,58 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[box_view +//` Shows usage of the Boost.Range compatible view on a box + +#include <iostream> + +#include <boost/geometry.hpp> + + +int main() +{ + typedef boost::geometry::model::box + < + boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> + > box_type; + + // Define the Boost.Range compatible type: + typedef boost::geometry::box_view<box_type> box_view; + + box_type box; + boost::geometry::assign_values(box, 0, 0, 4, 4); + + box_view view(box); + + // Iterating in clockwise direction over the points of this box + for (boost::range_iterator<box_view const>::type it = boost::begin(view); + it != boost::end(view); ++it) + { + std::cout << " " << boost::geometry::dsv(*it); + } + std::cout << std::endl; + + // Note that a box_view is tagged as a ring, so supports area etc. + std::cout << "Area: " << boost::geometry::area(view) << std::endl; + + return 0; +} + +//] + + +//[box_view_output +/*` +Output: +[pre + (0, 0) (0, 4) (4, 4) (4, 0) (0, 0) +Area: 16 +] +*/ +//] diff --git a/libs/geometry/doc/src/examples/views/segment_view.cpp b/libs/geometry/doc/src/examples/views/segment_view.cpp new file mode 100644 index 000000000..5337189f9 --- /dev/null +++ b/libs/geometry/doc/src/examples/views/segment_view.cpp @@ -0,0 +1,57 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// QuickBook Example + +// Copyright (c) 2011-2012 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) + +//[segment_view +//` Shows usage of the Boost.Range compatible view on a box + +#include <iostream> + +#include <boost/geometry.hpp> + + +int main() +{ + typedef boost::geometry::model::segment + < + boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> + > segment_type; + + typedef boost::geometry::segment_view<segment_type> segment_view; + + segment_type segment; + boost::geometry::assign_values(segment, 0, 0, 1, 1); + + segment_view view(segment); + + // Iterating over the points of this segment + for (boost::range_iterator<segment_view const>::type it = boost::begin(view); + it != boost::end(view); ++it) + { + std::cout << " " << boost::geometry::dsv(*it); + } + std::cout << std::endl; + + // Note that a segment_view is tagged as a linestring, so supports length etc. + std::cout << "Length: " << boost::geometry::length(view) << std::endl; + + return 0; +} + +//] + + +//[segment_view_output +/*` +Output: +[pre + (0, 0) (0, 4) (4, 4) (4, 0) (0, 0) +Area: 16 +] +*/ +//] |