docs: update math API docs
This commit is contained in:
50
docs/api/math/rect/contains.md
Normal file
50
docs/api/math/rect/contains.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Rect::Contains
|
||||
|
||||
判断点是否在矩形内部。
|
||||
|
||||
```cpp
|
||||
bool Contains(float px, float py) const;
|
||||
bool Contains(const Vector2& point) const;
|
||||
```
|
||||
|
||||
矩形使用左上位坐标系,内部定义为:x >= left && x < right && y >= top && y < bottom。即左边界和上边界在内部,右边界和下边界在外部。
|
||||
|
||||
**参数:**
|
||||
- `px` - 点的 x 坐标
|
||||
- `py` - 点的 y 坐标
|
||||
- `point` - 要判断的点(Vector2 类型)
|
||||
|
||||
**返回:** 点在矩形内部返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
Rect rect(10.0f, 20.0f, 100.0f, 50.0f);
|
||||
|
||||
if (rect.Contains(50.0f, 30.0f)) {
|
||||
std::cout << "Point (50, 30) is inside\n";
|
||||
}
|
||||
|
||||
Vector2 point(150.0f, 100.0f);
|
||||
if (!rect.Contains(point)) {
|
||||
std::cout << "Point (150, 100) is outside\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`Rect::Intersects`](intersects.md) - 判断是否相交
|
||||
- [Rect 总览](rect.md)
|
||||
Reference in New Issue
Block a user