mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-25 16:18:57 +08:00
added RectI::overlap_rect
This commit is contained in:
parent
14a53c0f3a
commit
aa6efb23b1
|
@ -31,6 +31,8 @@ namespace Blah
|
|||
Point bottom_right() const;
|
||||
|
||||
bool overlaps(const RectI& other) const;
|
||||
RectI overlap_rect(const Rect& against) const;
|
||||
|
||||
bool contains(const Point& pt) const;
|
||||
bool contains(const Vec2& pt) const;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <blah/math/rect.h>
|
||||
#include <blah/math/point.h>
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/math/calc.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
|
@ -89,6 +90,25 @@ bool RectI::overlaps(const RectI& other) const
|
|||
&& other.y < y + h;
|
||||
}
|
||||
|
||||
RectI RectI::overlap_rect(const Rect& against) const
|
||||
{
|
||||
RectI result(0, 0, 0, 0);
|
||||
|
||||
if (x + w >= against.x && x < against.x + against.w)
|
||||
{
|
||||
result.x = Calc::max(x, against.x);
|
||||
result.w = Calc::min(x + w, against.x + against.w) - result.x;
|
||||
}
|
||||
|
||||
if (y + h >= against.y && y < against.y + against.h)
|
||||
{
|
||||
result.y = Calc::max(y, against.y);
|
||||
result.h = Calc::min(y + h, against.y + against.h) - result.y;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RectI::contains(const Point& point) const
|
||||
{
|
||||
return point.x >= x && point.x < x + w && point.y >= y && point.y < y + h;
|
||||
|
|
Loading…
Reference in New Issue
Block a user