Overlapping rectangles
Rick

There was a simple way to find the overlapping rectangle after you found that 2 rectangles have collided using min max functions but I can't remember it. Anyone know what that is?

Kris Asick
```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

HardTranceFan

Doh, Same as Kris's. I should learn to read before I write [/edit]

Something like this?

```//
// rect[n].<Left|Right|Top|Bottom>
//   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.Left =   max(rect.Left, rect.Left)
rect.Right =  min(rect.Right, rect.Right)
rect.Top =    max(rect.Top, rect.Top)
rect.Bottom = min(rect.Bottom, rect.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]