public void TestRecreationOfChildNodeAfterRemovalByReference() { Node node = new OctreeNode(this.sceneManager); Node childNode = node.CreateChild(Name); node.RemoveChild(childNode); node.CreateChild(Name); }
public void TestRecreationOfChildNodeAfterRemovalByName() { Node node = new OctreeNode(this.fakeSceneManager); node.CreateChild(Name); node.RemoveChild(Name); node.CreateChild(Name); }
// Returns whether the node is changed. private bool AddInternal(IntVector3 coords, T obj, OctreeNode <T> node, int level, IntVector3 corner) { if (node.isFilled) { return(false); } else if (level == 0) { node.obj = obj; node.objCount = 1; return(true); } int childSize = 1 << (level - 1); IntVector3 childIndex = (coords - corner) / childSize; var childNode = node.GetChild(childIndex); if (childNode == null) { childNode = node.CreateChild(childIndex); } long oldChildObjCount = childNode.objCount; bool changed = AddInternal(coords, obj, childNode, level - 1, corner + childIndex * childSize); if (changed) { node.objCount += childNode.objCount - oldChildObjCount; if (childNode.isFilled) { node.MergeIfPossible(obj); } } return(changed); }
public void TestReaddingOfChildNodeAfterRemovalByName() { Node node = new OctreeNode(this.sceneManager); Node childNode = node.CreateChild(Name); node.RemoveChild(Name); node.AddChild(childNode); }
// Returns whether the node is changed. private bool SetInternal(IntBox area, T obj, OctreeNode <T> node, int level, IntVector3 corner) { IntBox nodeArea = new IntBox(corner, corner + ((1 << level) - 1) * IntVector3.one); if (node.obj.Equals(obj)) { return(false); } else if (area.Contains(nodeArea)) { node.obj = obj; node.objCount = 1 << level; node.RemoveChildren(); return(true); } else if (node.isFilled) { node.Split(); } int childSize = 1 << (level - 1); IntVector3 childIndexMin = IntVector3.Max((area.min - corner) / childSize, IntVector3.zero); IntVector3 childIndexMax = IntVector3.Min((area.max - corner) / childSize, IntVector3.one); bool changed = false; for (int x = childIndexMin.x; x <= childIndexMax.x; x++) { for (int y = childIndexMin.y; y <= childIndexMax.y; y++) { for (int z = childIndexMin.z; z <= childIndexMax.z; z++) { IntVector3 childIndex = new IntVector3(x, y, z); var childNode = node.GetChild(childIndex); if (childNode == null) { childNode = node.CreateChild(childIndex); } long oldChildObjCount = childNode.objCount; bool childChanged = SetInternal(area, obj, childNode, level - 1, corner + childIndex * childSize); if (childChanged) { changed = true; node.objCount += childNode.objCount - oldChildObjCount; if (childNode.isFilled) { node.MergeIfPossible(obj); } } } } } return(changed); }