SOLVED: Where is CGRectIntersection?

I see CCRect::CCRectIntersectsRect but this only returns a BOOL if the 2 Rects intersect. I need a Rect returned of the intersection of Rect1 and Rect2. Is there a cocos2d-x implementation of this or will I have to make one? If so, HOW would I make it? :slight_smile:

Thanks
ML

Iโ€™m not sure if this code is already in cocos2d-x and I just missed it but I figured this out by looking the the CGRectIntersection code for iOS.

This is the code for CGRectIntersection to get the intersecting rect of the of two rects:

CCRect intersection;
intersection = CCRectMake(std::max(CCRect::CCRectGetMinX(r1),CCRect::CCRectGetMinX(r2)), std::max(CCRect::CCRectGetMinY(r1),CCRect::CCRectGetMinY(r2)),0,0);
intersection.size.width = std::min(CCRect::CCRectGetMaxX(r1), CCRect::CCRectGetMaxX(r2)) - CCRect::CCRectGetMinX(intersection);
intersection.size.height = std::min(CCRect::CCRectGetMaxY(r1), CCRect::CCRectGetMaxY(r2)) - CCRect::CCRectGetMinY(intersection);

Thanks
ML

hello, ML, in cocos2d-x, CCRectIntersectsRect returns bool, if you need, you could add a function to get rect intersected.

i donโ€™t find CGRectIntersection in cocos2d-iphone, which file does it lie in?

Thank 4 sharing.