# rectA & rectB not working

I am trying to get the intersection of 2 rectangles. What happens if the 2 rectangles do not intersect at all ? Will it give me an error ? Because the output below is what I am getting. The limits are (0,0,1242,375). I don't know the rectangles I am passing in. I just want to keep those that intersect and to retain the intersection.

```
[1170 x 232 from (72, 0)]
[1242 x 375 from (0, 0)]
[1242 x 375 from (0, 0)]
[967 x 211 from (275, 0)]
[1242 x 375 from (0, 0)]
[1242 x 375 from (0, 0)]
[1242 x 375 from (0, 0)]
[2147449647 x 375 from (2147483647, 0)]
[1242 x 375 from (0, 0)]
```

I am using this temporary fix after the intersection operator to remove all erroneous rectangles

```
if (rect.tl().x < 0 || rect.tl().y < 0 || rect.br().x >= image.cols || rect.br().y >= image.rows
|| rect.area() >= image.cols * image.rows || rect.area() == 0)
```

2147483647 == 0x7fffffff == INT_MAX.

looks like you have a bug elsewhere ...

thanks ! but wouldn't int_max be reduced to 1242 due to the intersection ? should I introduce another check for INT_MAX ? I am projecting 3D bounding boxes onto a 2D image so I guess if the box lies outside of the image then something weird might happen. I had hoped that the intersection would be enough

~~"should I introduce another check for INT_MAX" -- no, no, rather be paranoid about the~~restof your program(linked wrong libs again ? buffer overflow somewhere ? uninitialized meory ?)I think the error just lies at the projection function, if a corner of the 3D bounding box is "on the image plane" then its projection will be at infinity

oooh, that again sounds pretty likely ! (in that case, forget all remarks above.)

is there a solution ? Why doesn't it work for INT_MAX ? isn't that still a number ? Im currently using the area to filter out such rectangles rect.area() < image.rows*image.cols but im afraid if there are other rectangles that just lie out of bounds but still remain below the maximum area since it looks like the intersection operator doesn't work as I had hoped it would

code source for rect intersection is here. INT_MAX+width is not possible

you can't use area() to filter those out, since INT_MAX * something is already over the top. (or say INT_MAX + anything)

if a corner of the 3D bounding box is "on the image plane"I understand a field of view problem using a stenope model...