public static int decompose_overlapping(RECT A, RECT B, RECT [] ra) { int overlaps = 0; RECT C; RECT i; if (A.overlaps_interior(B)) { if (B.y0 < A.y0) { //0 C = new RECT(B.x0, B.y0, B.w, A.y0 - B.y0); i = C.intersection(B); if (!is_sliver(i)) { ra[overlaps] = i; RECTTOOLS.CHECK_NO_INTERIOR_OVERLAP(C, A); overlaps++; } } if (B.x1 > A.x1) { //1 C = RECT.FromPoints(A.x1, A.y0, B.x1, A.y1); i = C.intersection(B); if (!is_sliver(i)) { RECTTOOLS.CHECK_NO_INTERIOR_OVERLAP(C, A); ra[overlaps] = i; overlaps++; } } if (B.x0 < A.x0) { //2 C = RECT.FromPoints(B.x0, A.y0, A.x0, A.y1); i = C.intersection(B); if (!is_sliver(i)) { RECTTOOLS.CHECK_NO_INTERIOR_OVERLAP(C, A); ra[overlaps] = i; overlaps++; } } if (B.y1 > A.y1) { //3 C = new RECT(B.x0, A.y1, B.w, B.y1 - A.y1); i = C.intersection(B); if (!is_sliver(i)) { ra[overlaps] = i; overlaps++; } } } return(overlaps); }
public static RECT get_bounding_box(RECT [] ra) { RECT bb = ra[0]; for (int i = 0; i < ra.Length; i++) { bb = RECTTOOLS.get_bounding_box(bb, ra[i]); } return(bb); }
public static System.Collections.ArrayList decompose_overlapping_rects(RECT [] ra) { System.Collections.ArrayList good_list = new System.Collections.ArrayList(); System.Collections.ArrayList input_list = new System.Collections.ArrayList(); foreach (RECT r in ra) { input_list.Add(r); } while (input_list.Count > 0) { RECT rB = (RECT)input_list[0]; input_list.RemoveAt(0); bool resolved_overlap_conflict = false; foreach (RECT rA in good_list) { if (rA.overlaps_interior(rB)) { RECT i = rA.intersection(rB); if ((i.w >= 1.0) && (i.h >= 1.0)) { RECT [] overlapping_rects = new RECT[4]; int num_overlaps = RECTTOOLS.decompose_overlapping(rA, rB, overlapping_rects); for (int j = 0; j < num_overlaps; j++) { RECT rX = overlapping_rects[j]; input_list.Add(overlapping_rects[j]); } resolved_overlap_conflict = true; break; } } } if (!resolved_overlap_conflict) { good_list.Add(rB); } } return(good_list); }