Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Shape::Line arguments  (Read 26074 times)

0 Members and 3 Guests are viewing this topic.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
sf::Shape::Line arguments
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Shape::Line arguments
« Reply #1 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.
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
sf::Shape::Line arguments
« Reply #2 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.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
sf::Shape::Line arguments
« Reply #3 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.

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
sf::Shape::Line arguments
« Reply #4 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...
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
sf::Shape::Line arguments
« Reply #5 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.

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
sf::Shape::Line arguments
« Reply #6 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.

The DarK'

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
sf::Shape::Line arguments
« Reply #7 on: July 12, 2008, 01:02:16 pm »
Quote from: "Wizzard"
I don't see why we can't provide two versions...



Me too.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
sf::Shape::Line arguments
« Reply #8 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.

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
sf::Shape::Line arguments
« Reply #9 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)));

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
sf::Shape::Line arguments
« Reply #10 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.

Kreeg

  • Full Member
  • ***
  • Posts: 115
    • View Profile
sf::Shape::Line arguments
« Reply #11 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 !
Attention (va) aux (sur) messages (mon) subliminaux, (blog) camarade !

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
sf::Shape::Line arguments
« Reply #12 on: July 18, 2008, 03:12:16 pm »
I completely agree with that.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
sf::Shape::Line arguments
« Reply #13 on: July 18, 2008, 06:51:45 pm »
yeah both would be no problem either :)

 

anything