Clipper在建立联合时不会创建漏洞

时间:2013-09-09 13:26:04

标签: c# polygons

我有以下代码:

class Program {
    static void Main(string[] args) {

        Polygon a = new Polygon();
        a.Add(new IntPoint(0,0));
        a.Add(new IntPoint(2,0));
        a.Add(new IntPoint(2,1));
        a.Add(new IntPoint(1,1));
        a.Add(new IntPoint(1,2));
        a.Add(new IntPoint(2,2));
        a.Add(new IntPoint(2,3));
        a.Add(new IntPoint(0,3));

        Polygon b = new Polygon();
        b.Add(new IntPoint(2,0));
        b.Add(new IntPoint(3,0));
        b.Add(new IntPoint(3,3));
        b.Add(new IntPoint(2,3));

        PolyTree solution = new PolyTree();

        Clipper c = new Clipper();
        c.AddPolygon(a,PolyType.ptSubject);
        c.AddPolygon(b,PolyType.ptSubject);
        c.Execute(ClipType.ctUnion,solution);


        printPolygonTree(solution);

        Console.ReadLine();
    }

    static void printPolygonTree(PolyNode tree) {
        Console.WriteLine((tree.IsHole?"Hole":"Polygon")+":");
        foreach(IntPoint point in tree.Contour) {
            Console.WriteLine(point.X+"/"+point.Y);
        }
        foreach(PolyNode node in tree.Childs) {
            printPolygonTree(node);
        }
    }
}

它应该统一多边形 a b ,这应该会产生一个包含小方块作为洞的大方块。但我得到一个多边形,它有一个切口,用于将内部和外部多边形连接成一个多边形。

有没有办法按预期统一2个多边形?

图形: enter image description here

1 个答案:

答案 0 :(得分:1)

有一个新版本的Clipper即将发布,可以解决这个问题以及其他一些改进。

您可以从SF中继here下载Clipper ver 6的预览:

另请参阅:SF讨论此here