Menu

polygon difference leads to single hole?

David
2013-11-19
2013-11-21
  • David

    David - 2013-11-19

    I have two polygons, each a single outer contour, and I take the difference. If I set ioStrictlySimple in the constructor, which I'd prefer, I get the wrong result --- a single hole contour, which I can correct if I make an additional subsequent call to SimplifyPolygons. If I omit ioStrictlySimple from the constructor, I get the right result --- a single outer contour. I'm using 6.1.0 (r427). I'm wondering if you can help explain this behavior to me.

    Thanks,
    David

    #include "clipper.hpp"
    #include <iostream>
    
    using namespace ClipperLib;
    
    int main()
    {
       Paths subj(1);
       subj[0].resize(10);
       subj[0][0].X = 100000000000; subj[0][0].Y =  -99927485759;
       subj[0][1].X =  60244181434; subj[0][1].Y =   99927485759;
       subj[0][2].X =  49428200065; subj[0][2].Y =   99932394745;
       subj[0][3].X =  49228360048; subj[0][3].Y =   99834107441;
       subj[0][4].X =  -1341823808; subj[0][4].Y =   76996742309;
       subj[0][5].X = -54872755473; subj[0][5].Y =   54994282377;
       subj[0][6].X = -44113522444; subj[0][6].Y =   99974849973;
       subj[0][7].X = -94663704473; subj[0][7].Y =   99997792886;
       subj[0][8].X = -97426442119; subj[0][8].Y =   89176753675;
       subj[0][9].X = -60717536628; subj[0][9].Y = -100000000000;
    
       Paths clip(1);
       clip[0].resize(4);
       clip[0][0].X = -111508319343; clip[0][0].Y =  34021119982;
       clip[0][1].X =  -54872755473; clip[0][1].Y =  54994282377;
       clip[0][2].X =  -35169444992; clip[0][2].Y = 137366890777;
       clip[0][3].X =  -90623819090; clip[0][3].Y = 115821140498;
    
       Clipper c(ioStrictlySimple | ioPreserveCollinear);
       c.AddPaths(subj, ptSubject, true);
       c.AddPaths(clip, ptClip   , true);
    
       Paths result;
       bool succeeded = c.Execute(ctDifference, result);
       //SimplifyPolygons(result);
    
       if (succeeded) {
         for (Paths::size_type ic=0; ic < result.size(); ++ic) {
           for (Path::size_type iv=0; iv < result[ic].size(); ++iv) {
             std::cout << result[ic][iv].X << " " << result[ic][iv].Y <<  std::endl;
           }
           if (Orientation(result[ic])) {
             std::cout << "Contour " << ic << " is not a hole." << std::endl;
           } else {
             std::cout << "Contour " << ic << " is a hole." << std::endl;
           }
         }
       } else {
         std::cout << "ERROR! Clipper library failed" << std::endl;
       }
    
       return 0;
    }
    
     

    Last edit: David 2013-11-19
  • Angus Johnson

    Angus Johnson - 2013-11-19

    Hi David.
    Thanks for the very clear feedback.
    Yes, there is a bug.
    I'll fix it shortly.

     
  • Angus Johnson

    Angus Johnson - 2013-11-20

    OK, I've located and 'fixed' the bug that was in Poly2ContainsPoly1() - see revision 429 in the Repository. It's still not perfect but I'm pondering the need for that :).

     
  • David

    David - 2013-11-21

    That indeed appears to have fixed my problem, and other related ones. Thanks so much!

     
  • Angus Johnson

    Angus Johnson - 2013-11-21

    A pleasure.

     
MongoDB Logo MongoDB