22#include <kiwano/math/Vec2.hpp>
28template <
typename _Ty>
32 using ValueType = _Ty;
40 RectT(ValueType left, ValueType top, ValueType right, ValueType bottom)
42 , right_bottom(right, bottom)
48 , right_bottom(right_bottom)
53 : left_top(other.left_top)
54 , right_bottom(other.right_bottom)
60 left_top = other.left_top;
61 right_bottom = other.right_bottom;
65 inline bool operator==(
const RectT& rect)
const
67 return (left_top == rect.left_top) && (right_bottom == rect.right_bottom);
70 inline void Set(ValueType left, ValueType top, ValueType right, ValueType bottom)
78 return Vec2T<ValueType>{ (left_top.x + right_bottom.x) / 2, (left_top.y + right_bottom.y) / 2 };
101 inline ValueType GetLeft()
const
106 inline ValueType GetTop()
const
111 inline ValueType GetRight()
const
113 return right_bottom.x;
116 inline ValueType GetBottom()
const
118 return right_bottom.y;
121 inline ValueType GetWidth()
const
123 return right_bottom.x - left_top.x;
126 inline ValueType GetHeight()
const
128 return right_bottom.y - left_top.y;
136 inline bool IsEmpty()
const
138 return left_top.IsOrigin() && right_bottom.IsOrigin();
143 return point.x >= left_top.x && point.x <= right_bottom.x && point.y >= left_top.y && point.y <= right_bottom.y;
146 inline bool Intersects(
const RectT& rect)
const
148 return !(right_bottom.x < rect.left_top.x || rect.right_bottom.x < left_top.x
149 || right_bottom.y < rect.left_top.y || rect.right_bottom.y < left_top.y);
152 static inline RectT Infinite()
154 return RectT{ -math::FLOAT_MAX, -math::FLOAT_MAX, math::FLOAT_MAX, math::FLOAT_MAX };