private static ArrayList<RectangleF> OptimizeBoundingArea(IEnumerable<RectangleF> boundingArea) { RTree rTree = new RTree(); int rectCount = 0; foreach (RectangleF rect in boundingArea) { rTree.Insert(rect); rectCount++; } ArrayList<RectangleF> result = new ArrayList<RectangleF>(rectCount); while (rTree.mRoot.Entries.Count > 0) { Entry entry = rTree.GetAnyLeafEntry(); RectangleF bb = entry.BoundingBox; float area = 0; while (bb.Width * bb.Height - area > 0.1f) // *** increase this threshold? { area = bb.Width * bb.Height; ArrayList<Entry> queryResult = rTree.Fetch(bb); rTree.Delete(queryResult); foreach (Entry resultEntry in queryResult) { bb = RectangleF.Union(bb, resultEntry.BoundingBox); } } result.Add(bb); } return result; }
public void Optimize() { mRects = RTree.FullyOptimizeBoundingArea(this); }