zeus/include/zeus/CRectangle.hpp

30 lines
844 B
C++
Raw Normal View History

2018-10-06 20:39:40 -07:00
#pragma once
2018-12-07 17:16:50 -08:00
2016-03-04 15:03:26 -08:00
#include "zeus/CVector2f.hpp"
2018-12-07 17:16:50 -08:00
namespace zeus {
class CRectangle {
public:
2019-02-23 23:15:32 -08:00
constexpr CRectangle() = default;
2018-12-07 17:16:50 -08:00
2019-02-23 23:15:32 -08:00
constexpr CRectangle(float x, float y, float w, float h) : position(x, y), size(w, h) {}
2018-12-07 17:16:50 -08:00
[[nodiscard]] bool contains(const CVector2f& point) const {
2018-12-07 17:16:50 -08:00
if (point.x() < position.x() || point.x() > position.x() + size.x())
return false;
if (point.y() < position.y() || point.y() > position.y() + size.y())
return false;
return true;
}
[[nodiscard]] bool intersects(const CRectangle& rect) const {
2018-12-07 17:16:50 -08:00
return !(position.x() > rect.position.x() + rect.size.x() || rect.position.x() > position.x() + size.x() ||
position.y() > rect.position.y() + rect.size.y() || rect.position.y() > position.y() + size.y());
}
CVector2f position;
CVector2f size;
};
2018-12-07 21:23:50 -08:00
} // namespace zeus