/// <summary> /// Constructor /// </summary> /// <param name="plane">Plane</param> /// <param name="normal">Normal</param> protected BSPTree(BSPTree <T> parent, ICollection <T> items, PartitionHandler partitionHandler) { this.parent = parent; bounds = GetBounds(items); partition = DeterminePartition(items, bounds, partitionHandler); if (items.Count == 1) { this.items.AddRange(items); } else { var backItems = new List <T>(); var frontItems = new List <T>(); foreach (var item in items) { Add(item, backItems, frontItems); } if (backItems.Count > 0) { back = new BSPTree <T>(this, backItems, partitionHandler); } if (frontItems.Count > 0) { front = new BSPTree <T>(this, frontItems, partitionHandler); } } }
/// <summary> /// Find leaf closest to point /// </summary> /// <param name="point">Point</param> public BSPTree <T> FindLeaf(Point3D point) { BSPTree <T> last = this; BSPTree <T> tree = this; while (tree != null) { tree = tree.FindNext(point); if (tree != null) { last = tree; } } return(last); }