SFML community forums

General => Feature requests => Topic started by: heishe on July 08, 2008, 03:44:54 pm

Title: sf::Shape::Line arguments
Post 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.
Title: sf::Shape::Line arguments
Post by: Laurent on July 08, 2008, 03:47:57 pm
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.
Title: sf::Shape::Line arguments
Post by: heishe on July 08, 2008, 05:59:07 pm
Quote from: "Laurent"
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:
Code: [Select]

//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:
Code: [Select]

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.
Title: sf::Shape::Line arguments
Post by: Tank on July 11, 2008, 12:33:58 pm
I agree, too. At least an (inlined) overloaded function could be done to be able to use SFML vectors/point structures.
Title: sf::Shape::Line arguments
Post by: Daazku on July 11, 2008, 03:16:47 pm
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...
Title: sf::Shape::Line arguments
Post by: heishe on July 11, 2008, 06:52:31 pm
Quote from: "Daazku"
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.
Title: sf::Shape::Line arguments
Post by: Wizzard on July 11, 2008, 09:36:15 pm
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.
Title: sf::Shape::Line arguments
Post by: The DarK' on July 12, 2008, 01:02:16 pm
Quote from: "Wizzard"
I don't see why we can't provide two versions...



Me too.
Title: sf::Shape::Line arguments
Post by: Tank on July 13, 2008, 12:53:10 am
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.
Title: sf::Shape::Line arguments
Post by: Wizzard on July 14, 2008, 07:57:58 am
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:
Code: [Select]
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:
Code: [Select]
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)));
Title: sf::Shape::Line arguments
Post by: heishe on July 14, 2008, 06:24:50 pm
Quote from: "Wizzard"
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:
Code: [Select]
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:
Code: [Select]
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.
Title: sf::Shape::Line arguments
Post by: Kreeg on July 18, 2008, 03:27:27 am
I'd rather have the two signatures. They both are useful. Just add the second, this is no ugliness !
Title: sf::Shape::Line arguments
Post by: Tank on July 18, 2008, 03:12:16 pm
I completely agree with that.
Title: sf::Shape::Line arguments
Post by: heishe on July 18, 2008, 06:51:45 pm
yeah both would be no problem either :)