48 lines
964 B
Markdown
48 lines
964 B
Markdown
# RectInt::Intersects
|
||
|
||
```cpp
|
||
bool Intersects(const RectInt& other) const;
|
||
```
|
||
|
||
判断此矩形是否与另一矩形相交。
|
||
|
||
使用 AABB(轴对齐包围盒)碰撞检测算法。如果两个矩形在 x 轴和 y 轴上都有重叠,则返回 true。
|
||
|
||
**参数:**
|
||
- `other` - 另一个矩形
|
||
|
||
**返回:** 两矩形相交返回 true,否则返回 false
|
||
|
||
**线程安全:** ✅
|
||
|
||
**复杂度:** O(1)
|
||
|
||
**示例:**
|
||
|
||
```cpp
|
||
#include "XCEngine/Math/Rect.h"
|
||
#include <iostream>
|
||
|
||
using namespace XCEngine::Math;
|
||
|
||
int main() {
|
||
RectInt rectA(0, 0, 100, 100);
|
||
RectInt rectB(50, 50, 100, 100);
|
||
|
||
if (rectA.Intersects(rectB)) {
|
||
std::cout << "Rects intersect\n";
|
||
}
|
||
|
||
RectInt rectC(200, 200, 50, 50);
|
||
if (!rectA.Intersects(rectC)) {
|
||
std::cout << "Rects do not intersect\n";
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [`RectInt::Contains`](contains.md) - 判断点是否在矩形内
|
||
- [RectInt 总览](rectint.md) |