建立联合时,Clipper不会产生孔 [英] Clipper does not create hole when making a union

查看:138
本文介绍了建立联合时,Clipper不会产生孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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 ,这将导致一个大正方形,其中包含一个小正方形作为孔.但是我得到了一个多边形,该多边形具有将内部和外部多边形连接成一个多边形的切口.

It should unify the polygons a and b, which should result in a big square that contains a small square as a hole. But I get one polygon instead, that has a cut to connect the inner and outer polygon into one polygon.

是否可以按预期的方式统一两个多边形?

Is there a way to unify the 2 polygons as expected?

图形:

推荐答案

有一个新版本的Clipper即将发布,该版本将解决此问题以及许多其他改进.

There's a new version of Clipper that's about to be released that addresses this issue together with a number of other improvements.

您可以从SF干线 此处下载Clipper ver 6的预览 :

You can download a preview of Clipper ver 6 from the SF trunk here:

另请参见:关于此SF的讨论此处

See also: the SF discussion about this here

这篇关于建立联合时,Clipper不会产生孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆