1.8 KiB
1.8 KiB
RectInt
命名空间: XCEngine::Math
类型: struct
头文件: XCEngine/Math/Rect.h
描述: 二维整数矩形,用于表示像素级 2D 区域
概述
RectInt 结构体表示一个二维整数矩形,由整数位置 (x, y) 和尺寸 (width, height) 组成。与 Rect 不同,它使用 int32_t 类型,适合像素级操作和坐标计算。
公共方法
| 方法 | 描述 |
|---|---|
GetLeft |
获取矩形左边界 |
GetRight |
获取矩形右边界 |
GetTop |
获取矩形上边界 |
GetBottom |
获取矩形下边界 |
GetPosition |
获取矩形位置 |
GetSize |
获取矩形尺寸 |
GetCenter |
获取矩形中心点 |
Contains |
判断点是否在矩形内 |
Intersects |
判断是否与另一矩形相交 |
使用示例
#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;
}