(C++) BoostGeometryExample8

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) BoostGeometryExample8

 

BoostQt
CreatorLubuntu

 

Boost.Geometry example 8: Convert points to a polygon and back is a Boost.Geometry example.

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • Qt Qt: version 5.4.1 (32 bit)
  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppBoostGeometryExample8/CppBoostGeometryExample8.pro

 


exists(../../ConsoleApplication.pri) {   include(../../ConsoleApplication.pri) } !exists(../../ConsoleApplication.pri) {   QT += core   QT += gui   greaterThan(QT_MAJOR_VERSION, 4): QT += widgets   CONFIG   += console   CONFIG   -= app_bundle   TEMPLATE = app   CONFIG(release, debug|release) {     DEFINES += NDEBUG NTRACE_BILDERBIKKEL   }   QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++   unix {     QMAKE_CXXFLAGS += -Werror   } } exists(../../Libraries/Boost.pri) {   include(../../Libraries/Boost.pri) } !exists(../../Libraries/Boost.pri) {   win32 {     INCLUDEPATH += \       ../../Libraries/boost_1_55_0   } } SOURCES += main.cpp

 

 

 

 

 

./CppBoostGeometryExample8/main.cpp

 


#include <cassert> #include <iostream> #include <vector> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #pragma GCC diagnostic ignored "-Wunused-variable" #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> #pragma GCC diagnostic pop int main() {   typedef boost::geometry::model::d2::point_xy<double> Point;   typedef boost::geometry::model::polygon<Point> Polygon;   //Obtain the points   const std::vector<Point> points {       {15.9835,631.923},       {8.24075,628.579},       {8.24075,679.58 },       {15.9835,682.926}   };   //Create a polygon from these points   Polygon polygon;   boost::geometry::append(polygon, points);   assert(boost::geometry::num_points(polygon) == 4);   //Create the points back again from that polygon   const std::vector<Point> points_again = polygon.outer();   //Initial and re-created points must be equal   assert(     std::equal(points.begin(),points.end(),points_again.begin(),       [](const boost::geometry::model::d2::point_xy<double>& a, const boost::geometry::model::d2::point_xy<double>& b)       {         return boost::geometry::equals(a,b);       }     )   ); }