- template <class B> TRect<B> Convert() {return TRect<B>(B(x), B(y), B(w), B(h));}
+ template <class B> TRect<B> Convert() const {return TRect<B>(B(x), B(y), B(w), B(h));}
+
+ template <class B> TRect<T> & operator=(const TRect<B> & equ)
+ {
+ x = T(equ.x);
+ y = T(equ.y);
+ w = T(equ.w);
+ h = T(equ.h);
+ return *this;
+ }
+
+ // Clips "other" to "this"
+ inline TRect Clip(const TRect& other) const
+ {
+ TRect clipped = other;
+ if (clipped.x < x)
+ {
+ clipped.w += clipped.x - x;
+ clipped.x = x;
+ }
+ if (clipped.y < y)
+ {
+ clipped.h += clipped.y - y;
+ clipped.y = 0;
+ }
+ if (clipped.x + clipped.w > x + w)
+ {
+ clipped.w += ((x + w) - (clipped.x + clipped.w));
+ }
+ if (clipped.y + clipped.h > y + h)
+ {
+ clipped.h += ((y + h) - (clipped.y + clipped.h));
+ }
+ return clipped;
+ }