internal RtreeR2Page(Storage storage, RtreeR2Page root, RtreeR2Page p) { branch = storage.CreateLink(card); branch.Length = card; b = new RectangleR2[card]; n = 2; setBranch(0, root.cover(), root); setBranch(1, p.cover(), p); for (int i = 2; i < card; i++) { b[i] = new RectangleR2(); } }
internal RtreeR2Page insert(Storage storage, RectangleR2 r, object obj, int level) { Modify(); if (--level != 0) { // not leaf page int i, mini = 0; double minIncr = Double.MaxValue; double minArea = Double.MaxValue; for (i = 0; i < n; i++) { double area = b[i].Area(); double incr = RectangleR2.JoinArea(b[i], r) - area; if (incr < minIncr) { minIncr = incr; minArea = area; mini = i; } else if (incr == minIncr && area < minArea) { minArea = area; mini = i; } } RtreeR2Page p = (RtreeR2Page)branch[mini]; RtreeR2Page q = p.insert(storage, r, obj, level); if (q == null) { // child was not split b[mini].Join(r); return(null); } else { // child was split setBranch(mini, p.cover(), p); return(addBranch(storage, q.cover(), q)); } } else { return(addBranch(storage, new RectangleR2(r), obj)); } }
internal int remove(RectangleR2 r, object obj, int level, ArrayList reinsertList) { if (--level != 0) { for (int i = 0; i < n; i++) { if (r.Intersects(b[i])) { RtreeR2Page pg = (RtreeR2Page)branch[i]; int reinsertLevel = pg.remove(r, obj, level, reinsertList); if (reinsertLevel >= 0) { if (pg.n >= minFill) { setBranch(i, pg.cover(), pg); Modify(); } else { // not enough entries in child reinsertList.Add(pg); reinsertLevel = level - 1; removeBranch(i); } return(reinsertLevel); } } } } else { for (int i = 0; i < n; i++) { if (branch.ContainsElement(i, obj)) { removeBranch(i); return(0); } } } return(-1); }