public void RemoveOverlappingX(List <BoundingBox> boxes) { const int TO_MOVE = 50; Overlap ovl = new Overlap(); boxes = boxes.OrderBy(p => p.Left).ToList(); for (int i = 0; i < boxes.Count; i++) { BoundingBox outer = boxes[i]; for (int j = i + 1; j < boxes.Count; j++) { BoundingBox inner = boxes[j]; if (ovl.OverlapAreaX(outer, inner) < .75) { if (ovl.OverlapAreaX(outer, inner) < .25) { //move down inner.Left = inner.Left + TO_MOVE; } if (ovl.OverlapArea(outer, inner) > 0) { //move down inner.Left = outer.Left + outer.Width + TO_MOVE; } } } } }
public void RemoveOverlappingOld(List <BoundingBox> boxes) { const int TO_MOVE = 50; Overlap ovl = new Overlap(); DeleteOverlapping(boxes); boxes = boxes.OrderBy(p => p.Top).ToList(); foreach (BoundingBox outer in boxes) { foreach (BoundingBox inner in boxes) { if (outer != inner) { if (ovl.OverlapArea(outer, inner) > 0) { double ovl_x = ovl.OverlapAreaX(outer, inner); double ovl_y = ovl.OverlapAreaY(outer, inner); if (ovl_y > ovl_x) { //Move inner to the right if (inner.Left > outer.Left) { inner.Left = outer.Left + outer.Width + TO_MOVE; } else { outer.Left = inner.Left + inner.Width + TO_MOVE; } } else { if (inner.Top > outer.Top) { //Move inner to the bottom inner.Top = outer.Top + outer.Height + TO_MOVE; } else { //Move outer to the bottom outer.Top = inner.Top + inner.Height + TO_MOVE; } //Move everything down 100 List <BoundingBox> toMove = boxes.Where(p => p.Top > inner.Top + inner.Height).ToList(); foreach (BoundingBox b in toMove) { b.Top = b.Top + TO_MOVE; } } } } } } }