关于使用Clipper库通过矩形剪裁与矩形边部分重叠的水平直线段没有解的问题
我想使用矩形剪裁任意图形,但遇到一个问题:
当被裁剪的图形是一条与矩形下边界部分重叠的直线段时,没有返回期望的与矩形下边重叠部分的线段。
C#代码如下:
private void btnTest_Click(object sender, EventArgs e)
{
Paths subjs = new Paths();
Path aLine = new Path();
aLine.Add(new IntPoint(0, 0));
aLine.Add(new IntPoint(0, 90));
subjs.Add(aLine);
Paths clips = new Paths();
Path aRect = new Path();
aRect.Add(new IntPoint(0, 0));
aRect.Add(new IntPoint(0, 45));
aRect.Add(new IntPoint(45, 45));
aRect.Add(new IntPoint(45, 0));
clips.Add(aRect);
PolyTree solution = new PolyTree();
Clipper c = new Clipper(0);
c.AddPaths(subjs, PolyType.ptSubject,false);
c.AddPaths(clips, PolyType.ptClip, true);
c.Execute(ClipType.ctIntersection, solution);
Paths result = Clipper.PolyTreeToPaths(solution);
MessageBox.Show("Done");
}
期望result中的结果是:(0,0)->(0,45),但实际结果是result为空。
但是我只要将线段由(0,0)->(0,90)换成(0,0)->(0,44)或(1,0)->(1,90)都可以得到想要的结果:(0,0)->(0,44)及(1,0)->(1,45)。
期盼大家的解答,万分感谢。