//不能出现A多边形的连接两条边的顶点在B多边形的一条边上的情况 public static List <Polygon> Union(Polygon clip, Polygon subject) { var ret = new List <Polygon>(); pClip = clip; pSubject = subject; //包围盒不相交 if (pSubject.boxRectangle.IsIntersect(pClip.boxRectangle) == false) { return(null); } //所有顶点和交点 lnClip = PolygonNodeUtil.CreateNodes(clip, false, false); //副多边形 lnSubject = PolygonNodeUtil.CreateNodes(subject, false, true); //主多边形 //插入交点 var insCnt = IntersectPoint_Union(); //生成多边形 if (insCnt > 0) { ret = LinkToPolygon_Union(); return(ret); } return(null); }
public static List <Polygon> Cut(Polygon clip, Polygon subject) { var ret = new List <Polygon>(); pClip = clip; pSubject = subject; //包围盒不相交 if (pSubject.boxRectangle.IsIntersect(pClip.boxRectangle) == false) { return(null); } //所有顶点和交点 lnClip = PolygonNodeUtil.CreateNodes(pClip, false, false); //副多边形 lnSubject = PolygonNodeUtil.CreateNodes(pSubject, false, true); //主多边形 //插入交点 var insCnt = IntersectPoint_Cut(); //生成多边形 if (insCnt > 0) { ret = LinkToPolygon_Cut(); return(ret); } //0个交点 //要判断是否主多边形包含副多边形,如果包含,则返回副多边形 var AContainB = true; foreach (var line in pClip.lineList) { if (!pSubject.Contains(line)) { AContainB = false; } } if (AContainB) { ret.Add(pClip); return(ret); } //要判断是否副多边形包含主多边形,如果包含,则返回主多边形 var BContainA = true; for (var i = 0; i < pSubject.lineList.Count; i++) { var line = pSubject.lineList[i]; if (!pClip.Contains(line)) { BContainA = false; } } if (BContainA) { ret.Add(pSubject); return(ret); } return(null); }