Added explicit conversions between different types of sf::Vector2, sf::Vector3 and sf::Rect (implements feature #31)

This commit is contained in:
Laurent Gomila 2011-04-26 19:20:24 +02:00
parent ade8cb8771
commit eac841ec71
6 changed files with 75 additions and 0 deletions

View file

@ -78,6 +78,20 @@ public :
////////////////////////////////////////////////////////////
Rect(const Vector2<T>& position, const Vector2<T>& size);
////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from another type of rectangle
///
/// This constructor doesn't replace the copy constructor,
/// it's called only when U != T.
/// A call to this constructor will fail to compile if U
/// is not convertible to T.
///
/// \param rectangle Rectangle to convert
///
////////////////////////////////////////////////////////////
template <typename U>
explicit Rect(const Rect<U>& rectangle);
////////////////////////////////////////////////////////////
/// \brief Check if a point is inside the rectangle's area
///

View file

@ -59,6 +59,18 @@ Height(size.y)
}
////////////////////////////////////////////////////////////
template <typename T>
template <typename U>
Rect<T>::Rect(const Rect<U>& rectangle) :
Left (static_cast<T>(rectangle.Left)),
Top (static_cast<T>(rectangle.Top)),
Width (static_cast<T>(rectangle.Width)),
Height(static_cast<T>(rectangle.Height))
{
}
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::Contains(T x, T y) const