mirror of
https://github.com/AxioDL/zeus.git
synced 2025-07-01 19:03:32 +00:00
Given this aims to be a general purpose math library for use in various other libraries applications for axiodl, we can annotate functions that return by value or reference with [[nodiscard]] where it's very obvious that not making use of the return value is a bug. This allows the compiler to diagnose and emit warnings for these API misuses at compile-time, preventing silent bugs from occurring. Any cases where not using the return value is desirable may still be casted to void in order to silence warnings.
30 lines
844 B
C++
30 lines
844 B
C++
#pragma once
|
|
|
|
#include "zeus/CVector2f.hpp"
|
|
|
|
namespace zeus {
|
|
class CRectangle {
|
|
public:
|
|
constexpr CRectangle() = default;
|
|
|
|
constexpr CRectangle(float x, float y, float w, float h) : position(x, y), size(w, h) {}
|
|
|
|
[[nodiscard]] bool contains(const CVector2f& point) const {
|
|
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 {
|
|
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;
|
|
};
|
|
} // namespace zeus
|