public bool Insert(Vector2 point2D) { if (boundary.Contains(point2D) == false) { return(false); } if (Point2Ds.Count < capacity) { Point2Ds.Add(point2D); return(true); } else { if (divided == false) { Subdivide(); } if (topRight.Insert(point2D) == true) { return(true); } else if (topLeft.Insert(point2D) == true) { return(true); } else if (bottomRight.Insert(point2D) == true) { return(true); } else if (bottomLeft.Insert(point2D) == true) { return(true); } } return(false); }
void MeshLayer(List <Pixel> layer, int i) { if (!meshed[i]) { var line = new Dictionary <float, List <Pixel> >(); List <float> row = layer.Select(a => a.coords.y).Distinct().ToList(); foreach (float r in row) { line.Add(r, GetMaximumRange(layer.Where(a => a.coords.y == r))); } ListofPoints = new List <Point2D>(); foreach (var l in line) { foreach (Pixel px in l.Value) { ListofPoints.Add(MakePoint(px.coords.x, px.coords.y)); } } Vector2 middle = new Vector2(layer.Min(a => a.coords.x), layer.Min(a => a.coords.y)); float height = layer.Max(a => a.coords.x) - middle.x; float width = layer.Max(a => a.coords.y) - middle.y; Boundary2 boundaryy = new Boundary2(middle, Mathf.Max(height, width), Mathf.Max(height, width)); List <Vector2> res = new List <Vector2>(); SilentQuadTree quadTree = new SilentQuadTree(boundaryy, 4, new Vector2[] { }, res); foreach (KeyValuePair <float, List <Pixel> > l in line) { foreach (Pixel v in l.Value) { quadTree.Insert(v.coords); } } quadTree.Deep(ref BoundarySize); foreach (var item in res) { float lval = line.Keys.First(); foreach (var k in line.Keys) { if (Mathf.Abs(k - item.y) < Mathf.Abs(lval - item.y)) { lval = k; } } List <Pixel> range = line[lval]; if (range.Count > 1) { if (range[1].coords.x > item.x && range[0].coords.x < item.x) { var pktt = gameObject.MakePoint(item.x, item.y, Prefab); ListofPoints.Add(pktt); } } } meshed[i] = true; DelaunayTriangulation(ListofPoints); } }