1.0 KiB
1.0 KiB
Rect::Contains
判断点是否在矩形内部。
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)
示例:
#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- 判断是否相交- Rect 总览