private void DivideBranch() { char axis = ChooseSplitAxis(); Leaf[] sortedLeaf = GetChilds().Select(node => (Leaf)node).ToArray(); if (axis == 'x') { Array.Sort(sortedLeaf, new LeafComparerX()); } else if (axis == 'y') { Array.Sort(sortedLeaf, new LeafComparerY()); } else { Array.Sort(sortedLeaf, new LeafComparerZ()); } int splitIndex = ChooseSplitIndex(sortedLeaf); Branch firstChild = new Branch(); Branch secondChild = new Branch(); for (int i = 0; i < sortedLeaf.Length; i++) { if (i < splitIndex) { firstChild.AddChild(sortedLeaf[i]); } else { secondChild.AddChild(sortedLeaf[i]); } } _childs = new List <Node> { firstChild, secondChild }; }
public void AddTriangle(Triangle triangle) { Branch destinationBranch = ChooseSubtree(triangle); destinationBranch.AddChild(triangle); }