SFML community forums
General => Feature requests => Topic started by: heishe on July 08, 2008, 03:44:54 pm
-
I think to go with the rest of your lib, you should change the first 4 arguments of that method from float P1X, float P1Y,float P2X,float P2Y to Vector2f p1, Vector2f p2;
Just a small change, but it would look more nice and it would make the sourcecode a little tigher for us.
-
Well, if I do so, another user will come tomorrow and say that float P1X, float P1Y,float P2X,float P2Y is much clearer / consistent / whatever.
Whenever possible I provide two versions of the functions taking points as parameters, but for those ones I'd like to keep one version.
-
Well, if I do so, another user will come tomorrow and say that float P1X, float P1Y,float P2X,float P2Y is much clearer / consistent / whatever.
Whenever possible I provide two versions of the functions taking points as parameters, but for those ones I'd like to keep one version.
If you like to keep one version, there are more reasons for Vector2f.
After all, what is Vector2f for if not for those things? A structure combines different values to make them available in a more logical and compact hierarchy.
From the sourcecode side, i have to type things like this all the time, which is just annoying:
//Creating a line between a sprite and the mouse pointer
Shape s = Shape::Line(m_sprite.GetPosition().x,m_Sprite.GetPosition().y,m_mouse.x,m_mouse.y...)
This would be much easier if it were just 2 vectors where i could write:
Shape s = Shape::Line(m_sprite.GetPosition(),m_mouse.xy,...)
Long lines like the first one make the code longer and harder to read, and they are also annoying to type.
Maybe it's okay like the first case for other things, but a Point is the perfect example of why to use a structure and not bare float/int values.
Of course all that goes for the other methods as well, like, AddPoint and so on.
-
I agree, too. At least an (inlined) overloaded function could be done to be able to use SFML vectors/point structures.
-
The problem is: Another user will do the same post than you guys.. Maybe with better arguments... Laurent can't change function signature just because of that..... But the overload of the function is not a bad idea...
-
The problem is: Another user will do the same post than you guys.. Maybe with better arguments... Laurent can't change function signature just because of that..... But the overload of the function is not a bad idea...
no, there are no better arguments for single values. if he designs a vector2f class for that, then he should use it. anything else would be bad / ugly code.
-
I don't see why we can't provide two versions...
In fact, I thought the whole point of Vector2f was to make the library feel cleaner, but the other function should be there for simplicity reasons.
-
I don't see why we can't provide two versions...
Me too.
-
Maybe it'd be a good idea to implement the vector-parametrized function and declare the single-value version deprecated, dropping it in a future release. Surely single values are "simple" or "easy", but like heishe said, there's a point class and I also can't see a reason why not using it, since it's just cleaner code.
-
Does it really lead to cleaner code? I figured Vector2f was just for convenience when getting positions.
Setting positions via vectors, however, in my opinion, doesn't really provide much convenience other than when the position is from a get function.
For example, we could make lines that connect dots with this code:
sf::Shape circle1(sf::Shape::Circle(40, 40, 25, sf::Color(255, 255, 255)));
sf::Shape circle2(sf::Shape::Circle(600, 600, 25, sf::Color(255, 255, 255)));
sf::Shape line(sf::Shape::Line(circle1.GetPosition(), circle2.GetPosition(), 5, sf::Color(255, 255, 255)));
Rather than:
sf::Shape circle1(sf::Shape::Circle(40, 40, 25, sf::Color(255, 255, 255)));
sf::Shape circle2(sf::Shape::Circle(600, 600, 25, sf::Color(255, 255, 255)));
sf::Shape line(sf::Shape::Line(circle1.GetPosition().x, circle1.GetPosition().y, circle2.GetPosition().x, circle2.GetPosition().y, 5, sf::Color(255, 255, 255)));
-
Does it really lead to cleaner code? I figured Vector2f was just for convenience when getting positions.
Setting positions via vectors, however, in my opinion, doesn't really provide much convenience other than when the position is from a get function.
For example, we could make lines that connect dots with this code:
sf::Shape circle1(sf::Shape::Circle(40, 40, 25, sf::Color(255, 255, 255)));
sf::Shape circle2(sf::Shape::Circle(600, 600, 25, sf::Color(255, 255, 255)));
sf::Shape line(sf::Shape::Line(circle1.GetPosition(), circle2.GetPosition(), 5, sf::Color(255, 255, 255)));
Rather than:
sf::Shape circle1(sf::Shape::Circle(40, 40, 25, sf::Color(255, 255, 255)));
sf::Shape circle2(sf::Shape::Circle(600, 600, 25, sf::Color(255, 255, 255)));
sf::Shape line(sf::Shape::Line(circle1.GetPosition().x, circle1.GetPosition().y, circle2.GetPosition().x, circle2.GetPosition().y, 5, sf::Color(255, 255, 255)));
if you like the second example better than the first one, you have a weird taste for good code.
-
I'd rather have the two signatures. They both are useful. Just add the second, this is no ugliness !
-
I completely agree with that.
-
yeah both would be no problem either :)