Files
XCEngine/docs/api/math/rectint/intersects.md
2026-03-20 02:35:15 +08:00

964 B
Raw Blame History

RectInt::Intersects

bool Intersects(const RectInt& other) const;

判断此矩形是否与另一矩形相交。

使用 AABB轴对齐包围盒碰撞检测算法。如果两个矩形在 x 轴和 y 轴上都有重叠,则返回 true。

参数:

  • other - 另一个矩形

返回: 两矩形相交返回 true否则返回 false

线程安全:

复杂度: O(1)

示例:

#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;
}

相关文档