Files
XCEngine/docs/api/math/rectint/contains.md

47 lines
973 B
Markdown
Raw Normal View History

2026-03-20 02:35:15 +08:00
# RectInt::Contains
```cpp
bool Contains(int32_t px, int32_t py) const;
```
判断整数坐标点是否在矩形内部。
矩形使用左上位坐标系内部定义为x >= left && x < right && y >= top && y < bottom。即左边界和上边界在内部右边界和下边界在外部。
**参数:**
- `px` - 点的 x 坐标
- `py` - 点的 y 坐标
**返回:** 点在矩形内部返回 true否则返回 false
**线程安全:** ✅
**复杂度:** O(1)
**示例:**
```cpp
#include "XCEngine/Math/Rect.h"
#include <iostream>
using namespace XCEngine::Math;
int main() {
RectInt rect(0, 0, 1920, 1080);
if (rect.Contains(960, 540)) {
std::cout << "Point (960, 540) is inside\n";
}
if (!rect.Contains(2000, 1000)) {
std::cout << "Point (2000, 1000) is outside\n";
}
return 0;
}
```
## 相关文档
- [`RectInt::Intersects`](intersects.md) - 判断是否相交
- [RectInt 总览](rectint.md)