void InsertAET(NET net, ref AET aet) { AET lastAET = null; AET nowAET = null; AET tempAET = null; if (net != null) { if (aet == null) { aet = new AET { DeltaX = net.DeltaX, MaxY = net.MaxY, X = net.MinX }; } else { nowAET = aet.Next; lastAET = aet; while (nowAET != null) { if (nowAET.X > net.MinX) { tempAET = new AET() { DeltaX = net.DeltaX, MaxY = net.MaxY, X = net.MinX, }; lastAET.Next = tempAET; tempAET.Next = nowAET; break; } else { lastAET = nowAET; nowAET = nowAET.Next; } } if (tempAET == null) { tempAET = new AET() { DeltaX = net.DeltaX, MaxY = net.MaxY, X = net.MinX, }; lastAET.Next = tempAET; } } } }
void UpdateAET(ref AET aet) { AET nowAET = null; nowAET = aet; while (nowAET != null) { nowAET.X = (int)(nowAET.DeltaX + nowAET.X); nowAET = nowAET.Next; } }
List <Point> GetPointsByAET(AET left, AET right, int Y) { List <Point> points = new List <Point>(); for (int i = left.X; i <= right.X; i++) { Point point = new Point() { X = i, Y = Y }; points.Add(point); } return(points); }
void DeleteAET(ref AET aet, int Y) { if (aet == null) { return; } AET nextAET = null; AET nowAET = null; AET lastAET = null; nowAET = aet; lastAET = aet; nextAET = aet.Next; while (nowAET != null) { if (nowAET.MaxY == Y) { if (nowAET.Equals(aet)) { aet = nextAET; } else { lastAET.Next = nowAET.Next; } } nowAET = nowAET.Next; if (nowAET != null) { nextAET = nowAET.Next; } if (!lastAET.Equals(aet)) { lastAET = lastAET.Next; } } }
public IEnumerable <Point> GetPoints(IEnumerable <Point> points) { List <Point> pointList = new List <Point>(); int maxY = points.Max(en => en.Y);//后续用非自带方法 int minY = points.Min(en => en.Y); NET net = new NET(); var lines = GetLines(points.ToList()); Dictionary <int, NET> dictNET = new Dictionary <int, NET>(); AET aet = null; for (int Y = minY; Y <= maxY; Y++) { dictNET.Add(Y, null); List <Line> lineList = new List <Line>(); for (int i = 0; i < lines.Count; i++) { if (lines[i].StartY == Y || lines[i].EndY == Y) { AddNET(lines[i], dictNET, Y); lineList.Add(lines[i]); } } foreach (var line in lineList) { lines.Remove(line); } } for (int Y = minY; Y <= maxY; Y++) { if (dictNET[Y] != null) { var newNET = dictNET[Y]; while (newNET != null) { InsertAET(newNET, ref aet); newNET = newNET.Next; } } #region 遍历删除点 DeleteAET(ref aet, Y); #endregion if (aet != null) { #region 遍历得到点 AET left = null; AET right = null; left = aet; right = aet.Next; while (left != null && right != null) { var tempPoints = GetPointsByAET(left, right, Y); pointList.AddRange(tempPoints); left = right.Next; if (left != null) { right = left.Next; } } #endregion UpdateAET(ref aet); } } return(pointList); }