// TODO: Check this function /// <summary> /// Recursively remove all polygons in `polygons` that are inside this BSP tree. /// </summary> public List <Polygon> ClipPolygons(Polygon[] polygons) { if (this.plane == null) { return(polygons.Clone <Polygon>().ToList()); } // TODO: Removed slice here? List <Polygon> front = new List <Polygon>(); List <Polygon> back = new List <Polygon>(); for (int i = 0; i < polygons.Length; i++) { this.plane.SplitPolygon(polygons[i], ref front, ref back, ref front, ref back); } if (this.front != null) { front = this.front.ClipPolygons(front.ToArray()); } if (this.back != null) { back = this.back.ClipPolygons(back.ToArray()); } else { back = new List <Polygon>(); } return(front.Concat(back).ToList()); }