add integer version of aabb
diff --git a/include/rive/math/aabb.hpp b/include/rive/math/aabb.hpp
index f886466..9f9151e 100644
--- a/include/rive/math/aabb.hpp
+++ b/include/rive/math/aabb.hpp
@@ -6,6 +6,21 @@
#include <cstddef>
namespace rive {
+ struct IAABB {
+ int32_t left, top, right, bottom;
+
+ constexpr int width() const { return right - left; }
+ constexpr int height() const { return bottom - top; }
+ constexpr bool empty() const { return width() <= 0 || height() <= 0; }
+
+ IAABB inset(int dx, int dy) const {
+ return {left + dx, top + dy, right - dx, bottom - dy};
+ }
+ IAABB offset(int dx, int dy) const {
+ return {left + dx, top + dy, right + dx, bottom + dy};
+ }
+ };
+
class AABB {
public:
union {
@@ -20,11 +35,15 @@
AABB(const AABB& o) :
minX(o.minX), minY(o.minY), maxX(o.maxX), maxY(o.maxY)
{}
-
+
AABB(float minX, float minY, float maxX, float maxY) :
minX(minX), minY(minY), maxX(maxX), maxY(maxY)
{}
+ AABB(const IAABB& o) :
+ AABB((float)o.left, (float)o.top, (float)o.right, (float)o.bottom)
+ {}
+
bool operator==(const AABB& o) const {
return minX == o.minX && minY == o.minY &&
maxX == o.maxX && maxY == o.maxY;
@@ -67,6 +86,9 @@
AABB offset(float dx, float dy) const {
return {minX + dx, minY + dy, maxX + dx, maxY + dy};
}
+
+ IAABB round() const;
};
+
} // namespace rive
#endif
diff --git a/src/math/aabb.cpp b/src/math/aabb.cpp
index 0bf16a9..5e77188 100644
--- a/src/math/aabb.cpp
+++ b/src/math/aabb.cpp
@@ -43,3 +43,21 @@
out[2] = std::fmax(p1[0], std::fmax(p2[0], std::fmax(p3[0], p4[0])));
out[3] = std::fmax(p1[1], std::fmax(p2[1], std::fmax(p3[1], p4[1])));
}
+
+static inline float graphics_roundf(float x) {
+ return std::floor(x + 0.5f);
+}
+
+static inline int graphics_round(float x) {
+ return (int)graphics_roundf(x);
+}
+
+IAABB AABB::round() const {
+ return {
+ graphics_round(left()),
+ graphics_round(top()),
+ graphics_round(right()),
+ graphics_round(bottom()),
+ };
+}
+