Added explicit conversions between different types of sf::Vector2, sf::Vector3 and sf::Rect (implements feature #31)
This commit is contained in:
parent
ade8cb8771
commit
eac841ec71
@ -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
|
||||
///
|
||||
|
@ -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
|
||||
|
@ -55,6 +55,20 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2(T X, T Y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vector from another type of vector
|
||||
///
|
||||
/// 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 vector Vector to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename U>
|
||||
explicit Vector2(const Vector2<U>& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -43,6 +43,16 @@ y(Y)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
inline Vector2<T>::Vector2(const Vector2<U>& vector) :
|
||||
x(static_cast<T>(vector.x)),
|
||||
y(static_cast<T>(vector.y))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator -(const Vector2<T>& right)
|
||||
|
@ -56,6 +56,20 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3(T X, T Y, T Z);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vector from another type of vector
|
||||
///
|
||||
/// 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 vector Vector to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename U>
|
||||
explicit Vector3(const Vector3<U>& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -45,6 +45,17 @@ z(Z)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
inline Vector3<T>::Vector3(const Vector3<U>& vector) :
|
||||
x(static_cast<T>(vector.x)),
|
||||
y(static_cast<T>(vector.y)),
|
||||
z(static_cast<T>(vector.z))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator -(const Vector3<T>& left)
|
||||
|
Loading…
Reference in New Issue
Block a user