6e5114ec2a406003d15ab3d803029c09f9367ccb
[platform/core/uifw/rive-tizen.git] / submodule / include / math / aabb.hpp
1 #ifndef _RIVE_AABB_HPP_
2 #define _RIVE_AABB_HPP_
3
4 #include "mat2d.hpp"
5 #include "vec2d.hpp"
6 #include <cstddef>
7
8 namespace rive
9 {
10         class AABB
11         {
12         public:
13                 union
14                 {
15                         float buffer[4];
16                         struct
17                         {
18                                 Vec2D min, max;
19                         };
20                         struct
21                         {
22                                 float minX, minY, maxX, maxY;
23                         };
24                 };
25
26         public:
27                 AABB();
28                 AABB(const AABB& copy);
29                 AABB(float minX, float minY, float maxX, float maxY);
30
31                 inline const float* values() const { return buffer; }
32
33                 float& operator[](std::size_t idx) { return buffer[idx]; }
34                 const float& operator[](std::size_t idx) const { return buffer[idx]; }
35
36                 static void center(Vec2D& out, const AABB& a);
37                 static void size(Vec2D& out, const AABB& a);
38                 static void extents(Vec2D& out, const AABB& a);
39                 static void combine(AABB& out, const AABB& a, const AABB& b);
40                 static bool contains(const AABB& a, const AABB& b);
41                 static bool isValid(const AABB& a);
42                 static bool testOverlap(const AABB& a, const AABB& b);
43                 static bool areIdentical(const AABB& a, const AABB& b);
44                 static void transform(AABB& out, const AABB& a, const Mat2D& matrix);
45
46                 float width() const;
47                 float height() const;
48                 float perimeter() const;
49         };
50 } // namespace rive
51 #endif