63 lines
1.8 KiB
Markdown
63 lines
1.8 KiB
Markdown
|
|
# 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) - 二维向量
|