[Boost-bugs] [Boost C++ Libraries] #11576: boost::geometry::intersection wrong results

Subject: [Boost-bugs] [Boost C++ Libraries] #11576: boost::geometry::intersection wrong results
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-08-24 17:01:43


#11576: boost::geometry::intersection wrong results
------------------------------+---------------------------
 Reporter: alex-x@… | Owner: barendgehrels
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: geometry
  Version: Boost 1.59.0 | Severity: Problem
 Keywords: intersection |
------------------------------+---------------------------
 Here is a code of intersection of two 2d triangles.
 boost::geometry::intersection (inside get_poly_intersection_area_S_2d
 function) gives empty result.
 It was ok in boost 1.55.0 version.

 {{{
 // boost_geom.cpp : Defines the entry point for the console application.
 //

 #include "stdafx.h"
 #include <time.h>
 #include <deque>

 #include <boost/geometry.hpp>
 #include <boost/geometry/geometries/point_xy.hpp>
 #include <boost/geometry/geometries/polygon.hpp>
 #include <boost/foreach.hpp>


 bool get_poly_intersection_area_S_2d( const double *poly_x_1,
 const int poly_n_1,
 const double *poly_x_2, const int poly_n_2, double *S)
 {
         // intersects two 2d polygons using boost::geometry library
         // polygons are in 3d format [(x0, y0, 0.0) (x1, y1, 0.0) ....
 (xn, yn, 0.0) ]
         // S is resulting area of intersection
         // returns true if intersection exists (area > DBL_EPSILON) and
 false otherwise

         typedef boost::geometry::model::d2::point_xy<double> bg_point;
         typedef boost::geometry::model::polygon< bg_point, false, false >
 bg_polygon;

         *S = 0.0;

         bg_polygon bg_poly_1, bg_poly_2;

         // init boost 2d polygons by our double 3D polygons
         for(int i=0; i<poly_n_1; i++)
                 bg_poly_1.outer().push_back(bg_point(poly_x_1[i*3],
 poly_x_1[i*3+1]));

         for(int i=0; i<poly_n_2; i++)
                 bg_poly_2.outer().push_back(bg_point(poly_x_2[i*3],
 poly_x_2[i*3+1]));

         // correct polygons
         boost::geometry::correct(bg_poly_1);
         boost::geometry::correct(bg_poly_2);

         // call intersection
         std::deque<bg_polygon> output;
         bool res = boost::geometry::intersection(bg_poly_1, bg_poly_2,
 output);

         if(!res)
                 return false;

         // for each polygon of intersection we add area
         BOOST_FOREACH(bg_polygon const& p, output)
         {
                 double s = boost::geometry::area(p);
                 *S += s;
         }

         // no intersection
         if(fabs(*S) <= DBL_EPSILON)
                 return false;

         // intersection > DBL_EPSILON
         return true;
 }


 int _tmain(int argc, _TCHAR* argv[])
 {
         /*double p1[3 * 3] = {0.00000000000000000,
                         -0.00000000000000000,
                         0.00000000000000000,
                         0.0025482760575599476,
                         0.00000000000000000,
                         0.00000000000000000,
                         0.00053468140165232941,
                         0.0010376086029810613,
                         0.00000000000000000};

         double p2[4 * 3] = {0.0030662413355881501,
                         0.0010051691098038377,
                         0.00000000000000000,
                         0.0019811507896907981,
                         -0.0011005695262458440,
                         0.00000000000000000,
                         -3.2443866216813556e-005,
                         -6.2960923264770714e-005,
                         0.00000000000000000,
                         0.0010526466796805442,
                         0.0020427777127849226,
                         0.00000000000000000};*/

         double p1[3 * 3]={
                         -0.00000000000000000 ,
                         0.00000000000000000 ,
                         0.00000000000000000 ,
                         0.0030892383152813277,
                         0.00000000000000000 ,
                         0.00000000000000000 ,
                         0.0017033357506405240,
                         0.0015364430953530355,
                         0.00000000000000000

         };

         double p2[3 * 3] = {
                         0.0023117731015916947,
                         0.00082400923980274917,
                         0.00000000000000000,
                         0.00079878052059454633,
                         0.00072051609032968962,
                         0.00000000000000000,
                         0.0016845031281539609,
                         0.0015194556912103366,
                         0.00000000000000000
         };



         double s = 0;
         get_poly_intersection_area_S_2d(p1, 3, p2, 3, &s);

         return 0;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11576>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC