(C++) BoostGeometryExample6

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) BoostGeometryExample6

 

BoostQt
CreatorLubuntu

 

Boost.Geometry example 6: See if a point is within a polygon 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: ./CppBoostGeometryExample6/CppBoostGeometryExample6.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

 

 

 

 

 

./CppBoostGeometryExample6/main.cpp

 


#include <cassert> #include <iostream> #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> #pragma GCC diagnostic pop int main() {   using namespace boost::geometry;   /* Polygon used:     3-      |     2-    4 #      |   / \     1-  2   3      |  | * |     0-  0---1      |      +--|---|---|         0   1   2   *: point that is tested to be within the polygon   #: point that is tested to be outside of the polygon   */   const std::vector<model::d2::point_xy<double>> points {     {0.0, 0.0}, {1.0, 0.0}, {0.0, 2.0}, {1.0, 2.0}, {0.5, 2.0}   };   model::polygon<model::d2::point_xy<double> > house;   append(house, points);   assert( within(model::d2::point_xy<double>(0.5, 0.5), house));   assert(!within(model::d2::point_xy<double>(1.0, 2.0), house)); }