00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025
00027 template <typename T>
00028 Rect<T>::Rect() :
00029 Left (0),
00030 Top (0),
00031 Width (0),
00032 Height(0)
00033 {
00034
00035 }
00036
00037
00039 template <typename T>
00040 Rect<T>::Rect(T left, T top, T width, T height) :
00041 Left (left),
00042 Top (top),
00043 Width (width),
00044 Height(height)
00045 {
00046
00047 }
00048
00049
00051 template <typename T>
00052 Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
00053 Left (position.x),
00054 Top (position.y),
00055 Width (size.x),
00056 Height(size.y)
00057 {
00058
00059 }
00060
00061
00063 template <typename T>
00064 template <typename U>
00065 Rect<T>::Rect(const Rect<U>& rectangle) :
00066 Left (static_cast<T>(rectangle.Left)),
00067 Top (static_cast<T>(rectangle.Top)),
00068 Width (static_cast<T>(rectangle.Width)),
00069 Height(static_cast<T>(rectangle.Height))
00070 {
00071 }
00072
00073
00075 template <typename T>
00076 bool Rect<T>::Contains(T x, T y) const
00077 {
00078 return (x >= Left) && (x < Left + Width) && (y >= Top) && (y < Top + Height);
00079 }
00080
00081
00083 template <typename T>
00084 bool Rect<T>::Contains(const Vector2<T>& point) const
00085 {
00086 return Contains(point.x, point.y);
00087 }
00088
00089
00091 template <typename T>
00092 bool Rect<T>::Intersects(const Rect<T>& rectangle) const
00093 {
00094 Rect<T> intersection;
00095 return Intersects(rectangle, intersection);
00096 }
00097
00098
00100 template <typename T>
00101 bool Rect<T>::Intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
00102 {
00103
00104 T left = std::max(Left, rectangle.Left);
00105 T top = std::max(Top, rectangle.Top);
00106 T right = std::min(Left + Width, rectangle.Left + rectangle.Width);
00107 T bottom = std::min(Top + Height, rectangle.Top + rectangle.Height);
00108
00109
00110 if ((left < right) && (top < bottom))
00111 {
00112 intersection = Rect<T>(left, top, right - left, bottom - top);
00113 return true;
00114 }
00115 else
00116 {
00117 intersection = Rect<T>(0, 0, 0, 0);
00118 return false;
00119 }
00120 }