internal void SetValue(short type, float x, float y, float newValue, float?oldValue, short depthToGo) { bool divide = false; float value; if (TryGetValue(type, out value)) { if (value != newValue) { if (depthToGo == 1) { GetDataTuple(type).Item2 = newValue; } else { oldValue = RemoveData(type); divide = true; } } } else { if (depthToGo == 1) { data.Add(new CustomTuple <short, float>(type, newValue)); } else { divide = true; } } if (divide) { if (children == null) { children = new Node[4]; for (int i = 0; i < 4; ++i) { DataQuadTree.Create(this, i); } } float?[] vals = new float?[] { oldValue, oldValue, oldValue, oldValue }; float xMin, yMin; int quadrant = GetQuadrant(x, y, out xMin, out yMin); vals[quadrant] = newValue; for (int i = 0; i < 4; ++i) { if (vals[i] != null) { children[i].SetValue(type, x - xMin, y - yMin, (float)vals[i], oldValue, (short)(i == quadrant ? depthToGo - 1 : 1)); } } } }
internal void Dispose() { DataQuadTree.AddToAvailableNodes(this); }