SFML community forums
General => Feature requests => Topic started by: Disch on April 19, 2010, 12:09:54 am
-
I use sf::Vector2<double> in calculations for extra precision, but pretty much everything in SFML takes sf::Vector2<float>.
It would be nice if sf::Vector2 had a ctor that could convert between different types so that these could be implicitly cast.
-
Such an implicit cast would be dangerous, hiding conversions that lose precision is always bad.
That's why your compiler issues a warning when you type "int x = 5.0", and you must use a static_cast ;)
-
Or write a vector cast function.
template <typename Dest, typename Source>
sf::Vector2<Dest> ConvertVector(const Vector<Source>& source)
{
return sf::Vector2<Dest>(
static_cast<Dest>(source.x),
static_cast<Dest>(source.y));
}
sf::Vector2<double> doubleVec;
sf::Vector2<float> floatVec = ConvertVector<float>(doubleVec)
-
Point taken.
How about an explicit ctor then?