public void Add(int id, int level) { MeshContour newContour = new MeshContour(this, id, level); Levels = Mathf.Max(Levels, level); members.Add(newContour); }
public void AppendTo(MeshContour parent) { if ((object)parent == null) { return; } Parent = parent.ID; parent.Children.Add(ID); }
public MeshContourTree(List <Vector2[]> contours) { int x, y; bool[,] inclusion = new bool[contours.Count, contours.Count]; // inclusion [x, y] = входит ли x в y int[] inclusionLevel = new int[contours.Count]; for (x = 0; x < contours.Count; x++) { inclusionLevel[x] = 0; for (y = 0; y < contours.Count; y++) { inclusion[x, y] = false; } } x = 0; y = 0; // Матрица смежности foreach (Vector2[] inner in contours) { foreach (Vector2[] outer in contours) { if (inner[0] != outer[0] && inner[1] != outer[1]) { inclusion[x, y] = Planimetry.IsPointInPolygon(ref inner[0], outer); inclusionLevel[x] += inclusion[x, y] ? 1 : 0; } y++; } Add(x, inclusionLevel[x]); x++; y = 0; } for (int l = 1; l < Levels; l++) { List <MeshContour> byLevel = FindByLevel(l); List <MeshContour> parents = FindByLevel(l - 1); foreach (MeshContour contour in byLevel) { MeshContour parent = parents.Find(potentialParent => inclusion[contour.ID, potentialParent.ID]); contour.AppendTo(parent); } } }