MegaSteve/Math.ixx

35 lines
864 B
Plaintext
Raw Permalink Normal View History

module;
#include <d2d1.h>
2022-08-05 23:50:08 +08:00
#include <concepts>
export module Math;
export
{
struct Vector2 : D2D1_POINT_2F
{
};
struct Rect : D2D1_RECT_F
{
2022-08-01 17:19:30 +08:00
Vector2 size() const&
{
return { right - left, bottom - top };
}
};
2022-08-05 23:50:08 +08:00
inline bool isIntersection(const Rect& lhs, const Rect& rhs)
{
auto ox1 = (lhs.left + lhs.right) * 0.5f;
auto oy1 = (lhs.top + lhs.bottom) * 0.5f;
auto ox2 = (rhs.left + rhs.right) * 0.5f;
auto oy2 = (rhs.top + rhs.bottom) * 0.5f;
auto rx1 = abs(lhs.right - lhs.left) * 0.5f;
auto ry1 = abs(lhs.top - lhs.bottom) * 0.5f;
auto rx2 = abs(rhs.right - rhs.left) * 0.5f;
auto ry2 = abs(rhs.top - rhs.bottom) * 0.5f;
return ((abs(ox1 - ox2) - (rx1 + rx2)) < -20.f) && ((abs(oy1 - oy2) - (ry1 + ry2)) < -20.f);
}
}