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

Author Topic: sf::Rect modifications in SFML 2 (important!)  (Read 7377 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Rect modifications in SFML 2 (important!)
« on: April 09, 2010, 03:09:58 pm »
Hi

Today I decided to fix all the bad stuff about sf::Rect. I mainly applied what was said there:
http://www.sfml-dev.org/forum/viewtopic.php?t=1745

Here is a list of what has changed:
- sf::Rect now uses Width/Height instead of Right/Bottom ; this is extremely important because you'll have to change the construction parameters of all your rectangles (sorry)
- Coordinates are now handled consistently: the top-left corner is included in the rectangle's area while the right-bottom corner is excluded
- Rect::GetSize, Rect::Offset and Rect::GetCenter were no longer necessary and were removed

Tell me what you think, and if it's the right solution regarding everything that was said before :)
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Rect modifications in SFML 2 (important!)
« Reply #1 on: April 09, 2010, 03:27:20 pm »
Hey, this looks extremely nice. Thanks a lot for the adaptions. :D

Now the goal is to fix all rects. That is going to be funny... But now I can even throw away my SizeRect class. ;)

However, I wonder why the Intersects() method is still a member and not a global function. Do you plan to keep this?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

bullno1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
sf::Rect modifications in SFML 2 (important!)
« Reply #2 on: April 09, 2010, 03:31:35 pm »
Why the sudden change from bottom, right to width height? I though it was OK.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Rect modifications in SFML 2 (important!)
« Reply #3 on: April 09, 2010, 03:33:19 pm »
Quote
However, I wonder why the Intersects() method is still a member and not a global function. Do you plan to keep this?

I know that it would be a better design, but then Intersects would be the only non-member function of sf::Rect (out of two :D) and even of the whole SFML API. Weird.
So I think that I'll keep it as a member, for simplicity and consistency.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Rect modifications in SFML 2 (important!)
« Reply #4 on: April 09, 2010, 03:37:26 pm »
Quote
Why the sudden change from bottom, right to width height? I though it was OK.

I think it's more intuitive when you think about the way coordinates are handled. Having top/left and bottom/right would suggest that they are handled the same way, but top/left is part of the rectangle's area while bottom/right is not. The start/length representation is better in my opinion.

And I originally chose right/bottom to easily allow flipped rectangles (right < left is less confusing than width < 0, I think) but it is not used anymore so there was no reason to keep this definition.
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
sf::Rect modifications in SFML 2 (important!)
« Reply #5 on: April 09, 2010, 09:51:16 pm »
Excellent.  :D

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Rect modifications in SFML 2 (important!)
« Reply #6 on: April 11, 2010, 02:36:22 pm »
Quote from: "Laurent"
I know that it would be a better design, but then Intersects would be the only non-member function of sf::Rect (out of two :D) and even of the whole SFML API. Weird.
So I think that I'll keep it as a member, for simplicity and consistency.
That's a good point. Now that you say it, I see that there are hardly global functions in SFML (apart from sf::Sleep(), the vector operators and maybe a few others). So you're probably right.

As far as I remember, Doxygen also has problems with global member functions. In order to list them together with the class interface, you would have to write modules and group functionality. For example, sf::Sleep() currently doesn't appear in the documentation.

Another question: Why are Rect::Offset() and Rect::GetCenter() no longer necessary? Now, one has to write
Code: [Select]
MyRect.Top += OffsetVector.x;
MyRect.Left += OffsetVector.y;
and
Code: [Select]
sf::Vector2f(MyRect.Left + MyRect.Width/2.f, MyRect.Top + MyRect.Height/2.f);to achieve the same. It may be fewer work than with Right/Bottom, but it's still quite tedious...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Rect modifications in SFML 2 (important!)
« Reply #7 on: April 11, 2010, 05:16:59 pm »
Quote
Another question: Why are Rect::Offset() and Rect::GetCenter() no longer necessary?

I think it's not worth it anymore. And they are almost never used. So again, I decided to remove them for simplicity and consistency.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Rect modifications in SFML 2 (important!)
« Reply #8 on: April 11, 2010, 07:11:29 pm »
Okay. If it shows that there will be many users requiring those functions, you could still add them later. Better to add than to remove and break existing code. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
sf::Rect modifications in SFML 2 (important!)
« Reply #9 on: April 13, 2010, 08:27:51 am »
I think it was a good decision, thanks. sf::Rect feels a lot for confident now. ;)

Warfield

  • Newbie
  • *
  • Posts: 4
    • View Profile
sf::Rect modifications in SFML 2 (important!)
« Reply #10 on: April 21, 2010, 04:58:26 am »
Woohoo :)