docs: update math API docs
This commit is contained in:
47
docs/api/math/rectint/contains.md
Normal file
47
docs/api/math/rectint/contains.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# 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)
|
||||
36
docs/api/math/rectint/getbottom.md
Normal file
36
docs/api/math/rectint/getbottom.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# RectInt::GetBottom
|
||||
|
||||
```cpp
|
||||
int32_t GetBottom() const;
|
||||
```
|
||||
|
||||
获取矩形下边界 y 坐标。
|
||||
|
||||
**返回:** 矩形下边界 y 坐标(等于 y + height)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t bottom = rect.GetBottom();
|
||||
std::cout << "Bottom: " << bottom << "\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetLeft`](getleft.md) - 获取左边界
|
||||
- [`RectInt::GetRight`](getright.md) - 获取右边界
|
||||
- [`RectInt::GetTop`](gettop.md) - 获取上边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
35
docs/api/math/rectint/getcenter.md
Normal file
35
docs/api/math/rectint/getcenter.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# RectInt::GetCenter
|
||||
|
||||
```cpp
|
||||
Vector2 GetCenter() const;
|
||||
```
|
||||
|
||||
获取矩形中心点坐标。
|
||||
|
||||
**返回:** 表示矩形中心点的 Vector2(转换为浮点)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 center = rect.GetCenter();
|
||||
std::cout << "Center: (" << center.x << ", " << center.y << ")\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetPosition`](getposition.md) - 获取位置
|
||||
- [`RectInt::GetSize`](getsize.md) - 获取尺寸
|
||||
- [RectInt 总览](rectint.md)
|
||||
36
docs/api/math/rectint/getleft.md
Normal file
36
docs/api/math/rectint/getleft.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# RectInt::GetLeft
|
||||
|
||||
```cpp
|
||||
int32_t GetLeft() const;
|
||||
```
|
||||
|
||||
获取矩形左边界 x 坐标。
|
||||
|
||||
**返回:** 矩形左边界 x 坐标(等于 x 成员变量)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t left = rect.GetLeft();
|
||||
std::cout << "Left: " << left << "\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetRight`](getright.md) - 获取右边界
|
||||
- [`RectInt::GetTop`](gettop.md) - 获取上边界
|
||||
- [`RectInt::GetBottom`](getbottom.md) - 获取下边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
35
docs/api/math/rectint/getposition.md
Normal file
35
docs/api/math/rectint/getposition.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# RectInt::GetPosition
|
||||
|
||||
```cpp
|
||||
Vector2 GetPosition() const;
|
||||
```
|
||||
|
||||
获取矩形位置(x, y 坐标)。
|
||||
|
||||
**返回:** 表示矩形位置的 Vector2(转换为浮点)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 pos = rect.GetPosition();
|
||||
std::cout << "Position: (" << pos.x << ", " << pos.y << ")\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetSize`](getsize.md) - 获取尺寸
|
||||
- [`RectInt::GetCenter`](getcenter.md) - 获取中心点
|
||||
- [RectInt 总览](rectint.md)
|
||||
36
docs/api/math/rectint/getright.md
Normal file
36
docs/api/math/rectint/getright.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# RectInt::GetRight
|
||||
|
||||
```cpp
|
||||
int32_t GetRight() const;
|
||||
```
|
||||
|
||||
获取矩形右边界 x 坐标。
|
||||
|
||||
**返回:** 矩形右边界 x 坐标(等于 x + width)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t right = rect.GetRight();
|
||||
std::cout << "Right: " << right << "\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetLeft`](getleft.md) - 获取左边界
|
||||
- [`RectInt::GetTop`](gettop.md) - 获取上边界
|
||||
- [`RectInt::GetBottom`](getbottom.md) - 获取下边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
35
docs/api/math/rectint/getsize.md
Normal file
35
docs/api/math/rectint/getsize.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# RectInt::GetSize
|
||||
|
||||
```cpp
|
||||
Vector2 GetSize() const;
|
||||
```
|
||||
|
||||
获取矩形尺寸(width, height)。
|
||||
|
||||
**返回:** 表示矩形尺寸的 Vector2(转换为浮点)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 size = rect.GetSize();
|
||||
std::cout << "Size: (" << size.x << ", " << size.y << ")\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetPosition`](getposition.md) - 获取位置
|
||||
- [`RectInt::GetCenter`](getcenter.md) - 获取中心点
|
||||
- [RectInt 总览](rectint.md)
|
||||
36
docs/api/math/rectint/gettop.md
Normal file
36
docs/api/math/rectint/gettop.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# RectInt::GetTop
|
||||
|
||||
```cpp
|
||||
int32_t GetTop() const;
|
||||
```
|
||||
|
||||
获取矩形上边界 y 坐标。
|
||||
|
||||
**返回:** 矩形上边界 y 坐标(等于 y 成员变量)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t top = rect.GetTop();
|
||||
std::cout << "Top: " << top << "\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetLeft`](getleft.md) - 获取左边界
|
||||
- [`RectInt::GetRight`](getright.md) - 获取右边界
|
||||
- [`RectInt::GetBottom`](getbottom.md) - 获取下边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
48
docs/api/math/rectint/intersects.md
Normal file
48
docs/api/math/rectint/intersects.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# 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)
|
||||
63
docs/api/math/rectint/rectint.md
Normal file
63
docs/api/math/rectint/rectint.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# RectInt
|
||||
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**类型**: `struct`
|
||||
|
||||
**头文件**: `XCEngine/Math/Rect.h`
|
||||
|
||||
**描述**: 二维整数矩形,用于表示像素级 2D 区域
|
||||
|
||||
## 概述
|
||||
|
||||
RectInt 结构体表示一个二维整数矩形,由整数位置 `(x, y)` 和尺寸 `(width, height)` 组成。与 Rect 不同,它使用 `int32_t` 类型,适合像素级操作和坐标计算。
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`GetLeft`](getleft.md) | 获取矩形左边界 |
|
||||
| [`GetRight`](getright.md) | 获取矩形右边界 |
|
||||
| [`GetTop`](gettop.md) | 获取矩形上边界 |
|
||||
| [`GetBottom`](getbottom.md) | 获取矩形下边界 |
|
||||
| [`GetPosition`](getposition.md) | 获取矩形位置 |
|
||||
| [`GetSize`](getsize.md) | 获取矩形尺寸 |
|
||||
| [`GetCenter`](getcenter.md) | 获取矩形中心点 |
|
||||
| [`Contains`](contains.md) | 判断点是否在矩形内 |
|
||||
| [`Intersects`](intersects.md) | 判断是否与另一矩形相交 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include "XCEngine/Math/Vector2.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
|
||||
std::cout << "Position: (" << rect.x << ", " << rect.y << ")\n";
|
||||
std::cout << "Size: " << rect.width << " x " << rect.height << "\n";
|
||||
std::cout << "Left: " << rect.GetLeft() << ", Right: " << rect.GetRight() << "\n";
|
||||
std::cout << "Top: " << rect.GetTop() << ", Bottom: " << rect.GetBottom() << "\n";
|
||||
|
||||
if (rect.Contains(50, 30)) {
|
||||
std::cout << "Point (50, 30) is inside rect\n";
|
||||
}
|
||||
|
||||
RectInt other(60, 40, 100, 50);
|
||||
if (rect.Intersects(other)) {
|
||||
std::cout << "Rects intersect\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`Rect`](../rect/rect.md) - 浮点矩形
|
||||
- [`Viewport`](../rect/viewport.md) - 视口
|
||||
- [`Vector2`](../vector2/vector2.md) - 二维向量
|
||||
Reference in New Issue
Block a user