/// <summary> /// 用于合并传进来的多边形数组,返回合并后的多边形数组, /// 如果生成了孤岛,则孤岛的tag标志递增 /// </summary> /// <param name="polys"></param> /// <returns></returns> public static PolyResCode UnionAllPolygon(ref List <Polygon> polys) { int tag = 1; for (int i = 0; i < polys.Count; i++) { polys[i].CW(); } for (int i = 1; i < polys.Count; i++) { Polygon p1 = polys[i]; for (int j = 1; j < polys.Count; j++) { Polygon p2 = polys[j]; if (i != j && !p1.Equals(p2)) { List <Polygon> polyResult = new List <Polygon>(); PolyResCode result = p1.Union(p2, ref polyResult); if (result == PolyResCode.Success && polyResult.Count > 0) { polys.Remove(p1); polys.Remove(p2); for (int k = 0; k < polyResult.Count; k++) { Polygon poly = polyResult[k]; if (/*polyResult.Count > 1 &&*/ !poly.IsCW()) { poly.SetTag(tag++);//如果逆时针说明这个多边形是孤岛 } polys.Add(poly); } i = -1; break; } } } } return(PolyResCode.Success); }