Files
XCEngine/docs/api/math/rectint/intersects.md
2026-03-20 02:35:15 +08:00

48 lines
964 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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)