...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Boost.Polygon's polygon type supporting holes (boost::polygon::polygon_with_holes_data) is adapted to the Boost.Geometry Polygon Concept.
Boost.Polygon's points (as well as polygons) can be used by Boost.Geometry. The two libraries can therefore be used together. Using a boost::polygon::polygon_with_holes_data<...>, algorithms from both Boost.Polygon and Boost.Geometry can be called.
#include <boost/geometry/geometries/adapted/boost_polygon.hpp>
The standard header boost/geometry.hpp
does not include this header.
Shows how to use Boost.Polygon polygon_with_holes_data within Boost.Geometry
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/adapted/boost_polygon.hpp> int main() { typedef boost::polygon::polygon_with_holes_data<int> polygon; typedef boost::polygon::polygon_traits<polygon>::point_type point; typedef boost::polygon::polygon_with_holes_traits<polygon>::hole_type hole; point pts[5] = { boost::polygon::construct<point>(0, 0), boost::polygon::construct<point>(0, 10), boost::polygon::construct<point>(10, 10), boost::polygon::construct<point>(10, 0), boost::polygon::construct<point>(0, 0) }; point hole_pts[5] = { boost::polygon::construct<point>(1, 1), boost::polygon::construct<point>(9, 1), boost::polygon::construct<point>(9, 9), boost::polygon::construct<point>(1, 9), boost::polygon::construct<point>(1, 1) }; hole hls[1]; boost::polygon::set_points(hls[0], hole_pts, hole_pts+5); polygon poly; boost::polygon::set_points(poly, pts, pts+5); boost::polygon::set_holes(poly, hls, hls+1); std::cout << "Area (using Boost.Geometry): " << boost::geometry::area(poly) << std::endl; std::cout << "Area (using Boost.Polygon): " << boost::polygon::area(poly) << std::endl; return 0; }
Output:
Area (using Boost.Geometry): 36 Area (using Boost.Polygon): 36