40 Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) :
52 Rect<T>::Rect(
const Vector2<T>& position,
const Vector2<T>& size) :
65 Rect<T>::Rect(
const Rect<U>& rectangle) :
66 left (static_cast<T>(rectangle.left)),
67 top (static_cast<T>(rectangle.top)),
68 width (static_cast<T>(rectangle.width)),
69 height(static_cast<T>(rectangle.height))
76 bool Rect<T>::contains(T x, T y)
const
81 T minX = std::min(left, left + width);
82 T maxX = std::max(left, left + width);
83 T minY = std::min(top, top + height);
84 T maxY = std::max(top, top + height);
86 return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
92 bool Rect<T>::contains(
const Vector2<T>& point)
const
94 return contains(point.x, point.y);
100 bool Rect<T>::intersects(
const Rect<T>& rectangle)
const
102 Rect<T> intersection;
103 return intersects(rectangle, intersection);
108 template <
typename T>
109 bool Rect<T>::intersects(
const Rect<T>& rectangle, Rect<T>& intersection)
const
114 T r1MinX = std::min(left, left + width);
115 T r1MaxX = std::max(left, left + width);
116 T r1MinY = std::min(top, top + height);
117 T r1MaxY = std::max(top, top + height);
120 T r2MinX = std::min(rectangle.left, rectangle.left + rectangle.width);
121 T r2MaxX = std::max(rectangle.left, rectangle.left + rectangle.width);
122 T r2MinY = std::min(rectangle.top, rectangle.top + rectangle.height);
123 T r2MaxY = std::max(rectangle.top, rectangle.top + rectangle.height);
126 T interLeft = std::max(r1MinX, r2MinX);
127 T interTop = std::max(r1MinY, r2MinY);
128 T interRight = std::min(r1MaxX, r2MaxX);
129 T interBottom = std::min(r1MaxY, r2MaxY);
132 if ((interLeft < interRight) && (interTop < interBottom))
134 intersection = Rect<T>(interLeft, interTop, interRight - interLeft, interBottom - interTop);
139 intersection = Rect<T>(0, 0, 0, 0);
146 template <
typename T>
147 inline bool operator ==(
const Rect<T>& left,
const Rect<T>& right)
149 return (left.left == right.left) && (left.width == right.width) &&
150 (left.top == right.top) && (left.height == right.height);
155 template <
typename T>
156 inline bool operator !=(
const Rect<T>& left,
const Rect<T>& right)
158 return !(left == right);