mirror of
https://github.com/thunderbrewhq/typhoon.git
synced 2025-12-12 02:22:30 +00:00
feat(rect): add CRect
This commit is contained in:
parent
ae7654ea64
commit
0623492fe6
5 changed files with 81 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
file(GLOB TEMPEST_SOURCES
|
||||
"*.cpp"
|
||||
"matrix/*.cpp"
|
||||
"rect/*.cpp"
|
||||
"vector/*.cpp"
|
||||
)
|
||||
|
||||
|
|
|
|||
6
tempest/Rect.hpp
Normal file
6
tempest/Rect.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef TEMPEST_RECT_HPP
|
||||
#define TEMPEST_RECT_HPP
|
||||
|
||||
#include "tempest/rect/CRect.hpp"
|
||||
|
||||
#endif
|
||||
25
tempest/rect/CRect.cpp
Normal file
25
tempest/rect/CRect.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "tempest/rect/CRect.hpp"
|
||||
#include "tempest/Vector.hpp"
|
||||
|
||||
CRect CRect::Intersection(const CRect& l, const CRect& r) {
|
||||
CRect i;
|
||||
|
||||
i.maxX = r.maxX <= l.maxX ? r.maxX : l.maxX;
|
||||
i.maxY = r.maxY <= l.maxY ? r.maxY : l.maxY;
|
||||
i.minX = r.minX >= l.minX ? r.minX : l.minX;
|
||||
i.minY = r.minY >= l.minY ? r.minY : l.minY;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
bool CRect::operator==(const CRect& rect) {
|
||||
return this->minX == rect.minX && this->minY == rect.minY && this->maxX == rect.maxX && this->maxY == rect.maxY;
|
||||
}
|
||||
|
||||
bool CRect::IsPointInside(const C2Vector& pt) {
|
||||
return this->minX <= pt.x && this->maxX >= pt.x && this->minY <= pt.y && this->maxY >= pt.y;
|
||||
}
|
||||
|
||||
bool CRect::Sub4826D0() const {
|
||||
return this->maxY < 0.0f || this->minY > 1.0f || this->maxX < 0.0f || this->minX > 1.0f;
|
||||
}
|
||||
29
tempest/rect/CRect.hpp
Normal file
29
tempest/rect/CRect.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef TEMPEST_RECT_C_RECT_HPP
|
||||
#define TEMPEST_RECT_C_RECT_HPP
|
||||
|
||||
class C2Vector;
|
||||
|
||||
class CRect {
|
||||
public:
|
||||
// Static functions
|
||||
static CRect Intersection(const CRect& l, const CRect& r);
|
||||
|
||||
// Member variables
|
||||
float minY = 0.0f; // t
|
||||
float minX = 0.0f; // l
|
||||
float maxY = 0.0f; // b
|
||||
float maxX = 0.0f; // r
|
||||
|
||||
// Member functions
|
||||
CRect() = default;
|
||||
CRect(float minY, float minX, float maxY, float maxX)
|
||||
: minY(minY)
|
||||
, minX(minX)
|
||||
, maxY(maxY)
|
||||
, maxX(maxX) {};
|
||||
bool operator==(const CRect& r);
|
||||
bool IsPointInside(const C2Vector& pt);
|
||||
bool Sub4826D0() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
20
test/Rect.cpp
Normal file
20
test/Rect.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "tempest/Rect.hpp"
|
||||
#include "test/Test.hpp"
|
||||
|
||||
TEST_CASE("CRect", "[rect]") {
|
||||
SECTION("constructs with default constructor") {
|
||||
CRect rect;
|
||||
CHECK(rect.minY == 0.0f);
|
||||
CHECK(rect.minX == 0.0f);
|
||||
CHECK(rect.maxY == 0.0f);
|
||||
CHECK(rect.maxX == 0.0f);
|
||||
}
|
||||
|
||||
SECTION("constructs with minY minX maxY maxX constructor") {
|
||||
auto rect = CRect(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
CHECK(rect.minY == 1.0f);
|
||||
CHECK(rect.minX == 2.0f);
|
||||
CHECK(rect.maxY == 3.0f);
|
||||
CHECK(rect.maxX == 4.0f);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue