国外建设网站流程,中国企业网地址,网站域名销售,建筑a证Clipper2库介绍
开源库介绍#xff1a; Clipper2在Github上的地址#xff1a;https://github.com/AngusJohnson/Clipper2 Clipper2库对简单和复杂多边形执行交集#xff08;Intersection#xff09;、并集#xff08;Union#xff09;、差分#xff08;Difference…Clipper2库介绍
开源库介绍 Clipper2在Github上的地址https://github.com/AngusJohnson/Clipper2 Clipper2库对简单和复杂多边形执行交集Intersection、并集Union、差分Difference、异或XOR的布尔运算。它还执行多边形偏移。 Clipper2库是对Clipper库的一次重大更新。Clipper库姑且称之为Clipper1的库虽然它仍然运行良好但Clipper2在几乎所有方面都更好。
支持的环境 Clipper2可以使用C、C#或Delphi Pascal进行编译。通过动态链接到C编译的Clipper2库中的导出函数也可以从其他编程语言访问该库。由于C编译的代码明显更快C#和Delphi开发人员也可能更喜欢在库性能至关重要的应用程序中使用这种方法。
其他介绍Clipper或Clipper2的博客
ClipperLib库使用说明 Clipper2中的术语和基本概念
测试
环境
.NET Framework4.7.2在NuGet中安装Clipper2 1.4.0
数据1未产生浮点数的交点
Paths64 subj new Paths64();
Paths64 clip new Paths64();
subj.Add(Clipper.MakePath(new int[] { 0,0,0,2,2,2,2,0 }));
clip.Add(Clipper.MakePath(new int[] { 0,0, 0,1, 1,1, 1,0, 1,-1, 0,-1 }));
Paths64 r1 Clipper.Intersect(subj, clip, FillRule.NonZero);
Paths64 r2 Clipper.Union(subj, clip, FillRule.NonZero);
Paths64 r3 Clipper.Difference(subj, clip, FillRule.NonZero);
Paths64 r4 Clipper.Xor(subj, clip, FillRule.NonZero);
Trace.WriteLine(r1.ToString());//1,0 1,1 0,1 0,0
Trace.WriteLine(r2.ToString());//1,-1 , 1,0 , 2,0 , 2,2 , 0,2 , 0,0 , 0,-1
Trace.WriteLine(r3.ToString());//0,1 , 1,1 , 1,0 , 2,0 , 2,2 , 0,2
Trace.WriteLine(r4.ToString());
//0,1 , 1,1 , 1,0 , 2,0 , 2,2 , 0,2
//1,-1 , 1,0 , 0,0 , 0,-1效果图如下
数据2产生了浮点数的交点
Paths64 subj new Paths64();
Paths64 clip new Paths64();
subj.Add(Clipper.MakePath(new int[] { 0, 0, 0, 2, 2, 2, 2, 0 }));
clip.Add(Clipper.MakePath(new int[] { -1, 0, 0, 1, 3,0, 0, -1 }));
Paths64 r1 Clipper.Intersect(subj, clip, FillRule.NonZero);
Paths64 r2 Clipper.Union(subj, clip, FillRule.NonZero);
Paths64 r3 Clipper.Difference(subj, clip, FillRule.NonZero);
Paths64 r4 Clipper.Xor(subj, clip, FillRule.NonZero);
Trace.WriteLine(r1.ToString());//2,0 , 0,2 , 0,0
Trace.WriteLine(r2.ToString());//3,0 , 2,0 , 2,2 , 0,2 , -1,0 , 0,-1
Trace.WriteLine(r3.ToString());//2,2 , 0,2 , 2,0
Trace.WriteLine(r4.ToString());
// 2,2 , 0,2 , 2,0
//3,0 , 2,0 , 0,0 , 0,2 , -1,0 , 0,-1Clipper的坐标都是用int类型表示的数据2在运算时产生了小数例如CD和BG的交点的Y值就带有小数Clipper2会进行“四舍五入”等操作并保持几何形状的有效性。
另外异或相当于合并结果减去相交结果图略。