...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 (boost::polygon::polygon_data) is adapted to the Boost.Geometry Ring 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_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_data within Boost.Geometry
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/adapted/boost_polygon.hpp> int main() { typedef boost::polygon::polygon_data<int> polygon; typedef boost::polygon::polygon_traits<polygon>::point_type point; 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) }; polygon poly; boost::polygon::set_points(poly, pts, pts+5); 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): 100 Area (using Boost.Polygon): 100