00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 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 // Compute the intersection boundaries 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 // If the intersection is valid (positive non zero area), then there is an intersection 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 }
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::