Menu

Union of adjacent polygons

DaveInCaz
2018-01-09
2018-02-05
  • DaveInCaz

    DaveInCaz - 2018-01-09

    I did a simple example of unioning three adjacent rectangles. I was expecting a single polygon returned, but instead I got two.

    Starting point - 3 independent closed polygons:

    e.g., the orange and green paths are both adjacent to the yellow path. But the resulting union solution set still includes the orange path as an independent entity.

    Result of unioning those 3 polygons shown in black:

    If I perform a second union on the results of the first, then it does indeed produce a single polygon.

    A second observation is that if I OMIT the green path, then indeed the returned solution shows an actual union of the other two:

    I don't really understand this output, if I am doign something wrong or if this is just a corner-case for the Clipper library?

    Sample code is below. This is using C# Clipper labelled version 6.4.2 which came from the SourceForge download.

    Thanks!

    var A0 = new IntPoint(0, 0);
    var A1 = new IntPoint(0, 10);
    var A2 = new IntPoint(0, 20);
    
    var B0 = new IntPoint(10, 0);
    var B1 = new IntPoint(10, 10);
    
    var C0 = new IntPoint(20, 0);
    var C1 = new IntPoint(20, 10);
    
    var D0 = new IntPoint(30, 0);
    var D1 = new IntPoint(30, 10);
    var D2 = new IntPoint(30, 20);
    
    var path1 = new List<IntPoint> { A0, A1, B1, B0 };
    var path2 = new List<IntPoint> { A1, A2, D2, D1 };
    var path3 = new List<IntPoint> { C0, C1, D1, D0 };
    
    Clipper c = new Clipper();
    c.AddPath(path1, PolyType.ptSubject, true);
    c.AddPath(path3, PolyType.ptSubject, true);
    c.AddPath(path2, PolyType.ptSubject, true);
    
    var solutions = new Paths();
    c.Execute(ClipType.ctUnion, solutions);
    
     

    Last edit: DaveInCaz 2018-01-09
  • Angus Johnson

    Angus Johnson - 2018-01-10

    From the FAQ:

    Q: Some polygons in the solution share a common edge. Is this a bug?
    A: No, though this should happen rarely as of version 6.

    From Clipper.Execute:

    • polygons may rarely share a common edge (though this is now very rare as of version 6)

    I'm working on a perfect fix in a major Clipper update though that's progressing very slowly and no time frame for completion. (Slowly because of health reasons and it's very difficult to get this right.)

     

    Last edit: Angus Johnson 2018-01-10
    • Ignorant

      Ignorant - 2018-02-05

      angus,
      are you trying to reorder Active edges at same x pt .I had a version in which i would restart after every vatti scan line.--.I used to reorder the ael edges on x,dx. The polygon output splits disappear.BUT at a cost...the output contours were also regenerated after the vatti lines.
      I noticed that one can have extra scan lines ,without effecting output) between the vatti lines.
      And if onr somehow selects these extra scan lines to pass through the intersection points then martinez would be delightedto a tango with vatti.

       
  • DaveInCaz

    DaveInCaz - 2018-01-11

    Thank you, I did not see that FAQ entry.

    One workaround would be to do n-1 union operations in order to union n objects. But that seems simplistic. Instead, is a better approach to keep unioning the contents of the solution set until it diminishes to a single contour or at least reduces to an unchanging minimum number of (possibly non-overlapping) contours?

     
    • Ignorant

      Ignorant - 2018-01-13

      you are lucky.In the vatti algorithm used the only assurance is that the the filled clipped area is available.There is NO gaurantee that 2 output contours in the solution will NOT share a edge....