1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
26 ////////////////////////////////////////////////////////////
\r
27 /// Default constructor
\r
28 ////////////////////////////////////////////////////////////
\r
29 template <typename T>
\r
40 ////////////////////////////////////////////////////////////
\r
41 /// Construct the color from its coordinates
\r
42 ////////////////////////////////////////////////////////////
\r
43 template <typename T>
\r
44 Rect<T>::Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) :
\r
54 ////////////////////////////////////////////////////////////
\r
55 /// Get the width of the rectangle
\r
56 ////////////////////////////////////////////////////////////
\r
57 template <typename T>
\r
58 T Rect<T>::GetWidth() const
\r
60 return Right - Left;
\r
64 ////////////////////////////////////////////////////////////
\r
65 /// Get the height of the rectangle
\r
66 ////////////////////////////////////////////////////////////
\r
67 template <typename T>
\r
68 T Rect<T>::GetHeight() const
\r
70 return Bottom - Top;
\r
74 ////////////////////////////////////////////////////////////
\r
75 /// Move the whole rectangle by the given offset
\r
76 ////////////////////////////////////////////////////////////
\r
77 template <typename T>
\r
78 void Rect<T>::Offset(T OffsetX, T OffsetY)
\r
87 ////////////////////////////////////////////////////////////
\r
88 /// Check if a point is inside the rectangle's area
\r
89 ////////////////////////////////////////////////////////////
\r
90 template <typename T>
\r
91 bool Rect<T>::Contains(T X, T Y) const
\r
93 return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom);
\r
97 ////////////////////////////////////////////////////////////
\r
98 /// Check intersection between two rectangles
\r
99 ////////////////////////////////////////////////////////////
\r
100 template <typename T>
\r
101 bool Rect<T>::Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect) const
\r
103 // Compute overlapping rect
\r
104 Rect Overlapping(std::max(Left, Rectangle.Left),
\r
105 std::max(Top, Rectangle.Top),
\r
106 std::min(Right, Rectangle.Right),
\r
107 std::min(Bottom, Rectangle.Bottom));
\r
109 // If overlapping rect is valid, then there is intersection
\r
110 if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))
\r
112 if (OverlappingRect)
\r
113 *OverlappingRect = Overlapping;
\r
118 if (OverlappingRect)
\r
119 *OverlappingRect = Rect(0, 0, 0, 0);
\r