Allegro.cc Forums » Programming Questions » Overlapping rectangles

 Kris Asick Member #1,424 July 2001 ```if (rect1.x1 > rect2.x1) finalrect.x1 = rect1.x1; else finalrect.x1 = rect2.x1; if (rect1.x2 < rect2.x2) finalrect.x2 = rect1.x2; else finalrect.x2 = rect2.x2; if (rect1.y1 > rect2.y1) finalrect.y1 = rect1.y1; else finalrect.y1 = rect2.y1; if (rect1.y2 < rect2.y2) finalrect.y2 = rect1.y2; else finalrect.y2 = rect2.y2; ``` That's a guess BTW, that I came up with moments after reading your post... I could be totally wrong about that. --- Kris Asick (Gemini)--- http://www.pixelships.com --- Kris Asick (Gemini)--- http://www.pixelships.com
 HardTranceFan Member #7,317 June 2006 Doh, Same as Kris's. I should learn to read before I write [/edit]Something like this?```// // rect[n]. // n = rectangle number - 0 for first rectangle, 1 for second rectangle or 2 for overlap // Left = left edge // Right = right edge // Top = top edge // Bottom = bottom edge // rect[2].Left = max(rect[0].Left, rect[1].Left) rect[2].Right = min(rect[0].Right, rect[1].Right) rect[2].Top = max(rect[0].Top, rect[1].Top) rect[2].Bottom = min(rect[0].Bottom, rect[1].Bottom) ``` Is there any optimisation to : ```finalrect.y2 = (rect1.y2 < rect2.y2) ? rect1.y2 : rect2.y2; ``` as an alternative to : ```if (rect1.y2 < rect2.y2) finalrect.y2 = rect1.y2; else finalrect.y2 = rect2.y2; ``` [/edit] --"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)