12#ifndef TT_INCLUDE__RECT_H
13#define TT_INCLUDE__RECT_H
21 RectClass(
const RectClass & r ) { Left = r.Left; Top = r.Top; Right = r.Right; Bottom = r.Bottom; }
22 RectClass(
const Vector2 & top_left,
const Vector2 & bottom_right ) { Left = top_left.X; Top = top_left.Y; Right = bottom_right.X; Bottom = bottom_right.Y; }
23 RectClass& operator = (
const RectClass & r) { Left = r.Left; Top = r.Top; Right = r.Right; Bottom = r.Bottom;
return *
this; }
24 void Set(
float left,
float top,
float right,
float bottom) { Left = left; Top = top; Right = right; Bottom = bottom; }
25 void Set(
const Vector2 & top_left,
const Vector2 & bottom_right ) { Left = top_left.X; Top = top_left.Y; Right = bottom_right.X; Bottom = bottom_right.Y; }
26 void Set(
const RectClass & r) { Left = r.Left; Top = r.Top; Right = r.Right; Bottom = r.Bottom; }
27 Vector2 Upper_Right(
void )
const {
return Vector2( Right, Top ); }
28 Vector2 Lower_Left(
void )
const {
return Vector2( Left, Bottom ); }
29 float Width(
void)
const {
return Right - Left; }
30 float Height(
void)
const {
return Bottom - Top; }
31 Vector2 Center(
void )
const {
return Vector2( (Left + Right)/2, (Top + Bottom)/2 ); }
32 Vector2 Extent(
void )
const {
return Vector2( (Right - Left)/2, (Bottom - Top)/2 ); }
33 RectClass & operator *= (
float k) {
return Scale( k ); }
34 RectClass & operator /= (
float k) {
return Scale( 1/k ); }
35 RectClass & Scale_Relative_Center(
float k ) { Vector2 center = Center(); *
this-=center; Left*=k; Top*=k; Right*=k; Bottom*=k; *
this+=center;
return *
this; }
36 RectClass & Scale(
float k ) { Left*=k; Top*=k; Right*=k; Bottom*=k;
return *
this; }
37 RectClass & Scale(
const Vector2 &k ) { Left*=k.X; Top*=k.Y; Right*=k.X; Bottom*=k.Y;
return *
this; }
38 RectClass & Inverse_Scale(
const Vector2 &k ) { Left/=k.X; Top/=k.Y; Right/=k.X; Bottom/=k.Y;
return *
this; }
39 RectClass & operator += (
const Vector2 & o ) { Left+=o.X; Top+=o.Y; Right+=o.X; Bottom+=o.Y;
return *
this; }
40 RectClass & operator -= (
const Vector2 & o ) { Left-=o.X; Top-=o.Y; Right-=o.X; Bottom-=o.Y;
return *
this; }
41 void Inflate(
const Vector2 & o ) { Left-=o.X; Top-=o.Y; Right+=o.X; Bottom+=o.Y; }
42 RectClass & operator += (
const RectClass & r ) { Left=min(Left,r.Left); Top=min(Top,r.Top); Right=max(Right,r.Right); Bottom=max(Bottom,r.Bottom);
return *
this; }
43 RectClass(
float NewLeft,
float NewTop,
float NewRight,
float NewBottom)
53 Vector2 Upper_Left()
const
55 return Vector2(Left,Top);
57 Vector2 Lower_Right()
const
59 return Vector2(Right,Bottom);
61 bool operator == (
const RectClass &rval )
const {
return (rval.Left == Left) && (rval.Right == Right) && (rval.Top == Top) && (rval.Bottom == Bottom); }
62 bool operator != (
const RectClass &rval )
const {
return (rval.Left != Left) || (rval.Right != Right) || (rval.Top != Top) || (rval.Bottom != Bottom); }
63 bool Contains (
const Vector2 &pos )
const {
return (pos.X >= Left) && (pos.X <= Right) && (pos.Y >= Top) && (pos.Y <= Bottom); }
64 void Snap_To_Units(
const Vector2 & u ) { Left = (int)(Left / u.X + 0.5f) * u.X; Right = (int)(Right / u.X + 0.5f) * u.X; Top = (int)(Top / u.Y + 0.5f) * u.Y; Bottom = (int)(Bottom / u.Y + 0.5f) * u.Y; }
66 Vector2 getSize()
const {
return Vector2(Right - Left, Bottom - Top); }