diff --git a/doc/geometry.qbk b/doc/geometry.qbk index 8efd9f954..4415d1497 100644 --- a/doc/geometry.qbk +++ b/doc/geometry.qbk @@ -29,6 +29,7 @@ [def __0dim__ pointlike (e.g. point)] [def __1dim__ linear (e.g. linestring)] [def __2dim__ areal (e.g. polygon)] +[def DIM2 areal (e.g. polygon)] [def __single__ single (e.g. point, polygon)] [def __multi__ multiple (e.g. multi_point, multi_polygon)] [def __cart__ Cartesian] @@ -41,6 +42,7 @@ [def __point__ Point] [def __linestring__ Linestring] [def __polygon__ Polygon] +[def __ring__ Ring] [def __multi_point__ Multi point] [def __multi_polygon__ Multi Polygon] [def __range__ Rangelike (linestring, ring)] @@ -71,6 +73,7 @@ Simplify algorithm [link geometry.reference.algorithms.simplify.simplify_3 here] [import src/examples/quick_start.cpp] [import src/examples/algorithms/area.cpp] [import src/examples/algorithms/area_with_strategy.cpp] +[import src/examples/algorithms/append.cpp] [import src/examples/algorithms/assign_2d_point.cpp] [import src/examples/algorithms/assign_3d_point.cpp] [import src/examples/algorithms/assign_box_corners.cpp] @@ -78,6 +81,7 @@ Simplify algorithm [link geometry.reference.algorithms.simplify.simplify_3 here] [import src/examples/algorithms/assign_with_range.cpp] [import src/examples/algorithms/assign_point_to_index.cpp] [import src/examples/algorithms/assign_point_from_index.cpp] +[import src/examples/algorithms/difference.cpp] [import src/examples/algorithms/for_each_point.cpp] [import src/examples/algorithms/for_each_point_const.cpp] [import src/examples/algorithms/for_each_segment_const.cpp] @@ -89,12 +93,15 @@ Simplify algorithm [link geometry.reference.algorithms.simplify.simplify_3 here] [import src/examples/algorithms/make_with_range.cpp] [import src/examples/algorithms/intersection_ls_ls_point.cpp] [import src/examples/algorithms/intersection_segment.cpp] +[import src/examples/algorithms/intersection_poly_poly.cpp] [import src/examples/algorithms/intersects_linestring.cpp] [import src/examples/algorithms/num_geometries.cpp] [import src/examples/algorithms/num_interior_rings.cpp] [import src/examples/algorithms/num_points.cpp] [import src/examples/algorithms/simplify.cpp] [import src/examples/algorithms/simplify_inserter.cpp] +[import src/examples/algorithms/sym_difference.cpp] +[import src/examples/algorithms/union.cpp] [import src/examples/core/get_point.cpp] [import src/examples/core/get_box.cpp] [import src/examples/core/set_point.cpp] diff --git a/doc/html/img/algorithms/difference_a.png b/doc/html/img/algorithms/difference_a.png new file mode 100644 index 000000000..ce019857e Binary files /dev/null and b/doc/html/img/algorithms/difference_a.png differ diff --git a/doc/html/img/algorithms/difference_b.png b/doc/html/img/algorithms/difference_b.png new file mode 100644 index 000000000..ae3e61795 Binary files /dev/null and b/doc/html/img/algorithms/difference_b.png differ diff --git a/doc/html/img/algorithms/intersection.png b/doc/html/img/algorithms/intersection.png new file mode 100644 index 000000000..51e91eabf Binary files /dev/null and b/doc/html/img/algorithms/intersection.png differ diff --git a/doc/html/img/algorithms/sym_difference.png b/doc/html/img/algorithms/sym_difference.png new file mode 100644 index 000000000..50963b5c4 Binary files /dev/null and b/doc/html/img/algorithms/sym_difference.png differ diff --git a/doc/html/img/algorithms/union.png b/doc/html/img/algorithms/union.png new file mode 100644 index 000000000..ff841f8f0 Binary files /dev/null and b/doc/html/img/algorithms/union.png differ diff --git a/doc/ref/algorithms/append.qbk b/doc/ref/algorithms/append.qbk new file mode 100644 index 000000000..4261adfb5 --- /dev/null +++ b/doc/ref/algorithms/append.qbk @@ -0,0 +1,33 @@ +[/============================================================================ + Boost.Geometry (aka GGL, Generic Geometry Library) + + Copyright (c) 2009-2011 Barend Gehrels, Geodan, Amsterdam, the Netherlands. + Copyright (c) 2009-2011 Mateusz Loskot (mateusz@loskot.net) + Copyright (c) 2009-2011 Bruno Lalande, Paris, France. + + 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) +=============================================================================/] + +[heading Behavior] +[table +[[Case] [Behavior] ] +[[__point__, __box__, __segment__][Compiles, but no action]] +[[__linestring__][Appends point or range to the end of the linestring]] +[[__ring__][Appends point or range to the end of the ring (without explicitly closing it)]] +[[__polygon__][Appends point or range to the end of the polygon (without explicitly closing it), + either the exterior ring (the default) or specify a zero-based index for one of the interior rings. + In the last case, the interior rings are not resized automatically, + so ensure that the zero-based index is smaller than the number of interior rings]] +] + +[heading Complexity] +Linear + +[heading Example] +[append] +[append_output] + +[heading See also] +* [link geometry.reference.algorithms.assign.assign_2_with_a_range assign] diff --git a/doc/ref/algorithms/intersection.qbk b/doc/ref/algorithms/intersection.qbk index df4ac5dfc..ad897034f 100644 --- a/doc/ref/algorithms/intersection.qbk +++ b/doc/ref/algorithms/intersection.qbk @@ -18,3 +18,11 @@ [[[qbk_out __polygon__]][Calculates intersection polygons input (multi)polygons and/or boxes]] ] +[heading Example] +[intersection] +[intersection_output] + +[heading See also] +* [link geometry.reference.algorithms.union.union_ union] +* [link geometry.reference.algorithms.difference.difference difference] +* [link geometry.reference.algorithms.sym_difference.sym_difference sym_difference (symmetric difference)] diff --git a/doc/ref/algorithms/sym_difference.qbk b/doc/ref/algorithms/sym_difference.qbk new file mode 100644 index 000000000..cf0b8d0da --- /dev/null +++ b/doc/ref/algorithms/sym_difference.qbk @@ -0,0 +1,29 @@ +[/============================================================================ + Boost.Geometry (aka GGL, Generic Geometry Library) + + Copyright (c) 2009-2011 Barend Gehrels, Geodan, Amsterdam, the Netherlands. + Copyright (c) 2009-2011 Mateusz Loskot (mateusz@loskot.net) + Copyright (c) 2009-2011 Bruno Lalande, Paris, France. + + 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) +=============================================================================/] + +[heading Behavior] +[table +[[Case] [Behavior] ] +[[__2dim__][All combinations of: box, ring, polygon, multi_polygon]] +[[__other__][Not supported]] + +] + +[heading Example] +[sym_difference] +[sym_difference_output] + +[heading See also] +* [link geometry.reference.algorithms.difference.difference difference] +* [link geometry.reference.algorithms.intersection.intersection intersection] +* [link geometry.reference.algorithms.union.union_ union] + diff --git a/doc/ref/algorithms/union.qbk b/doc/ref/algorithms/union.qbk new file mode 100644 index 000000000..d6bb91591 --- /dev/null +++ b/doc/ref/algorithms/union.qbk @@ -0,0 +1,25 @@ +[/============================================================================ + Boost.Geometry (aka GGL, Generic Geometry Library) + + Copyright (c) 2009-2011 Barend Gehrels, Geodan, Amsterdam, the Netherlands. + Copyright (c) 2009-2011 Mateusz Loskot (mateusz@loskot.net) + Copyright (c) 2009-2011 Bruno Lalande, Paris, France. + + 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) +=============================================================================/] + +[heading Behavior] +[table +[[Case] [Behavior] ] +] + +[heading Example] +[union] +[union_output] + +[heading See also] +* [link geometry.reference.algorithms.intersection.intersection intersection] +* [link geometry.reference.algorithms.difference.difference difference] +* [link geometry.reference.algorithms.sym_difference.sym_difference sym_difference (symmetric difference)] diff --git a/doc/ref/core/set_point.qbk b/doc/ref/core/set_point.qbk index 807ac2958..8591a655b 100644 --- a/doc/ref/core/set_point.qbk +++ b/doc/ref/core/set_point.qbk @@ -8,6 +8,7 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================/] +[note If you host both the std:: library namespace and boost::geometry:: namespace set might become ambiguous, std::set is a collection. So don't do that or refer to geometry::set then explicitly.] [heading Behavior] [table diff --git a/doc/reference/append.qbk b/doc/reference/append.qbk index 5c3e009f3..627f7ca8a 100644 --- a/doc/reference/append.qbk +++ b/doc/reference/append.qbk @@ -15,20 +15,20 @@ [/ Generated from doxy/doxygen_output/xml/group__append.xml] [section:append append] -Appends one or more points to a linestring, ring, polygon, multi. +Appends one or more points to a linestring, ring, polygon, multi-geometry. [heading Synopsis] -``template -void append(Geometry & geometry, RoP const & range_or_point, int ring_index = -1, int multi_index = 0)`` +``template +void append(Geometry & geometry, RangeOrPoint const & range_or_point, int ring_index = -1, int multi_index = 0)`` [heading Parameters] [table [[Type] [Concept] [Name] [Description] ] -[[Geometry &] [] [geometry] [a geometry ]] -[[RoP const &] [] [range_or_point] [the point or range to add ]] -[[int] [] [ring_index] [the index of the ring in case of a polygon: exterior ring (-1, the default) or interior ring index ]] -[[int] [] [multi_index] [reserved for multi polygons ]] +[[Geometry &] [Any type fulfilling a Geometry Concept ] [geometry] [A model of the specified concept ]] +[[RangeOrPoint const &] [Either a range or a point, fullfilling Boost.Range concept or Boost.Geometry Point Concept ] [range_or_point] [The point or range to add ]] +[[int] [] [ring_index] [The index of the ring in case of a polygon: exterior ring (-1, the default) or interior ring index ]] +[[int] [] [multi_index] [Reserved for multi polygons or multi linestrings]] ] @@ -41,6 +41,8 @@ Or `#include ` +[include ref/algorithms/append.qbk] + [endsect] diff --git a/doc/reference/assign.qbk b/doc/reference/assign.qbk index d5c08bd99..15119af86 100644 --- a/doc/reference/assign.qbk +++ b/doc/reference/assign.qbk @@ -39,11 +39,14 @@ Or `#include ` +[heading Notes] +[note Assign automatically clears the geometry before assigning (use append if you don't want that)] [heading Example] [assign_with_range] [assign_with_range_output] [heading See also] * [link geometry.reference.algorithms.make.make_1_with_a_range make] +* [link geometry.reference.algorithms.append.append append] [endsect] diff --git a/doc/reference/difference.qbk b/doc/reference/difference.qbk index 53a54e304..3ea6f5950 100644 --- a/doc/reference/difference.qbk +++ b/doc/reference/difference.qbk @@ -30,7 +30,7 @@ void difference(Geometry1 const & geometry1, Geometry2 const & geometry2, Collec [[Type] [Concept] [Name] [Description] ] [[Geometry1 const &] [Any type fulfilling a Geometry Concept ] [geometry1] [A model of the specified concept ]] [[Geometry2 const &] [Any type fulfilling a Geometry Concept ] [geometry2] [A model of the specified concept ]] -[[Collection &] [output collection, either a multi-geometry, or a std::vector / std::deque etc ] [output_collection] [the output collection ]] +[[Collection &] [output collection, either a multi-geometry, or a std::vector / std::deque etc ] [output_collection] [the output collection]] ] @@ -43,6 +43,8 @@ Or `#include ` +[include ref/algorithms/difference.qbk] + [endsect] diff --git a/doc/reference/sym_difference.qbk b/doc/reference/sym_difference.qbk index c16368b86..cf597a1ac 100644 --- a/doc/reference/sym_difference.qbk +++ b/doc/reference/sym_difference.qbk @@ -27,7 +27,7 @@ void sym_difference(Geometry1 const & geometry1, Geometry2 const & geometry2, Co [[Type] [Concept] [Name] [Description] ] [[Geometry1 const &] [Any type fulfilling a Geometry Concept ] [geometry1] [A model of the specified concept ]] [[Geometry2 const &] [Any type fulfilling a Geometry Concept ] [geometry2] [A model of the specified concept ]] -[[Collection &] [output collection, either a multi-geometry, or a std::vector / std::deque etc ] [output_collection] [the output collection ]] +[[Collection &] [output collection, either a multi-geometry, or a std::vector / std::deque etc ] [output_collection] [the output collection]] ] @@ -40,6 +40,8 @@ Or `#include ` +[include ref/algorithms/sym_difference.qbk] + [endsect] diff --git a/doc/reference/union.qbk b/doc/reference/union.qbk index 225a66c78..a08f5fe37 100644 --- a/doc/reference/union.qbk +++ b/doc/reference/union.qbk @@ -40,6 +40,8 @@ Or `#include ` +[include ref/algorithms/union.qbk] + [endsect] diff --git a/doc/src/examples/algorithms/append.cpp b/doc/src/examples/algorithms/append.cpp new file mode 100644 index 000000000..b2859e19f --- /dev/null +++ b/doc/src/examples/algorithms/append.cpp @@ -0,0 +1,59 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, 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) +// +// Quickbook Example + +//[append +//` Shows usage of Boost.Geometry's append to append a point or a range to a polygon + +#include + +#include +#include +#include + +#include + +int main() +{ + using boost::assign::tuple_list_of; + using boost::make_tuple; + using boost::geometry::append; + + typedef boost::geometry::model::polygon > 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); + // 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/doc/src/examples/algorithms/create_svg.hpp b/doc/src/examples/algorithms/create_svg.hpp new file mode 100644 index 000000000..189ddab64 --- /dev/null +++ b/doc/src/examples/algorithms/create_svg.hpp @@ -0,0 +1,46 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, 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) +// +// Code to create SVG for examples +#ifndef CREATE_SVG_HPP +#define CREATE_SVG_HPP + +#include +#include +#include + +template +void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range) +{ + std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl; + + typedef typename boost::geometry::point_type::type point_type; + std::ofstream svg(filename.c_str()); + + boost::geometry::svg_mapper 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(Geometry 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::make_centroid(g), out.str(), + "fill:rgb(0,0,0);font-family:Arial;font-size:10px"); + } +} + +// NOTE: convert manually from svg to png using Inkscape ctrl-shift-E +// and copy png to html/img/algorithms/ + + +#endif // CREATE_SVG_HPP + diff --git a/doc/src/examples/algorithms/difference.cpp b/doc/src/examples/algorithms/difference.cpp new file mode 100644 index 000000000..61f31e3a2 --- /dev/null +++ b/doc/src/examples/algorithms/difference.cpp @@ -0,0 +1,89 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, 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) +// +// Quickbook Example + +//[difference +//` Shows how to subtract one polygon from another polygon + +#include +#include + +#include +#include +#include + +#include +/*<-*/ #include "create_svg.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon > 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 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_a.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/doc/src/examples/algorithms/intersection_poly_poly.cpp b/doc/src/examples/algorithms/intersection_poly_poly.cpp new file mode 100644 index 000000000..87e4ec2cf --- /dev/null +++ b/doc/src/examples/algorithms/intersection_poly_poly.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, 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) +// +// Quickbook Example + +//[intersection +//` Shows the intersection of two polygons + +#include +#include + +#include +#include +#include + +#include +/*<-*/ #include "create_svg.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon > 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 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/doc/src/examples/algorithms/sym_difference.cpp b/doc/src/examples/algorithms/sym_difference.cpp new file mode 100644 index 000000000..d6cb94106 --- /dev/null +++ b/doc/src/examples/algorithms/sym_difference.cpp @@ -0,0 +1,75 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, 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) +// +// Quickbook Example + +//[sym_difference +//` Shows how to calculate the symmetric difference (XOR) geometry of two polygons + +#include +#include + +#include +#include +#include + +#include +/*<-*/ #include "create_svg.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon > 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 output; + boost::geometry::sym_difference(green, blue, output); + + int i = 0; + std::cout << "green XOR blue:" << std::endl; + BOOST_FOREACH(polygon const& p, output) + { + std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; + } + + /*<-*/ create_svg("sym_difference.svg", green, blue, output); /*->*/ + return 0; +} + +//] + + +//[sym_difference_output +/*` +Output: +[pre +green XOR blue: +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/doc/src/examples/algorithms/union.cpp b/doc/src/examples/algorithms/union.cpp new file mode 100644 index 000000000..5e06c20d9 --- /dev/null +++ b/doc/src/examples/algorithms/union.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 2011, 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) +// +// Quickbook Example + +//[union +//` Shows how to get a united geometry of two polygons + +#include +#include + +#include +#include +#include + +#include +/*<-*/ #include "create_svg.hpp" /*->*/ + +int main() +{ + typedef boost::geometry::model::polygon > 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 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] + +] +*/ +//] +