2 #include "oxygine-include.h" 9 template<
typename po
int2>
13 typedef typename point2::type T;
16 RectT(): pos(0, 0), size(0, 0) {}
17 RectT(
const point2& Pos,
const point2& Size): pos(Pos), size(Size) {}
18 RectT(T x, T y, T w, T h): pos(x, y), size(w, h) {}
20 static const RectT invalidated()
23 std::numeric_limits<T>::max() / 2,
24 std::numeric_limits<T>::max() / 2,
25 -std::numeric_limits<T>::max(),
26 -std::numeric_limits<T>::max());
29 static const RectT huge()
32 -std::numeric_limits<T>::max() / 2,
33 -std::numeric_limits<T>::max() / 2,
34 std::numeric_limits<T>::max(),
35 std::numeric_limits<T>::max());
38 bool operator == (
const RectT& r)
const 40 return r.pos == pos && r.size == size;
43 bool operator != (
const RectT& r)
const 50 if (size.x <= 0 || size.y <= 0)
55 bool isIntersecting(
const RectT& r)
const 62 bool pointIn(
const point2& p)
const 66 return (p.x >= pos.x) && (p.x < rb.x) && (p.y >= pos.y) && (p.y < rb.y);
69 void clip(
const RectT& rect)
71 point2 pt = pos + size;
73 if (pos.x < rect.pos.x)
75 if (pos.y < rect.pos.y)
78 point2 rb = rect.pos + rect.size;
85 size.x = pt.x - pos.x;
86 size.y = pt.y - pos.y;
89 void unite(
const RectT& rect)
91 point2 rbA = pos + size;
92 point2 rbB = rect.pos + rect.size;
94 pos.x = std::min(rect.pos.x, pos.x);
95 pos.y = std::min(rect.pos.y, pos.y);
97 size.x = std::max(rbA.x, rbB.x) - pos.x;
98 size.y = std::max(rbA.y, rbB.y) - pos.y;
101 void unite(
const point2& p)
103 RectT r(p, point2(0, 0));
107 point2 getCenter()
const {
return pos + size / 2;}
108 point2 getSize()
const {
return size;}
109 point2 getLeftTop()
const {
return pos;}
110 point2 getRightBottom()
const {
return pos + size;}
111 point2 getRightTop()
const {
return point2(getRight(), getTop());}
112 point2 getLeftBottom()
const {
return point2(getLeft(), getBottom());}
114 T getX()
const {
return pos.x;}
115 T getY()
const {
return pos.y;}
116 T getLeft()
const {
return pos.x;}
117 T getTop()
const {
return pos.y;}
118 T getWidth()
const {
return size.x;}
119 T getHeight()
const {
return size.y;}
121 T getRight()
const {
return pos.x + size.x;}
122 T getBottom()
const {
return pos.y + size.y;}
124 void set(T x, T y, T w, T h) {pos.x = x; pos.y = y; size.x = w; size.y = h;}
125 void setPosition(
const point2& pos_) {pos = pos_;}
126 void setPosition(T x, T y) {pos.x = x; pos.y = y;}
127 void setSize(
const point2& size_) {size = size_;}
128 void setSize(T x, T y) {size.x = x; size.y = y;}
129 void setX(T v) {pos.x = v;}
130 void setY(T v) {pos.y = v;}
133 void setWidth(T v) {size.x = v;}
134 void setHeight(T v) {size.y = v;}
136 void moveLeft(T v) {T p = pos.x; pos.x = v; size.x += p - v;}
137 void moveTop(T v) {T p = pos.y; pos.y = v; size.y += p - v;}
138 void moveRight(T v) {size.x = v - pos.x;}
139 void moveBottom(T v) {size.y = v - pos.y;}
141 void expand(
const point2& v1,
const point2& v2) {pos -= v1; size += v1 + v2;}
166 RectT operator * (
const R& v)
const 177 RectT operator / (
const R& v)
const 192 typedef typename R::type rect2type;
193 return rect(pos.template cast<rect2type>(), size.template cast<rect2type>());
–oxgl-end–!
Definition: Actor.h:14